473,626 Members | 3,322 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to dynamically load an exported class?

Hi All,

I know that I can use the GetProcAddress to get the proc address of a global
exported function from a WIn32 dll.

But if I have an exported class in the dll, is there a way to dynamically
load this dll and get an instance of this class? (No static linking with the
lib file) I am currently thinking about having global exported functions
which internally calls the member functions of the class's single instance.
These global exported dunctions can be accessed through GetProcAddress anyway.

Can anyone please throw some light into this?

TIA,
Jessy

Jul 30 '08 #1
4 2682
Jessica wrote:
Hi All,

I know that I can use the GetProcAddress to get the proc address of a
global exported function from a WIn32 dll.

But if I have an exported class in the dll, is there a way to
dynamically load this dll and get an instance of this class? (No
static linking with the lib file) I am currently thinking about
having global exported functions which internally calls the member
functions of the class's single instance. These global exported
dunctions can be accessed through GetProcAddress anyway.

Can anyone please throw some light into this?

The usual way is to have a factory method, an exported C function used to create
the desired class (something like COM DllGetClassObje ct). Your client only needs
the factory method signature and the class definition.

Regards

--
Cholo Lennon
Bs.As.
ARG

Jul 30 '08 #2

"Jessica" <Je*****@discus sions.microsoft .comha scritto nel messaggio
news:EE******** *************** ***********@mic rosoft.com...
But if I have an exported class in the dll, is there a way to dynamically
load this dll and get an instance of this class? (No static linking with
the
lib file) I am currently thinking about having global exported functions
which internally calls the member functions of the class's single
instance.
These global exported dunctions can be accessed through GetProcAddress
anyway.

Can anyone please throw some light into this?
What you propose (i.e. a pure-C wrapping interface to your C++ class) is an
option.

However, you may also consider exporting a factory function, which creates
an instance of your class, so you can use GetProcAddress( ) to get a pointer
to the factory function, and call the factory function to create an instance
of the class.

i.e. you can export a function like this from the DLL:

CMyClass * BuildMyClass();

and call GetProcAddress( ) to get its address after loading the DLL with
LoadLibrary(), and then call that function to get a CMyClass pointer.

HTH,
Giovanni

Jul 30 '08 #3
Cholo Lennon wrote:
Jessica wrote:
>Hi All,

I know that I can use the GetProcAddress to get the proc address of a
global exported function from a WIn32 dll.

But if I have an exported class in the dll, is there a way to
dynamically load this dll and get an instance of this class? (No
static linking with the lib file) I am currently thinking about
having global exported functions which internally calls the member
functions of the class's single instance. These global exported
dunctions can be accessed through GetProcAddress anyway.

Can anyone please throw some light into this?


The usual way is to have a factory method, an exported C function
used to create the desired class (something like COM
DllGetClassObje ct). Your client only needs the factory method
signature and the class definition.
BTW, to avoid problems with different heaps, you can also export a complementary
function to destroy the object.

Regards

--
Cholo Lennon
Bs.As.
ARG

Jul 30 '08 #4

"Cholo Lennon" <ch*********@ho tmail.comha scritto nel messaggio
news:OB******** ******@TK2MSFTN GP05.phx.gbl...
BTW, to avoid problems with different heaps, you can also export a
complementary
function to destroy the object.
Or use a reference counting technique like COM AddRef/Release (and when
reference counter becomes 0, the object destroys itself).

Giovanni

Jul 30 '08 #5

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

Similar topics

2
1778
by: Kevin Crosbie | last post by:
Hi, I have the following situation: I have a 3rd party DLL which does not include a LIB file, just a header file with typedef declarations for exported functions (It is intended for dynamic linking) I need to wrap the DLL to allow for callbacks to my own code (in Lisp), and to do this I need to load the DLL using LoadLibrary and access each function
4
20295
by: DotNetJunkies User | last post by:
Hi, Does anyone know how/if you can instantiate a C# reference type object dynamically? More specifically, my project has a number of classes that I've created and in some cases it would be very handy to be able to instantiate them based on a string variable representing their class name. Here's an example of what I'd be looking to do. public object DynamicInstantiation(string className) { return new ; }
1
2567
by: Kamal Jeet Singh | last post by:
Hi Friends !! I am facing problem in controlling the dynamically created controls on web page. The problem Scenario is Scenario:- My requirement is to load the web user controls on the web page dynamically. To do this, First I including a web page (MainPage.aspx) and I made form tag to Runat=Server. I included one table tag and also made this table Runat=Server side. Second I created three Web User Controls e.g. wucCustomerInfo.ascx,
3
2165
by: Egbert Nierop \(MVP for IIS\) | last post by:
Hi, I have a complex asp.net 1.1 program that dynamically needs to load controls (LoadControl) The textboxes etc inside these controls keep viewstate and values but not within Page_Load() when that event is 'going on' the load control happens but the values are not yet 'filled in' They are filled in only -when- the pageload event has
1
1022
by: Reza Nabi | last post by:
Bakground: I have a webform (LoadCtl.aspx) which loads the user control to a placeholder dynamically based on the ctlName querystring passed in the URL. Webform (LoadCtl.aspx) also passes a variable (targetId) in to the usercontrol (IntergySite.aspx) by calling its setter method. Currently, I am using if-then-else and hardcoded the User Control Object to do casting and call the setter method. Question: Is there any way I could load,...
6
3367
by: Steve Booth | last post by:
I have a web form with a button and a placeholder, the button adds a user control to the placeholder (and removes any existing controls). The user control contains a single button. I have done all the usual stuff of recreating the usercontrol in the Page Init event. The 'failure' sequence is as follows: - select web form button to display the user control - select user control button, event fires - select web form button to display...
5
2167
by: Konstantin Andreev | last post by:
Recently I became interested, - Are the data, bulk loaded in the table with LOAD utility, consume the same disk space as loaded with IMPORT utility? The answer turned out to be NOT ! Here is a nutshell description of the test. The testing was done at "DB2/LINUX 8.2.3". Tables for tests: F4106 has 5203 rows, 32 columns. F42199 has 1399252 rows, 245 columns.
2
5105
by: Smithers | last post by:
I have a Windows Forms application that implements a plug-in architecture whereby required assemblies are identified and loaded dynamically. Here are the relevant classes: A = application = Windows Forms class B = a singleton hosted within A. B is responsible for dynamically loading classes X, Y, and Z.
1
4080
by: filhodapuc | last post by:
How to Load the class "MyContent" dynamically ? I have 1 interface<T>, 1 abstract generic class<T> and 1 class. Check my code out: public interface IMyObjectInterface{ } public abstract MyAbstractObject : IMyObjectInterface{ } public class MyObject : MyAbstractObject{ }
0
8705
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
8637
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
8364
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
7193
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6125
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
5574
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();...
0
4092
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4197
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1808
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.