Tengo un archivo DLL compilado en Delphi 2007 y un ejemplo que lo usa en otro proyecto Delphi. Aquí está una parte de código:Llamar a una función delphi DLL desde C# Code
TErrorCallback = function(Msg:PChar):byte of object;
TSaveEventCallback = function (Line:PChar; HiCode:PChar; LoCode:PChar; MobileNo:PChar):byte of object;
function InitModule(ErrorCallback:TErrorCallback; SaveEventCallback :TSaveEventCallback; MainWindowHandle:THandle; Sock_Event:integer):byte; stdcall; external 'My.dll' name 'InitModule';
function DLLSocketEvent(var msg: TMessage): byte; stdcall; external 'My.dll' name 'DLLSocketEvent';
function InitObjList(Objs: array of PChar; NumObjs: byte; Name: PChar):byte; stdcall; external 'My.dll' name 'InitObjList';
Y aquí está mi C# analógico:
class Message
{
unsigned int msg;
int wParam;
int lParam;
int result;
};
delegate byte ErrorCallbackDelegate(string msg);
delegate byte SaveEventCallbackDelegate(string line, string hiCode, string loCode, string mobileNo);
[DllImport("My.dll")]
static extern byte InitModule(ErrorCallbackDelegate errorCallback, SaveEventCallbackDelegate saveEventCallback, IntPtr mainWindowsHandle, Int32 sockEvent);
[DllImport("My.dll")]
static extern byte DllSocketEvent(Message msg);
[DllImport("My.dll")]
static extern byte InitObjList(string[] objs, byte numObjs, string name);
El punto es que he intentado único método InitModule y throwed una excepción: Una llamada a la función PInvoke 'ProjTest! ProjTest.MyClass :: InitModule' ha desequilibrado la pila. Esto es probable porque la firma de PInvoke administrada no coincide con la firma de destino no administrada. Compruebe que la convención de llamada y los parámetros de la firma PInvoke coinciden con la firma no administrada de destino.
Por favor, ayúdenme con esto. ¿Cómo debo describir estas funciones DLL en C#?
¿Por qué votar abajo? –