如何在C#中实现非托管回调函数?

如何在C#中实现非托管回调函数?,c#,c,C#,C,我如何实现下面的C代码?这是来自非托管C/C++DLL的回调函数 extern void (*NdProcSamples)(word dc, word phase, word sum_st, const NdPackChan *chans);//This function is in Third party(C/C++ DLL). typedef void (*TProcSamples)(word dc, word phase, word sum_st, const NdPackChan *c

我如何实现下面的C代码?这是来自非托管C/C++DLL的回调函数

extern void (*NdProcSamples)(word dc, word phase, word sum_st, const NdPackChan *chans);//This function is in Third party(C/C++ DLL).

typedef void (*TProcSamples)(word dc, word phase, word sum_st, const NdPackChan *chans); //Call back Fucntion

TProcSamples *pProcSamples;

pProcSamples = (TProcSamples*) GetProcAddress(drv_lib, "NdProcSamples") //Gets address of function

*pProcSamples = NdProcSamples;

// Function below gets called by driver(DLL)

void NdProcSamples(word dc, word phase, word sum_st, const NdPackChan *chans)
{

    //logic goes here 

}

你知道呼叫约定是什么吗?这个问题有点不清楚。如何将此回调传递给非托管代码?但无论如何,您可以安全地使用
委托
并将其传递给非托管函数,只需记住默认情况下C具有
\uu stdcall
调用约定。如果您想要完整答案,请提供更多代码。