473,386 Members | 1,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Problem finding DLL

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?

Nov 17 '06 #1
2 979
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)

--

Kind regards,
Bruno van Dooren
br**********************@hotmail.com
Remove only "_nos_pam"
Nov 18 '06 #2

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

Nov 18 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Dave | last post by:
Hi all, I've been trying to figure this out for the last day and a half and it has me stumped. I've got a web application that I wrote that keeps track of trading cards I own, and I'm moving it...
7
by: addled | last post by:
Hi there, after reading posts here for a few months, I've built the courage to see if someone can see where I"m going wrong in the webpage I've been working on. In particular the horizontal nav...
117
by: Peter Olcott | last post by:
www.halting-problem.com
2
by: John Jumper | last post by:
I am using an XmlDataSource in VS2005Beta1 and setting the TransformFile property in my ASCX and it is finding both files. However, the resulting data does not contain any of the sub nodes of the...
4
by: | last post by:
I am stuck in a situation and I do believe that this should work, but it doesn't. I have a unmanaged dll, that uses MFC. This works great. Now I recompile the unmanaged dll so it contains...
6
by: Jared Turley | last post by:
I am currently having an issue with an ASP.NET page not finding the class library located in the application's /bin directory. The page recognizes the compiled .dll class when running on my...
1
by: Doug | last post by:
The html below shows DataList "DiscountList" nested within DataList "EventItemList". DiscountList contains a Label control. I'm trying to find the label, using FindControl, during...
6
by: Florian Lindner | last post by:
Hello, I have these class declarations class CBauteil { private: int m_iNumber; int m_iWeight; public: int getNumber(); void setNumber(int);
1
by: Empyrean | last post by:
I'm attempting to make my first program that involves file input, but I'm running into problems finding the .txt file. I placed the file inside the same folder as the rest of the project, but it...
1
by: avik1612 | last post by:
Hi, I have created a program to find text files in a particular directory or folder. and to find a particular word in that files i finding it difficult to put the list in an array and finding...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.