Posted January 24, 201510 yr function VolSerialNumber(DriveChar: Char): DWORD; unsafe;varNotUsed: DWORD;VolFlags: DWORD;VolSerNumber: DWORD;Buf: array [0..MAX_PATH] of Char;beginGetVolumeInformation ((PChar(DriveChar + ':\'), Buf, sizeof(Buf), @VolSerNumber, NotUsed, VolFlags, nil, 0));Result := VolSerNumber;end;please help for errorthis code work well in delphi 7 but after upgrade delphi 8 error in GetVolumeInformation ((PChar(DriveChar + ':\'), Buf, sizeof(Buf), @VolSerNumber, NotUsed, VolFlags, nil, 0));[Error] WinForm.pas(89): Invalid typecast[Error] WinForm.pas(89): There is no overloaded version of 'GetVolumeInformation' that can be called with these arguments
January 24, 201510 yr Check how many parameters GetVolumeInformation takes in delphi 8. If there is no problems with number of parameters I suspect that it takes a wide char instead. So change Buff to array of WChar, and use GetVol(PWChar(DriveChar + ':\'). Try that and see how it goes.
January 24, 201510 yr Delphi 8 is a really, really horrible .NET-only version. Unless you really must use it, I strongly suggest you to switch to Delphi 10 or Delphi 2007. Look how the definition of GetVolumeInformation looks like in D8: function GetVolumeInformation(lpRootPathName: string; lpVolumeNameBuffer: StringBuilder; nVolumeNameSize: DWORD; out lpVolumeSerialNumber: DWORD; out lpMaximumComponentLength, lpFileSystemFlags: DWORD; lpFileSystemNameBuffer: StringBuilder; nFileSystemNameSize: DWORD): BOOL; overload;function GetVolumeInformation(lpRootPathName: string; lpVolumeNameBuffer: StringBuilder; nVolumeNameSize: DWORD; lpVolumeSerialNumber: IntPtr; out lpMaximumComponentLength, lpFileSystemFlags: DWORD; lpFileSystemNameBuffer: StringBuilder; nFileSystemNameSize: DWORD): BOOL; overload;function GetVolumeInformationA(lpRootPathName: string; lpVolumeNameBuffer: StringBuilder; nVolumeNameSize: DWORD; out lpVolumeSerialNumber: DWORD; out lpMaximumComponentLength, lpFileSystemFlags: DWORD; lpFileSystemNameBuffer: StringBuilder; nFileSystemNameSize: DWORD): BOOL;function GetVolumeInformationW(lpRootPathName: string; lpVolumeNameBuffer: StringBuilder; nVolumeNameSize: DWORD; out lpVolumeSerialNumber: DWORD; out lpMaximumComponentLength, lpFileSystemFlags: DWORD; lpFileSystemNameBuffer: StringBuilder; nFileSystemNameSize: DWORD): BOOL;lpVolumeNameBuffer is not PChar anymore, you must use StringBuilder instead.
Create an account or sign in to comment