473,386 Members | 1,720 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,386 software developers and data experts.

Flexible DllImport

Hello, is there anyway to import unmanaged functions in a DLL file that
locate somewhere out of the current path?

Like this, when the app start, it'll locate the dll file, once it found
the file, it'll import the file's functions.

But the problem is, I have the location of the file store in a string
variable, I can't find a way to use that string variable with DllImport?
Nov 16 '05 #1
4 2165
You can use Reflection.Emit namespace functions to create the code at runtime, which specifies the DllImport attribute
taken from that string variable... Its just my idea, I don't know how complex it is..

HT
Sunil
Nov 16 '05 #2
"FrzzMan" <Fr***************@vnOCzone.com> wrote in message
news:ek**************@TK2MSFTNGP12.phx.gbl...
Hello, is there anyway to import unmanaged functions in a DLL file that
locate somewhere out of the current path?

Like this, when the app start, it'll locate the dll file, once it found
the file, it'll import the file's functions.

But the problem is, I have the location of the file store in a string
variable, I can't find a way to use that string variable with DllImport?


You can use a combination of "LoadLibrary" or "LoadLibraryEx" with
"FreeLibrary" as an option. Once the DLL has been loaded with either of the
"Load?" functions, you can call its methods without specifying the full path
to the file in the DllImport. Another option may be to use
"SetDllDirectory", though I haven't actually tested that one. The first I
mentioned definitely works.

Good luck,
Ryan LaNeve
Nov 16 '05 #3
"Ryan LaNeve" <rl*****@noaviincspam.com> wrote in message
news:u3*************@TK2MSFTNGP12.phx.gbl...
You can use a combination of "LoadLibrary" or "LoadLibraryEx" with
"FreeLibrary" as an option. Once the DLL has been loaded with either of the "Load?" functions, you can call its methods without specifying the full path to the file in the DllImport. Another option may be to use
"SetDllDirectory", though I haven't actually tested that one. The first I
mentioned definitely works.

Good luck,
Ryan LaNeve

I forgot to include this link in case you need it:
http://msdn.microsoft.com/library/de..._functions.asp
(watch for line-wrap)

Ryan LaNeve
Nov 16 '05 #4
Currently I don't know how to use Emit namespace, but I'm reading
documentation about it @ MSDN. Hope your idea will do the trick :)

Thank you.

But, let me explain my scenario, hope this will help you understand
better the problem and help me, of course :D

My app is plugins-based, when user want to use unavailable features, it
will request the server and the server will send the plugins to it.
After that it will save the DLL file somewhere (so that user can keep
all the plugins in the safe place).

The app will search for plugins when it need to use it, once found it'll
load the DLL and call the function, unfortunately most of them are
unmanaged, but fortunately the plugins are all have the same functions
list, so it won't be a problem of calling unavailable function.

The problem is, the plugins file are saved to unpredictable place, user
will specify it. So the DllImport seem to be useless :(

TIA, if you have better approach, please tell me, too :)

Sunil wrote:
You can use Reflection.Emit namespace functions to create the code at runtime, which specifies the DllImport attribute
taken from that string variable... Its just my idea, I don't know how complex it is...

HTH
Sunil

Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: H. van Kooten via .NET 247 | last post by:
Hello, I've got the following code: namespace Test1 { public struct stTest { public const string sDll = "C:\\Test1\\Test1.dll";
10
by: Adam Warner | last post by:
Hi all, With this structure that records the length of an array of pointers as its first member: struct array { ptrdiff_t length; void *ptr; };
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...
9
by: Ole Christensen | last post by:
I'm trying to make a sort of conditional compilation in my C# code because my app is intended to run on both a Pocket PC and on a normal desktop PC. My code uses a call to an API function that on...
3
by: Mark Jerde | last post by:
I'm sill learning VS .NET 2003, not an expert yet. I'm calling an unmanaged C++ DLL from C# using . When the whole project is done I will be calling a total of 5 C++ DLLs from C#. All the DLLs...
1
by: Brian Anderson | last post by:
Hello, I have a native, C++ console app that uses ~26MB of RAM when it runs. It uses quite a lot of RAM to make some math but will never xceed 26MB. Now I've made a dll out of this code and...
2
by: Brian Anderson | last post by:
Hello, is it possible to use DllImport to call a DLL in ASP.NET ? Or is it necessarry that my DLL has to be copied into \System32 ? My DLL is a native C++ 7.1 DLL (not managed, no COM, no...
2
by: Ed | last post by:
Hello, dear all, I often see these two import usage in the code. Both are the interface to use the Dll library. I think they are the same. Normally P/Invoke means using the to import the dll....
1
by: elke | last post by:
Hi, I want to use an unmanaged dll in C# .net and I'm having some troubles witch a function that should return an array. I'm new at this, so I don't know what I'm doing wrong. Here is some...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.