473,839 Members | 1,502 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Loading dlls dynamically

How do I load and run dll functions dynamically please? The dll may be
anywhere and its location is set in a command line parameter.

I've loaded the dll OK, done the equivalent of GetProcAddress

// kernel32, not used dynamically as it's fixed location.
[DllImport("kern el32.dll")]
internal static extern IntPtr LoadLibrary(Str ing dllname);
[DllImport("kern el32.dll")]
internal static extern IntPtr GetProcAddress( IntPtr hModule, String
procname);

// DynamicLibName is path/name of a dll on file system.
IntPtr Handle = LoadLibrary(Dyn amicLibName);
IntPtr GetError = GetProcAddress( Handle, "GetError") ;

If the function declaration for GetError is "int GetError(int ErrorNum" how
do I move on from the above to "return GetError(3);"

From old Delphi days I realize I must declare some kind of type, then link
it to the "GetError" procedure address. Im stuck on this bit.

I was following an example on a microsoft blog, they gave examples for a new
feature in the next version of dotnet - no good for my version. Their link
to a faq doing the same with version 1.1 required a userid and password, so
I was stuck.
Code or a link to a web site would be appreciated as I probably won't
understand a general overview of the process
Nov 16 '05 #1
2 2549
RCS
I'm not sure exactly what you are saying.

In order to compile, you'll need to have an available version of a library
(except maybe when you use extern?)

But assuming that is the case, but you want to swap out the version at
runtime, I believe System.Reflecti on is going to be the only way. Something
like System.Reflecti on.Assembly.Loa d()
"Claire" <ha*@notonyourn elly.coom> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
How do I load and run dll functions dynamically please? The dll may be
anywhere and its location is set in a command line parameter.

I've loaded the dll OK, done the equivalent of GetProcAddress

// kernel32, not used dynamically as it's fixed location.
[DllImport("kern el32.dll")]
internal static extern IntPtr LoadLibrary(Str ing dllname);
[DllImport("kern el32.dll")]
internal static extern IntPtr GetProcAddress( IntPtr hModule, String
procname);

// DynamicLibName is path/name of a dll on file system.
IntPtr Handle = LoadLibrary(Dyn amicLibName);
IntPtr GetError = GetProcAddress( Handle, "GetError") ;

If the function declaration for GetError is "int GetError(int ErrorNum"
how do I move on from the above to "return GetError(3);"

From old Delphi days I realize I must declare some kind of type, then link
it to the "GetError" procedure address. Im stuck on this bit.

I was following an example on a microsoft blog, they gave examples for a
new feature in the next version of dotnet - no good for my version. Their
link to a faq doing the same with version 1.1 required a userid and
password, so I was stuck.
Code or a link to a web site would be appreciated as I probably won't
understand a general overview of the process

Nov 16 '05 #2
Hi...

In essence, you are loading a module and getting a pointer to the function
you want to call. Hmmm, in .NET, a pointer to a function is delegate. Try
creating a delegate for the function you want to call and then call the
function through the delegate.

John Puopolo
"Claire" <ha*@notonyourn elly.coom> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
How do I load and run dll functions dynamically please? The dll may be
anywhere and its location is set in a command line parameter.

I've loaded the dll OK, done the equivalent of GetProcAddress

// kernel32, not used dynamically as it's fixed location.
[DllImport("kern el32.dll")]
internal static extern IntPtr LoadLibrary(Str ing dllname);
[DllImport("kern el32.dll")]
internal static extern IntPtr GetProcAddress( IntPtr hModule, String
procname);

// DynamicLibName is path/name of a dll on file system.
IntPtr Handle = LoadLibrary(Dyn amicLibName);
IntPtr GetError = GetProcAddress( Handle, "GetError") ;

If the function declaration for GetError is "int GetError(int ErrorNum" how do I move on from the above to "return GetError(3);"

From old Delphi days I realize I must declare some kind of type, then link
it to the "GetError" procedure address. Im stuck on this bit.

I was following an example on a microsoft blog, they gave examples for a new feature in the next version of dotnet - no good for my version. Their link
to a faq doing the same with version 1.1 required a userid and password, so I was stuck.
Code or a link to a web site would be appreciated as I probably won't
understand a general overview of the process

Nov 16 '05 #3

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

Similar topics

9
4498
by: Ender | last post by:
I have an application that I would like third party developers to be able to create Plug-ins that will be dynamically loaded into our application to extend functionality. I have utilized the "Let Users Add Functionality to Your .NET Applications with Macros and Plug-Ins" article at MSDN for the dynamic loading of DLLs http://msdn.microsoft.com/msdnmag/issues/03/10/Plug-Ins/default.aspx
0
1623
by: Oenone | last post by:
I have created a number of "plug-in" DLLs for my ASP.NET application which are dynamically loaded at run-time. This is done by locating the DLL file on disk and loading it using the Assembly.LoadFrom(Filename) function. It's important that the DLLs are shadowed by ASP.NET so that they can be easily updated. To get this to work I have placed the DLLs into the bin\ directory inside my web application. This seems to work fine. However, to...
6
6883
by: Dan Dorey | last post by:
I actually have two questions here, but I'll start by giving an outline of what I'm trying to do. I'm building an app with a simple plugin architecture (all in the same app domain). I have each plugin in a separate sub-dir inside a "Plugins" directory. Each plugin consists of at least two DLLs (a controller and a driver). However, most drivers also rely on other external DLLs. In one particular case this dependency is to a C++ DLL...
2
1716
by: =?Utf-8?B?SmF0aW5kZXI=?= | last post by:
Hi, I have written dlls in c# that are being used by other applications. My application works fine if I add these dlls to executable folder,but when I place these dlls in another folder my application crashes. Is there any way to load these dlls from folder other than executable folder. If yes, How will I do that.
1
1502
by: davidmurray1 | last post by:
I have a C++ app on my flash drive that i am running, but often times, i must take the flash drive out of the computer and use it elsewhere while the executable continues to run. however, the executable's behavior is sporadic, and it will disappear. I think the app is calling a DLL that exists in the current directory, but since the flash drive is gone, it can't find it. so, i wanted to know if i could load the executable with all of...
0
9855
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9697
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10907
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10586
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10647
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10293
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7828
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7017
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4484
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.