How to call a function in a Delphi DLL from C# - PChar as parameter

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ManUtdFans
    New Member
    • Jul 2010
    • 2

    How to call a function in a Delphi DLL from C# - PChar as parameter

    I have a Delphi DLL function:
    function GetMyNickName(a MyName: PChar): PChar; stdcall;

    This will return my nickname.

    In ASP.NET, C#:
    [DllImport("Test DLL.dll", EntryPoint = "GetMyNickName" ,
    ExactSpelling = false, CallingConventi on = CallingConventi on.Cdecl)]
    static extern string GetMyNickName(s tring aMyName);


    In the button on click event:

    string myName;
    string myNickName;

    myName = "John Smith";
    myNickName = GetMyNickName(m yName);
    Response.Write( myNickName);

    I got a runtime error:
    A call to PInvoke function 'App_Web_ojpwdp rl!Default2::Ge tMyNickName' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.

    Anyone has idea?

    Thanks
Working...