469,366 Members | 2,286 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,366 developers. It's quick & easy.

[DLLImport] Attribute where is default dll location

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

Dec 30 '05 #1
6 24814
If it is registered in the registry, you should be able
to just add a COM reference to it in your project.

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

"Lenn" <Le**@discussions.microsoft.com> wrote in message
news:4D**********************************@microsof t.com...
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

Dec 30 '05 #2
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]
- mv*@spam.guard.caspershouse.com

"Robbe Morris [C# MVP]" <in**@eggheadcafe.com> wrote in message
news:uQ*************@TK2MSFTNGP10.phx.gbl...
If it is registered in the registry, you should be able
to just add a COM reference to it in your project.

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

"Lenn" <Le**@discussions.microsoft.com> wrote in message
news:4D**********************************@microsof t.com...
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


Dec 30 '05 #3
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 [.NET/C# MVP]" wrote:
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]
- mv*@spam.guard.caspershouse.com

"Robbe Morris [C# MVP]" <in**@eggheadcafe.com> wrote in message
news:uQ*************@TK2MSFTNGP10.phx.gbl...
If it is registered in the registry, you should be able
to just add a COM reference to it in your project.

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

"Lenn" <Le**@discussions.microsoft.com> wrote in message
news:4D**********************************@microsof t.com...
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



Dec 30 '05 #4
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" <Le**@discussions.microsoft.com> wrote in message
news:99**********************************@microsof t.com...
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?


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.
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?


Mind to google for LoadLibrary and CSharp?

Willy.

Dec 30 '05 #5
That's great. Thanks

"Willy Denoyette [MVP]" wrote:
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" <Le**@discussions.microsoft.com> wrote in message
news:99**********************************@microsof t.com...
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?


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.
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?


Mind to google for LoadLibrary and CSharp?

Willy.

Dec 30 '05 #6
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 [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:OW**************@TK2MSFTNGP15.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Robbe Morris [C# MVP]" <in**@eggheadcafe.com> wrote in message
news:uQ*************@TK2MSFTNGP10.phx.gbl...
If it is registered in the registry, you should be able
to just add a COM reference to it in your project.

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

"Lenn" <Le**@discussions.microsoft.com> wrote in message
news:4D**********************************@microsof t.com...
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



Dec 30 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Jim | last post: by
9 posts views Thread by Gnic | last post: by
2 posts views Thread by =?Utf-8?B?U0FM?= | last post: by
3 posts views Thread by =?Utf-8?B?RGlvZ28gQWx2ZXM=?= | last post: by
1 post views Thread by John Dinning | last post: by
1 post views Thread by Larry | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.