David对另一个问题的回答显示Delphi DLL函数返回一个WideString.我从没想过如果没有使用它是可能的ShareMem.
我的测试DLL:
function SomeFunction1: Widestring; stdcall;
begin
Result := 'Hello';
end;
function SomeFunction2(var OutVar: Widestring): BOOL; stdcall;
begin
OutVar := 'Hello';
Result := True;
end;
Run Code Online (Sandbox Code Playgroud)
我的来电计划:
function SomeFunction1: WideString; stdcall; external 'Test.dll';
function SomeFunction2(var OutVar: Widestring): BOOL; stdcall; external 'Test.dll';
procedure TForm1.Button1Click(Sender: TObject);
var
W: WideString;
begin
ShowMessage(SomeFunction1);
SomeFunction2(W);
ShowMessage(W);
end;
Run Code Online (Sandbox Code Playgroud)
它有效,我不明白怎么做.我所知道的约定是Windows API使用的约定,例如Windows GetClassNameW:
function GetClassNameW(hWnd: HWND; lpClassName: PWideChar; nMaxCount: Integer): Integer; stdcall;
Run Code Online (Sandbox Code Playgroud)
意味着调用者提供缓冲区和最大长度.Windows DLL以长度限制写入该缓冲区.调用者分配和释放内存.
另一种选择是DLL分配内存,例如通过使用LocalAlloc,并且调用者通过调用释放内存LocalFree.
内存分配和解除分配如何与我的DLL示例一起使用?"魔法"是否会发生,因为结果是WideString(BSTR …
我想从Inno安装脚本中调用.NET DLL(用C#编码)中的函数.
我有:
[文件]
来源:c:\ temp\1\MyDLL.dll; 标志:dontcopy
[码]
function MyFunction():string;
外部'MyFunction @文件:MyDLL.dll stdcall setuponly';
但我仍然收到以下错误:
运行时错误(在-1:0):
无法导入DLL:C:\ DOCUME~1\foo\LOCALS~1\Temp\is-LRL3E.tmp\MyDLL.dll.
我究竟做错了什么?
我正在尝试将用C#编写的DLL加载到Inno Setup中。
这是代码:
function Check(version, dir: String): Integer;
external 'Check@{src}\check.dll stdcall';
Run Code Online (Sandbox Code Playgroud)
然后我这样称呼它 Check(x,y)
但是无法加载DLL。
我尝试了stdcall和cdecl。
该check.dll文件位于setup.exe。
为什么不起作用?