473,394 Members | 1,971 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

[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 25748
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Jim | last post by:
I am extremely frustrated. I am building c# application for a call center and am using a third party API to access some hardware. When develop and test my class using the windows console the...
5
by: Jason Bell | last post by:
I'm an experienced programmer, but a newbie to c#, so please be kind :) In a c++, unmanaged, DLL of my own making I have a function called void XGL_Core_SetCaption(XGL_Core * core, char *...
2
by: | last post by:
Hi everyone, Can you have a quick look and tell me why the caret is not shown , any help will be greatly appreicated thank you. using System; using System.Drawing; using System.Collections;...
9
by: Gnic | last post by:
Hi, I have a (Complied) C Library that needs to be called using c# code, some of the function require char* parameter(in and out) Here is the problem, There is a function that expect an...
2
by: =?Utf-8?B?U0FM?= | last post by:
Hello, I am getting the following error: "An attribute argument must be a constant expression, typeof expression or array creation expression" with this line of code on my GetDLLName() that...
3
by: =?Utf-8?B?RGlvZ28gQWx2ZXM=?= | last post by:
greentings I have a unmanaged dll that I need to use on my C# app. The problem is that the dll may be in diferent places... The only way I have to get the location of the dll is getting a key on...
1
by: John Dinning | last post by:
(Using VS2005 C# and compact Framework. Target device is running CE5). I am creating a simple visual control (New Control Library project for smart device Windows CE 5), derived from Label, with...
1
by: Larry | last post by:
I have an asp.net application (C#) that calls a web service that uses several c++ dlls which are loaded with DllImport. I put these dlls in a sub-directory off of the bin directory. For example,...
2
by: Nathan Sokalski | last post by:
I am attempting to create icons for controls I have created using VB.NET by using the System.Drawing.ToolboxBitmap attribute. I have managed to do this in C# by specifying the path to the *.ico...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.