C# 调用vc++;c语言中的动态链接库#

C# 调用vc++;c语言中的动态链接库#,c#,visual-c++,dll,dllimport,C#,Visual C++,Dll,Dllimport,我在vc++中有一个dll和相应的头文件(.h文件),现在我必须在c#中调用这个dll。 我也不知道如何调用约定 在头文件中有一个函数原型,如: typedef void CBOnStop_VC( int nFGHandle, unsigned int nChannel, void* pClientData ); 现在我想用c#调用这个函数 有什么想法吗?您可以使用这些步骤 1. compile your classe with the /clr switch #include "Nativ

我在vc++中有一个dll和相应的头文件(.h文件),现在我必须在c#中调用这个dll。 我也不知道如何调用约定

在头文件中有一个函数原型,如:

typedef void CBOnStop_VC( int nFGHandle, unsigned int nChannel, void* pClientData );
现在我想用c#调用这个函数


有什么想法吗?

您可以使用这些步骤

1. compile your classe with the /clr switch

#include "NativeType.h"

public ref class ManagedType
{
     NativeType*   NativePtr; 

public:
     ManagedType() : NativePtr(new NativeType()) {}
     ~ManagedType() { delete NativePtr; }

     void ManagedMethod()
      { NativePtr->NativeMethod(); } 
}; 

2.Add a reference to your ManagedType assembly

ManagedType mt = new ManagedType();
mt.ManagedMethod();
这是标准的方法。你应该对通话约定有一些想法。这个答案有助于你: