Home All Groups Group Topic Archive Search About

DllImport attribute

Author
3 Apr 2007 2:42 PM
Dmitry Dorobin
How I can write somthing like this:
[DllImport("%ProgramFiles%\\aaa.dll")]

where %ProgramFiles% - some DOS variable?

Author
3 Apr 2007 7:06 PM
Mattias Sjögren
>How I can write somthing like this:
>[DllImport("%ProgramFiles%\\aaa.dll")]
>
>where %ProgramFiles% - some DOS variable?

You can't. What you can do instead is is to just use
[DllImport("aaa.dll")], and then explicitly load the DLL with
LoadLibrary before using it.


Mattias

--
Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Are all your drivers up to date? click for free checkup

Author
4 Apr 2007 1:52 PM
Dmitry Dorobin
>
> >How I can write somthing like this:
> >[DllImport("%ProgramFiles%\\aaa.dll")]
> >
> >where %ProgramFiles% - some DOS variable?
>
> You can't. What you can do instead is is to just use
> [DllImport("aaa.dll")], and then explicitly load the DLL with
> LoadLibrary before using it.

Oh! Sorry for stupid question... Can you show me how I can do this?
Something like this doesn't work correct...

[DllImport("kernel32.dll")]
static extern IntPtr LoadLibrary(string lpFileName);

[DllImport("aaa.dll")]
static extern void bbb();

void main()
{
  IntPtr lib = LoadLibrary("C:\\Program Files\\...Some path...\\aaa.dll");
  bbb();
}

Bookmark and Share