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 6 25469
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
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
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
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.
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.
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
This discussion thread is closed Replies have been disabled for this discussion. Similar topics
15 posts
views
Thread by Jim |
last post: by
|
5 posts
views
Thread by Jason Bell |
last post: by
|
2 posts
views
Thread by |
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
|
2 posts
views
Thread by Nathan Sokalski |
last post: by
| | | | | | | | | | |