public class SendImage
{
public delegate int DWatch(int bytesLeftToSend, IntPtr Response);
ret=0xffff;
public void ReadImageFile()
{
int len = 1495;
DWatch pfWatch = DResponse;
IntPtr pfMethod = Marshal.GetFunctionPointerForDelegate(pfWatch);
ret=Send(len, pfMethod);
}
public int DResponse(int bytesLeftToSend, IntPtr Response)
{
//something;
return 0;
}
}
上面的代碼顯示瞭如何將代理編組爲函數指針。從這我能夠回調。但後來我收到內存損壞的錯誤。請幫忙。謝謝元帥代表函數指針:內存損壞
//unmanaged call in code
int Send(int length, int(*pfMethod)(int bytesLeftToSend, void * Response))
{
int Remaining = 50;
pfMethod(50);
}
你爲什麼標籤這個問題''C'視覺C++'和'C#-4.0' – Eregrith 2012-03-30 12:46:09