use*_*428 4 .net dll inno-setup
我正在尝试将用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。
为什么不起作用?
使用非托管导出从C#程序集导出函数,以便可以在Inno Setup中调用它。
DllExport属性添加到您的方法using RGiesecke.DllExport;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
namespace MyNetDll
{
public class MyFunctions
{
[DllExport(CallingConvention = CallingConvention.StdCall)]
public static bool RegexMatch(
[MarshalAs(UnmanagedType.LPWStr)]string pattern,
[MarshalAs(UnmanagedType.LPWStr)]string input)
{
return Regex.Match(input, pattern).Success;
}
}
}
Run Code Online (Sandbox Code Playgroud)
在Inno Setup端(Unicode版本):
using RGiesecke.DllExport;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
namespace MyNetDll
{
public class MyFunctions
{
[DllExport(CallingConvention = CallingConvention.StdCall)]
public static bool RegexMatch(
[MarshalAs(UnmanagedType.LPWStr)]string pattern,
[MarshalAs(UnmanagedType.LPWStr)]string input)
{
return Regex.Match(input, pattern).Success;
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在,您可以使用函数了:
[Files]
Source: "MyNetDll.dll"; Flags: dontcopy
[Code]
function RegexMatch(Pattern: string; Input: string): Boolean;
external 'RegexMatch@files:MyNetDll.dll stdcall';
Run Code Online (Sandbox Code Playgroud)
也可以看看:
| 归档时间: |
|
| 查看次数: |
2606 次 |
| 最近记录: |