Linda-chan

modFileNameHack.BAS

Aug 11th, 2015
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2.  
  3. '====================================================================
  4. Public Function GetFixedFileName(ByVal FileName As BStr) As BStr
  5.   Dim hFile As API_HANDLE
  6.   Dim Buff As BStr
  7.   Dim RC As Long
  8.  
  9.   hFile = CreateFileByNumW(FileName, GENERIC_WRITE, 0, ByVal 0&, CREATE_ALWAYS, 0, 0)
  10.   If hFile = INVALID_HANDLE_VALUE Then
  11.     GetFixedFileName = FileName
  12.     Exit Function
  13.   End If
  14.  
  15.   CloseHandle hFile
  16.  
  17.   RC = GetShortPathNameW(FileName, "", 0)
  18.   If RC = 0 Then
  19.     GetFixedFileName = FileName
  20.     Exit Function
  21.   End If
  22.  
  23.   RC = RC + 2
  24.   Buff = String(RC + 10, 0)
  25.  
  26.   RC = GetShortPathNameW(FileName, Buff, RC)
  27.   If RC = 0 Then
  28.     GetFixedFileName = FileName
  29.     Exit Function
  30.   End If
  31.  
  32.   GetFixedFileName = Left(Buff, RC)
  33. End Function
Add Comment
Please, Sign In to add comment