Tam*_*lei 6 c++ dll inno-setup pascalscript
我需要将一个字符串值返回给调用inno安装脚本.问题是我找不到管理分配内存的方法.如果我在DLL端分配,我没有任何东西可以在脚本端解除分配.我不能使用输出参数,因为Pascal脚本中也没有分配函数.我该怎么办?
以下是如何分配从DLL返回的字符串的示例代码:
[code]
Function GetClassNameA(hWnd: Integer; lpClassName: PChar; nMaxCount: Integer): Integer;
External 'GetClassNameA@User32.dll StdCall';
function GetClassName(hWnd: Integer): string;
var
ClassName: String;
Ret: Integer;
begin
// allocate enough memory (pascal script will deallocate the string)
SetLength(ClassName, 256);
// the DLL returns the number of characters copied to the buffer
Ret := GetClassNameA(hWnd, PChar(ClassName), 256);
// adjust new size
Result := Copy(ClassName, 1 , Ret);
end;
Run Code Online (Sandbox Code Playgroud)