Jump to content
Jurandi

Call a D7 dll from C#

Recommended Posts

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 by Jurandi
Big Font

Share this post


Link to post

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

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);

 

  • Like 2
  • Thanks 1

Share this post


Link to post
Hello Remy.
Thank you very much for the examples.
Both worked well.
Have a good week.
Hugs.

 

Edited by Jurandi

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×