在 C# 应用程序中,我引用了本机 C 静态库,我将其包装在 C++/CLI DLL 中。我选择静态库而不是 DLL,因为我还有与向用户发布应用程序的过程相关的其他限制。在该论坛上提供的许多主题中,我发现了以下实现。
Main :
{
MyCLRDLL test = new MyCLRDLL();
if(test.go()) Console.WriteLine("Hello, wrld");
}
在DLL项目中,文件MyCLRDLL.hpp
#include "MyNativeLib.h"
#pragma comment(lib, "MyNativeLib.lib")
namespace InteropTest {
public ref class MyCLRDLL
{
CMyNativeLib* mInt ;
public:
MyCLRDLL() { mInt = CMyNativeLib_New() ;} ;
~MyCLRDLL() { CMyNativeLib_Delete(mInt) ;} ;
bool go() { return mInt->areYouThere() ;} ;
};
}
在原生项目中,MyNativeLib.h
namespace InteropTest
{
class __declspec(dllexport) CMyNativeLib
{
public:
CMyNativeLib() {};
~CMyNativeLib(){};
bool areYouThere() ;
} ;
extern "C" __declspec(dllexport) CMyNativeLib* CMyNativeLib_New();
extern "C" __declspec(dllexport) void CMyNativeLib_Delete(CMyNativeLib* pLib);
}
and MyNativeLib.cpp
#include "MyNativeLib.h"
namespace InteropTest {
extern "C" __declspec(dllexport) CMyNativeLib* CMyNativeLib_New(){return new CMyNativeLib() ;}
extern "C" __declspec(dllexport) void CMyNativeLib_Delete(CMyNativeLib* pLib){delete pLib;}
bool CMyNativeLib::areYouThere() { return true ; }
}
调试器没有单步执行 mInt->areYouThere() 函数。为什么会这样?本机部分中的断点也不会被捕获。
为 MyCLRDLL 加载符号,“启用非托管代码调试”在 C# 项目上处于活动状态,“调试/调试器类型”对于两个 C 项目都设置为“混合”,并且在常规选项中,大多数相关内容似乎已选中。
这是否意味着 MyCLRDLL.pdb 文件不包含 lib 代码中的调试信息?如何检查?
(可能与未回答的问题相同调试 CLR .dll 中包含的非托管 C++ 静态库 https://stackoverflow.com/questions/13324341/debugging-an-unmanaged-c-static-lib-included-in-a-clr-dll)