Jurandi 1 Posted October 18, 2020 (edited) Hello everyone. I have a dll made in delphi 7 where the parameters are of type PChar. Calling it in a delphi program works ok. How to declare and use it in a C # program. Ex delphi dll: Function Mostra_Msg (Parmsg: PChar): LongBool; export; // stdcall begin Result: = True; ShowMessage ('String Passed =' + Strpas (parmsg)); end; Thank you. Edited October 19, 2020 by Jurandi Big Font Share this post Link to post
David Heffernan 2345 Posted October 19, 2020 What calling convention is the function? If it is register then that is a problem. Make sure it is stdcall. A websearch for pinvoke will tell you how to call this function. Share this post Link to post
Remy Lebeau 1394 Posted October 19, 2020 Assuming the calling convention of the DLL function is stdcall, then the correct PInvoke declaration in C# would be as follows: [DllImport("my.dll", CharSet = CharSet.Ansi)] static extern bool Mostra_Msg (string Parmsg); Alternatively: [DllImport("my.dll")] static extern bool Mostra_Msg ([MarshalAs(UnmanagedType.LPStr)]string Parmsg); 2 1 Share this post Link to post
Jurandi 1 Posted October 19, 2020 (edited) Hello Remy. Thank you very much for the examples. Both worked well. Have a good week. Hugs. Edited October 19, 2020 by Jurandi Share this post Link to post