我正在从 C# 应用程序中的非托管 DLL mscorpe.dll 导入 CreateICeeFileGen() 函数,以生成 PE 文件。此函数返回指向此处定义的 C++ 对象的指针,有什么方法可以通过 C# 访问此类中的字段,还是需要编写非托管包装 DLL?
我目前使用的代码如下:-
[DllImport(@"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorpe.dll", EntryPoint = "CreateICeeFileGen")]
static extern void CreateICeeFileGen(out IntPtr iceeFileGenPointer);
...
IntPtr filePtr;
CreateICeeFileGen(out filePtr);
注意:我知道你可以用 .net 库做类似的事情,但我需要使用非托管库来实现我的目的。