Error loading unmanaged dll from managed code

A

Andrew Falanga

Hi,

I have a C# class library that has to draw upon an unmanaged, C++,
library that is itself a project in this solution. So, because of how
this library is to be used, the C++ dll is built and placed in C:\temp
(I figure it's a directory everyone should have).

This strategy worked just fine until I re-imaged my box (a work place
requirement), yesterday. My solution builds just fine but when I run
the test driver program for the class library, I get this error,
"Unable to load DLL 'C:\\temp\\UnManaged.dll': The specified module
could not be found. (Exception from HRESULT: 0x8007007E)."

I've checked the c:\temp directory and the file *is* there. In the
code, I reference the dll thusly,

using System.Runtime.InteropServices;

[DllImport("C:\\temp\\UnManaged.dll", CharSet = CharSet.Ansi)]
private static extern <return_struct> CheckImage(<args>);

Everything is great until the test driver program makes a call to
CheckImage and then, I get the above error. (Yes, the two functions I
need are declared using the appropriate declspec. This was working
prior to the re-image.) So, what may be causing this?

Thanks,
Andy
 
I

Ignacio Machin ( .NET/ C# MVP )

Hi,

I have a C# class library that has to draw upon an unmanaged, C++,
library that is itself a project in this solution.  So, because of how
this library is to be used, the C++ dll is built and placed in C:\temp
(I figure it's a directory everyone should have).

Not at all, check a newly isntalled XP or Vista machine and they do
not have it.

Are you saying that you have an unmanaged project in a managed
solution?
using System.Runtime.InteropServices;

[DllImport("C:\\temp\\UnManaged.dll", CharSet = CharSet.Ansi)]
private static extern <return_struct> CheckImage(<args>);

Everything is great until the test driver program makes a call to
CheckImage and then, I get the above error.  (Yes, the two functions I
need are declared using the appropriate declspec.  This was working
prior to the re-image.)  So, what may be causing this?

Did you google the error code returned?
I would advise again using absolute paths, you should always use
relative paths.
 
A

Andrew Falanga

Not at all, check a newly isntalled XP or Vista machine and they do
not have it.

Interesting. Well, whoever in my organization is responsible for
making the master images for our dev boxes must have put it in place
because I didn't create it and it's there.
Are you saying that  you have an unmanaged project in a managed
solution?

I guess so. The solution has three projects in it. A C++ project
that is compiled into this dll that I'm speaking of. Then, there is
the class library that others in the organization will be using from
their managed code projects. Lastly, there is a managed test driver
program to test the managed class library. If this constitutes an
unmanaged project in a managed solution, then yes, that is what I'm
saying.
using System.Runtime.InteropServices;
[DllImport("C:\\temp\\UnManaged.dll", CharSet = CharSet.Ansi)]
private static extern <return_struct> CheckImage(<args>);
Everything is great until the test driver program makes a call to
CheckImage and then, I get the above error.  (Yes, the two functions I
need are declared using the appropriate declspec.  This was working
prior to the re-image.)  So, what may be causing this?

Did you google the error code returned?
I would advise again using absolute paths, you should always use
relative paths.

I did Google the error return and nothing I found as yet has helped
me.

Andy
 
A

Andrew Falanga

I have a C# class library that has to draw upon an unmanaged, C++,
library that is itself a project in this solution.  So, because of how
this library is to be used, the C++ dll is built and placed in C:\temp
(I figure it's a directory everyone should have).

Not at all, check a newly isntalled XP or Vista machine and they do
not have it.

Are you saying that  you have an unmanaged project in a managed
solution?


using System.Runtime.InteropServices;
[DllImport("C:\\temp\\UnManaged.dll", CharSet = CharSet.Ansi)]
private static extern <return_struct> CheckImage(<args>);
Everything is great until the test driver program makes a call to
CheckImage and then, I get the above error.  (Yes, the two functions I
need are declared using the appropriate declspec.  This was working
prior to the re-image.)  So, what may be causing this?

Did you google the error code returned?
I would advise again using absolute paths, you should always use
relative paths.

Ok, the problem has been solved. I fell victim to poorly worded
output. It wasn't that the file I was building couldn't be found, but
rather, a file that it depended upon. I discovered this by using a
program called Dependency Walker, http://www.dependencywalker.com/,
that was linking in a thread I read from a google search.
(Incidentally, does anyone here know if there is a VS tool that tells
this same information?)

I have another question now, but will start a new thread for this, and
in a C++ newsgroup since this next question is specific to that and
not managed code.

Andy
 

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