Hi Jak,
If you get the error message saying:
Unable to find an entry point named 'GetStr' in DLL 'DelphiDLLTest.dll'.
....when you execute your .NET application, then there must be an error in
your Delphi or VB code, for example a typo in the external (VB) and/or
exported function name (Delphi).
To help you solve your issue, I just tested interoperability between Delphi
2006 and C#, and it works well. Here's what I did.
First, I created a Delphi DLL project with the following minimal code:
-----------------------
library DelphiDLLTest;
function GetStr(s : PChar) : PChar; stdcall;
begin
Result:= s;
end;
exports
GetStr;
begin
end.
-----------------------
Next, I started a new C# WinForms project (VB.NET should be just as fine),
and then chose the menu command "Project/Add Existing Item" and added the
compiled Delphi DLL to the project. (This is actually not necessary, but
makes it simpler to develop at the same time in both Delphi and Visual
Studio.)
Once the DLL was added to the project, I clicked the DLL in Solution
Explorer and set the property "Copy To Output Directory" to "Copy Always".
Now when I build the solution in Visual Studio, the Delphi DLL is
automatically copied to the bin\Debug directory.
Thirdly, I wrote the following C# code:
-----------------------
[DllImport("DelphiDLLTest.dll")]
public static extern string GetStr(string s);
private void button1_Click(object sender, EventArgs e)
{
string result = GetStr("Hello, World!");
MessageBox.Show("DelphiDLLTest.dll returns:\r\n" + result);
}
-----------------------
When I run the C# application and click the button to execute the above
code, it works nicely. So if you get errors at this point, try creating a
new Delphi DLL from scratch, and then following the instructions above (but
changing to VB.NET code if you want to).
Hope this helps.
--
Regards,
Mr. Jani Järvinen
C# MVP
Helsinki, Finland
ja***@removethis.dystopia.fi http://www.saunalahti.fi/janij/