[DLLImport] Attribute where is default dll location

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have a DLL with unmanaged function written in C. I need to call from
managed C# code, where should DLL have to placed, bin folder system32? And
can this location be changed. I haven't found anything useful in this regard
on MSDN documentation.
Thank you
 
If it is registered in the registry, you should be able
to just add a COM reference to it in your project.
 
Robbe,

Two things here.

First, the poster was asking for the search path for the DllImport
attribute, which is used with the P/Invoke layer, not COM interop. In this
case, the P/Invoke layer uses LoadLibrary to load the DLL, and will follow
those rules for locating the DLL.

This means that you can also call LoadLibrary yourself if you need to
load the DLL outside of a location in the search path. This way, the DLL is
loaded in the process, and the P/Invoke call will succeed.

Also, in reference to COM, in XP, you can actually have
registration-free COM, by placing the details of the COM server in your
manifest file. Calls to CoCreateInstance/CoCreateInstanceEx will then look
through the loaded details from the manifest file first, and then in the
registry.

Hope this helps.
 
Thanks,

Yes, it's not COM object. It's one DLL file library of C function(s).
First, the poster was asking for the search path for the DllImport
attribute, which is used with the P/Invoke layer, not COM interop. In this
case, the P/Invoke layer uses LoadLibrary to load the DLL, and will follow
those rules for locating the DLL.

What are the rules?
This means that you can also call LoadLibrary yourself if you need to
load the DLL outside of a location in the search path. This way, the DLL is
loaded in the process, and the P/Invoke call will succeed.

Do you have any code samples, links?

Thank you

Nicholas Paldino said:
Robbe,

Two things here.

First, the poster was asking for the search path for the DllImport
attribute, which is used with the P/Invoke layer, not COM interop. In this
case, the P/Invoke layer uses LoadLibrary to load the DLL, and will follow
those rules for locating the DLL.

This means that you can also call LoadLibrary yourself if you need to
load the DLL outside of a location in the search path. This way, the DLL is
loaded in the process, and the P/Invoke call will succeed.

Also, in reference to COM, in XP, you can actually have
registration-free COM, by placing the details of the COM server in your
manifest file. Calls to CoCreateInstance/CoCreateInstanceEx will then look
through the loaded details from the manifest file first, and then in the
registry.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Robbe Morris said:
If it is registered in the registry, you should be able
to just add a COM reference to it in your project.
 
The search order used by the OS is:
1.. The directory where the executable module for the current process is
located.
2.. The current directory.The Windows system directory.

3.. The "Windows System" directory. (e.g c:\Windows\System32)

4.. The "Windows" directory. (e.g c:\Windows)

5.. The directories listed in the PATH environment variable.

Willy.

Lenn said:
Thanks,

Yes, it's not COM object. It's one DLL file library of C function(s).


What are the rules?

The search order used by the OS is:
1.. The directory where the executable module for the current process is
located.
2.. The current directory.The Windows system directory.

3.. The "Windows System" directory. (e.g c:\Windows\System32)

4.. The "Windows" directory. (e.g c:\Windows)

5.. The directories listed in the PATH environment variable.

Check MSDN for details on LoadLibrary and LoadLibraryEx.
Do you have any code samples, links?

Mind to google for LoadLibrary and CSharp?

Willy.
 
That's great. Thanks

Willy Denoyette said:
The search order used by the OS is:
1.. The directory where the executable module for the current process is
located.
2.. The current directory.The Windows system directory.

3.. The "Windows System" directory. (e.g c:\Windows\System32)

4.. The "Windows" directory. (e.g c:\Windows)

5.. The directories listed in the PATH environment variable.

Willy.



The search order used by the OS is:
1.. The directory where the executable module for the current process is
located.
2.. The current directory.The Windows system directory.

3.. The "Windows System" directory. (e.g c:\Windows\System32)

4.. The "Windows" directory. (e.g c:\Windows)

5.. The directories listed in the PATH environment variable.

Check MSDN for details on LoadLibrary and LoadLibraryEx.


Mind to google for LoadLibrary and CSharp?

Willy.
 
I read C and "thought C++" and assumed it was COM.

You is correct

--
Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.eggheadcafe.com/forums/merit.asp





Nicholas Paldino said:
Robbe,

Two things here.

First, the poster was asking for the search path for the DllImport
attribute, which is used with the P/Invoke layer, not COM interop. In
this case, the P/Invoke layer uses LoadLibrary to load the DLL, and will
follow those rules for locating the DLL.

This means that you can also call LoadLibrary yourself if you need to
load the DLL outside of a location in the search path. This way, the DLL
is loaded in the process, and the P/Invoke call will succeed.

Also, in reference to COM, in XP, you can actually have
registration-free COM, by placing the details of the COM server in your
manifest file. Calls to CoCreateInstance/CoCreateInstanceEx will then
look through the loaded details from the manifest file first, and then in
the registry.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Robbe Morris said:
If it is registered in the registry, you should be able
to just add a COM reference to it in your project.
 
Back
Top