我用VC在DLL中写了一个函数:
extern "C" __declspec(dllexport) HRESULT GetDiskType(INT64* nTypeRet, LPWSTR szDisk)
{
USES_CONVERSION;
CString strDisk = CW2CT(szDisk);
*nTypeRet = GetDriveType(strDisk);
return TRUE;
}
我不喜欢在inno设置中使用它:
procedure InitializeWizard();
var nDrType:any;
begin
GetDiskType(nDrType, 'D:\');
//MsgBox(IntToStr(nDrType), mbInformation, MB_OK);
if (nDrType=3) or (nDrType=6) then
begin
WizardForm.DirEdit.Text := 'D:\{#MyAppPublisher}{#MyAppName}';
end;
end;
运行时,它显示错误:写入地址00000000
我找到了答案1、更改dll中的函数声明:
//extern "C" __declspec(dllexport) HRESULT GetDiskType(INT64* nTypeRet, LPWSTR szDisk)
extern "C" __declspec(dllexport) HRESULT GetDiskType(int* nTypeRet, LPWSTR szDisk)
2、在inno-setup中使用关键字var:声明函数
function GetDiskType(var pKeyRet:integer; pszDirName: String) : integer; external 'GetDiskType@files:AppRegDll.dll cdecl setuponly';
感谢Martin Prikryl的帮助!