将调试和发布DLL与SWIG中的相同C#代码接口?

问题描述 投票:1回答:1

SWIG允许您使用-dllimport命令行参数指定要导入C#的DLL。

导入一个名称取决于Debug版本或Release版本的DLL怎么样?对于遵循Microsoft约定的d后缀附加到Debug版本的DLL,会发生这种情况。 ucrtbase.dll用于发布版本,ucrtbased.dll用于调试。

如果允许-dllimport指定符号常量,则该常量的值可能取决于是否定义了DEBUG,但这似乎并非如此。

c# swig dllimport
1个回答
0
投票

我认为您可以使用静态构造函数和the SetDllDirectory of suggestion of this this answer做您想做的事情。

为了测试这一点,我把这个例子放在一起:

SetDllDirectory

您必须像这样用SWIG来构建它才能%module foobar %pragma(csharp) imclasscode=%{ [global::System.Runtime.InteropServices.DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] static extern bool SetDllDirectory(string lpPathName); static $imclassname() { if (isDebug) SetDLLDirectory("path/to/directory/with/debugDll"); else SetDLLDirectory("path/to/directory/with/regularDll"); } %}

suppress the default static constructor

相当如何区分真实代码中的swig3.0 -DSWIG_CSHARP_NO_IMCLASS_STATIC_CONSTRUCTOR -csharp test.i ,我不太清楚-也许使用isDebug,然后使用this to find the current HMODULE来查看它是否是您的调试版本。

© www.soinside.com 2019 - 2024. All rights reserved.