DllImport path issue

S

Steve

I'm sure I'm missing something basic.
I have an class library that uses an unmanaged dll.

Let's say the class library is called "CL1.dll" and is located at:
[c:\temp\CL\CL1.dll]
and the unmanaged dll is called "UM.dll" and is located at [c:\temp\UM.dll]

For my DllImport attribute I was using [DllImport("c:\temp\UM.dll")] and
this worked.

Now I want to setup my installer so I can deploy this app and I realize that
I can't hard code the path like that. So I tried copying [UM.dll] to
[c:\temp\CL\] thinking that if it was in the same directory as CL1.dll it
would find it if I did this: [DllImport("UM.dll")]

no luck. Throws an exception saying it can't find it.

Then I thought I might still need to supply the full path, so I tried using
the Assembly class to get the executing path oc CL1.dll. This doesn't work
because DllImport needs a const string.


so.. how do I do this? Seems like it should be easy, but it's beating me...
:(

Thanks,
Steve
 
S

Steve

Mattias Sjögren said:
Place it in the directory of the application that consumes the class
library, or in some other directory searched by LoadLibrary. See

http://msdn.microsoft.com/library/en-us/dllproc/base/dynamic-link_library_search_order.asp

HI,
Mattias

I tried that and I'm still getting the error. My Exe that consumed the
managed dll, the managed dll and the unmanaged dll that it wraps are all in
the same folder. I looked over the link that you send me, but I don't see a
solution in there for my situation.

Anything else that I can try?

-Steve
 
S

Steve

It was another assembly that wasn't loading correctly. It's tough to find
these types of probs in release mode!

Anyway, thanks again for the help.
-Steve


Steve said:
Mattias Sjögren said:
Place it in the directory of the application that consumes the class
library, or in some other directory searched by LoadLibrary. See

http://msdn.microsoft.com/library/en-us/dllproc/base/dynamic-link_library_search_order.asp

HI,
Mattias

I tried that and I'm still getting the error. My Exe that consumed the
managed dll, the managed dll and the unmanaged dll that it wraps are all
in the same folder. I looked over the link that you send me, but I don't
see a solution in there for my situation.

Anything else that I can try?

-Steve
 
S

Steve

Mattias Sjögren said:
Place it in the directory of the application that consumes the class
library, or in some other directory searched by LoadLibrary. See

http://msdn.microsoft.com/library/en-us/dllproc/base/dynamic-link_library_search_order.asp

Well, I spoke too soon. This is still very much broken. I am trying to run
my application in release mode on another machine. When it crashes I click
the 'debug' and then see the exception:

<exception>
Failed to load module from assembly FETProgrammerModule, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null. Error was:
Failed to load module from assembly FETProgrammerModule, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null. Error was:
Unable to load DLL 'msp430.dll': The specified procedure could not be found.
(Exception from HRESULT: 0x8007007F)
</exception>


All of my assemblies are in a single folder.
This is so frustrating, I don't understand why it won't search in the folder
it's being consumed from??

Please, anyone have any other tips for me?
 
S

Steve

Yes, that appears to be the real problem. The unmanaged DLL did need
another DLL that I wasn't supplying a path to.
Thanks for the idea, it worked out well for me.

Have a great day,
Steve
 

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