如何从DLL返回一个字符串到Inno安装程序? [英] How to return a string from a DLL to Inno Setup?

查看:267
本文介绍了如何从DLL返回一个字符串到Inno安装程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要返回一个字符串值到调用inno安装脚本。问题是我找不到一种方法来管理分配的内存。如果我在DLL一侧分配,我没有任何东西在脚本一侧取消分配。我不能使用输出参数,因为在Pascal Script中也没有分配函数。我该怎么办?

I need to return a string value to the calling inno setup script. Problem is I can't find a way to manage the allocated memory. If I allocate on the DLL side, I don't have anything to deallocate with on the script side. I can't use an output parameter, because there is no allocation function in the Pascal Script either. What should I do?

推荐答案

这里是如何分配从DLL返回的字符串的示例代码:

Here is a sample code of how to allocate a string that returns from a 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;

这篇关于如何从DLL返回一个字符串到Inno安装程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆