C# and DLLs

  • Thread starter Thread starter DBfromMN
  • Start date Start date
D

DBfromMN

I'm trying to call unmanaged functions in a DLL from a C#
client program.
I've been over an over the tutorials and samples, but
still I'm missing something.
When one of these functions is called from the client
program, an unhandled exception is thrown stating that
there is no entry point in the dll by that name.
In the dll, I've qualified the function like this:

__declspec(dllexport) int iFunction(int);

In the client, I add this to a class

[DllImport("MyDll.dll")]
public static extern int iFunction(int iIn);

When I call the function, the dll is loaded, but the
iFunction name is not found.

Is there something else I need to do?
Thanks in advance.
Dennis
 
Is there something else I need to do?

Use a tool such as Dumpbin or Dependency Walker to find out the
exported name of the function, it's probably mangled.



Mattias
 
__declspec(dllexport) int iFunction(int);

instead try:

#ifdef __cplusplus
#define EXPORT extern "C" __declspec (dllexport)
#else
#define EXPORT __declspec (dllexport)
#endif
EXPORT int iFunction(int);
 
-----Original Message-----

instead try:

#ifdef __cplusplus
#define EXPORT extern "C" __declspec (dllexport)
#else
#define EXPORT __declspec (dllexport)
#endif
EXPORT int iFunction(int);



.
It works!!!!!!!!!!!!!!!!!!!

Thanks a lot. This has been driving me nuts!
Dennis
 
Hello,
Thank you for you advice. Thanks to Wiktor, I was able to
make it work by using a different dllexport declaration:
extern "C" __dllspec(dllexport)
Dennis
-----Original Message-----
Hi,

Take a look at the PInvoke tutorial in MSDN...

http://msdn.microsoft.com/library/default.asp?
url=/library/en-
us/csref/html/vcwlkPlatformInvokeTutorial.asp

Regards,
Madhu

MVP | MCSD.NET
-----Original Message-----
I'm trying to call unmanaged functions in a DLL from a C#
client program.
I've been over an over the tutorials and samples, but
still I'm missing something.
When one of these functions is called from the client
program, an unhandled exception is thrown stating that
there is no entry point in the dll by that name.
In the dll, I've qualified the function like this:

__declspec(dllexport) int iFunction(int);

In the client, I add this to a class

[DllImport("MyDll.dll")]
public static extern int iFunction(int iIn);

When I call the function, the dll is loaded, but the
iFunction name is not found.

Is there something else I need to do?
Thanks in advance.
Dennis
.
.
 
Back
Top