Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / November 2006

Tip: Looking for answers? Try searching our database.

Problem finding DLL

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rich - 17 Nov 2006 16:30 GMT
I am trying to use unmanaged DLLs within managed code.  My approach is
to create a managed DLL with wrapper functions for my unmanaged
functions.  The unmanaged functions come from an unmanaged DLL.

I can successfully build my managed DLL and use it from managed code.
However, at runtime the code cannot find the unmanaged DLL.  I've tried
putting the unmanaged DLL in the same directory as the code is running
from, in C:\Windows\System32, and a few other places - no luck, I
always get an error indicating that the unmanaged DLL cannot be found.

Here is what I do in my managed DLL to access functions in the
unmanaged DLL:

    using namespace System::Runtime::InteropServices;

    [DllImport("ADT_API_L1", EntryPoint="ADT_L1_Initialize")]
    extern "C" unsigned int ADT_L1_Initialize(unsigned int dev_num,
char *filename);

The unmanaged DLL is "ADT_API_L1.dll".  In the code for the managed DLL
I also define a namespace and classes with member functions that call
unmanaged functions like "ADT_L1_Initialize" - I left this out to keep
this as uncluttered as possible.

>From my managed CLR application I include the managed DLL as a
reference and I can see my namespace, classes, etc.  The managed
application compiles without error, but when I run the program it
chokes and dies, giving an error that it cannot load the DLL
(System.DllNotFoundException).

I'm sure there is something simple and stupid that I am missing.  Can
anybody here set me straight?
Bruno van Dooren [MVP VC++] - 18 Nov 2006 12:08 GMT
> I can successfully build my managed DLL and use it from managed code.
> However, at runtime the code cannot find the unmanaged DLL.  I've tried
> putting the unmanaged DLL in the same directory as the code is running
> from, in C:\Windows\System32, and a few other places - no luck, I
> always get an error indicating that the unmanaged DLL cannot be found.

The DLLs get loaded at runtime.
To make sure that you native dll is found
put it alongside the assembly in which it is imported or install it on your
disk somewhere, and add the containing folder in your path variable.

Now, there are 2 things to keep in mind:
- putting stuff in the system32 directory is frowned upon. you generally
don't want to do this to avoid DLL hell.
- be sure that your native DLL can also resolve its dll dependencies. it
will fail to load if one of its dependencies cannot be found (like e.g. the
VC runtime dlls)

Signature

Kind regards,
   Bruno van Dooren
   bruno_nos_pam_van_dooren@hotmail.com
   Remove only "_nos_pam"

Rich - 18 Nov 2006 15:14 GMT
Bruno,

I figured out my problem (I was doing something stupid), but thanks for
your response.
I do have another question related to DLLs, but I put it in a new post.

Thanks again,
Rich

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.