Problem with DllImport

T

t0x3e8

Hello

I load an external library written in Delphi (I don't have any source
code of this lib). I do it in this way:

[System.Runtime.InteropServices.DllImport("myLib.dll",
EntryPoint="externalMethod")]
public static extern bool userExist(string userName, string password);

Next I launch freely the userExist method and everything works fine. I
mean that the method returns the correct results.I able to run this
method couple times any is no problem with execution. But when I close
the program I get 2 errors.
1. "Unknown exception code (0x0eedfade) occurred at 0x7c81eb33."
2. "Runtime error 217 at 00009DF8"

Second message appears when I click Ok on the first error. I tied to
catch this exception on method level and whole application (by using
try-catch on Application.Run). Unfortunately nothing helps and the
messages still appears. Is it possible to switch off showing errors
from external libraries or maybe is possible to release the external
methods during run time.

Thank you for your help
 
N

Nicholas Paldino [.NET/C# MVP]

Are you sure the problem arises from using this library? Are there any
other calls you have to make in order to initialize the library?

Also, are you sure you have the signature correct in .NET? Can you show
the original signature?
 
J

Jani Järvinen [MVP]

Hello!
I load an external library written in Delphi (I don't have any source
code of this lib). I do it in this way:

[System.Runtime.InteropServices.DllImport("myLib.dll",
EntryPoint="externalMethod")]
public static extern bool userExist(string userName, string password);

Just a quick note: your trouble can be caused by Delphi's string types.
Depending on which Delphi version was used to build the DLL, the Delphi
strings can be different from what C# (.NET) expects. The safest thing is to
use PChars in Delphi code when interoperability is expected.
But when I close the program I get 2 errors.
1. "Unknown exception code (0x0eedfade) occurred at 0x7c81eb33."
2. "Runtime error 217 at 00009DF8"

Have you tried to call the DLL from a Delphi host application? Does the
error occur then? Either the DllImport signature is incorrect (like Nicholas
already suggested) or the Delphi DLL is incorrectly programmed. For example,
and object is freed twice upon shutdown, or used after it has been freed.

If you have the source code for the Delphi DLL, double-check to see how it
should be used (see again Nicholas' reply) or there are bugs in the DLL
code.

--
Regards,

Mr. Jani Järvinen
C# MVP
Helsinki, Finland
(e-mail address removed)
http://www.saunalahti.fi/janij/
 
T

t0x3e8

Hello

Thank you for your answers. Establish to your posts I have prepared a
small program where I tested only the external method. So I got the
same error which I mentioned yesterday but I discovered the one
strange thing, namely if I run the test application not from visual
studio then everything goes fine and no error appears but from Visual
studio errors still popups.
Jani I have no possibility to see the delphi code. Either I don't know
the delphi version I suppose it is 7 but I am not sure. This library
was made by someone two years ago and it worked with delphi program
(no errors, no problems) till now. Now my company rewrites some
solutions in .NET and sometimes I meet some exceptions but no hard
like this one.

On your mail I will send you the test application. I hope that will
help you to get closer my problem.
Thank you once again
bye
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top