2012-07-04 2 views
0

저는 vC++과 해당 헤더 파일 (.h 파일)에 dll이 있습니다. 이제는 C#에서이 DLL을 호출해야합니다. 그리고 나는 관습을 부르는 것에 대해 전혀 모른다. C#에서 vC++ dll을 호출하십시오.

typedef void CBOnStop_VC(int nFGHandle, unsigned int nChannel, void* pClientData); 

가 지금은 C#에서이 함수를 호출 할 :

헤더 파일에서 같은 함수 프로토 타입이 있습니다.

아이디어가 있으십니까? 당신이 논문을 사용할 수 있습니다

+2

가 [P/호출] (http://msdn.microsoft.com/en-us/library/fzhhdwae.aspx) 정식 방법 단계를 반복합니다. 그리고 호출 규칙에 대한 몇 가지 아이디어가 있어야합니다. – Vlad

+0

이 답변은 다음과 같이 도움이됩니다. [C++ DLL call from C#] (http://stackoverflow.com/a/9719226/47733) – lsalamon

답변

0

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(); 
관련 문제