Load DLLs compiled using Mingw

  • Thread starter Thread starter Brandon McCombs
  • Start date Start date
B

Brandon McCombs

Hello,

Yesterday I just started using Visual C# 2005 Express Edition and I'm
trying to load external DLLs. I started out with trying to load just one
like so:

[DllImport("libtest.dll")]
static extern void connections_init();


However when I call the function that wraps connections_init() I'm told
it can't find the libtest.dll and therefore an exception is generated.
This dll is compiled using the Mingw tools. Could that be the problem?
I know that the library can be loaded if using VS6 or VS2003. Also,
my syntax is correct since I can use user32.dll and pop up a message box
with text. I also noticed that if I run regsvr32 on libtest.dll it says
it can't find the library either and of course that is outside of the
VC# 2005 environment. I also placed libtest.dll in c:\windows\system32
and it didn't help. Any ideas?

thanks
 
Hi Brandon,

Is it possible that this libtest.dll depends on other dlls that are not in
the same directory with it or in PATH environment? You can use Dependency
Walker (http://www.dependencywalker.com/) to view the dependent files.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Walter said:
Hi Brandon,

Is it possible that this libtest.dll depends on other dlls that are not in
the same directory with it or in PATH environment? You can use Dependency
Walker (http://www.dependencywalker.com/) to view the dependent files.

Well I know it uses other DLLs but not sure if they are strictly
required. Do I need to specify a DllImport attribute for any DLLs
libtest.dll may depend on or will libtest.dll be able to access them
without importing them?
 
Hi Brandon,

You don't need to import every dependent dlls that libtest.dll uses.
However, if they're not in the same directory of libtest.dll, they need to
be put in a directory that in the PATH environment. Please note if one of
your dependent dll also depends on other files, this rule also applies.
That's why most of the shared dlls are put under %windir%\system32 because
normally this dll is always in the PATH environment.

Let me know if there's anything unclear. Thanks.


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Walter said:
Hi Brandon,

You don't need to import every dependent dlls that libtest.dll uses.
However, if they're not in the same directory of libtest.dll, they need to
be put in a directory that in the PATH environment. Please note if one of
your dependent dll also depends on other files, this rule also applies.
That's why most of the shared dlls are put under %windir%\system32 because
normally this dll is always in the PATH environment.

Let me know if there's anything unclear. Thanks.


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Brandon said:
Yesterday I just started using Visual C# 2005 Express Edition and I'm
trying to load external DLLs. I started out with trying to load just one
like so:

[DllImport("libtest.dll")]
static extern void connections_init();


However when I call the function that wraps connections_init() I'm told
it can't find the libtest.dll and therefore an exception is generated.
This dll is compiled using the Mingw tools. Could that be the problem?

How do you link it ?

Have you tried specifying full path to the DLL in the DllImport ?
I know that the library can be loaded if using VS6 or VS2003. Also, my
syntax is correct since I can use user32.dll and pop up a message box
with text. I also noticed that if I run regsvr32 on libtest.dll it says
it can't find the library either and of course that is outside of the
VC# 2005 environment.

regsvr32 are for COM DLL's not for Win32 DLL's.

Arne
 
Arne Vajhøj said:
Brandon said:
Yesterday I just started using Visual C# 2005 Express Edition and I'm
trying to load external DLLs. I started out with trying to load just one
like so:

[DllImport("libtest.dll")]
static extern void connections_init();


However when I call the function that wraps connections_init() I'm told
it can't find the libtest.dll and therefore an exception is generated.
This dll is compiled using the Mingw tools. Could that be the problem?

Is libtest.dll in the same directory as your .exe?

Did you open it with Dependency Walker (www.dependencywalker.com) and see if
"connections_init" function is exported?

If you know are using mingw tools, are you a C++ programmer? C++/CLI lets
code use both native and managed libraries seamlessly, and create a .NET
library that C# can use just like the built-in classes.
 

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

Back
Top