DLP library DELPHI XE2 cannot be added to C # application

For testing, I am trying to call a Delphi XE2 DLL (see code) in a C # application (developed in Visual C # 2010 Express).

procedure CLP; stdcall; export;
begin
  showmessage('TEST');
end;

exports CLP;

      

However, when trying to add a DLL as a reference to a C # project, the following message appears:

The reference to "D: \ temp \ test.dll" could not be added. Please make sure the file is available and it is a valid assembly or COM component.

When the same DLL is compiled in Delphi 2010, it works without issue.

Any suggestions to solve the problem are greatly appreciated.

+3


source to share


3 answers


You cannot add an unmanaged DLL to a .NET project.



But you can import functions, see for example Platform Learning App

+6


source


You are trying to link to an unmanaged, native DLL. You cannot add such a thing to a managed application as a link.

The way to call your DLL is to use p / invoke:

[DllImport(@"test.dll", CallingConvention=CallingConvention.Stdcall)]
static extern void CLP();

      



Naturally, things can get a little complicated when you run parameters for your DLL, but you can go a very long way with p / invoke.

One thing you need to pay attention to is that your managed project is targeting x86 if your DLL is 32 bit or x64 if your DLL is 64 bit.

Last but not least, note that use is export

pointless in modern Delphi. You should just remove it as the compiler ignores it anyway.

+3


source


Henk is right and I want to add a few things.

First of all, you can only add the dll if it is a .NET managed dll (which calls the assembly). But you can import unused functions from unmanaged dll or exe files. So the right question is how can I import functions from an unmanaged dll and you should be looking for an answer for that. And I think the best starting position is pinvoke .

0


source







All Articles