473,403 Members | 2,366 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,403 software developers and data experts.

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 2666
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 DllGetClassObject). Your client only needs
the factory method signature and the class definition.

Regards

--
Cholo Lennon
Bs.As.
ARG

Jul 30 '08 #2

"Jessica" <Je*****@discussions.microsoft.comha scritto nel messaggio
news:EE**********************************@microsof t.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
DllGetClassObject). 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*********@hotmail.comha scritto nel messaggio
news:OB**************@TK2MSFTNGP05.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
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...
4
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...
1
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...
3
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() ...
1
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...
6
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...
5
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...
2
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 =...
1
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...
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: 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
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
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,...
0
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...
0
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...
0
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,...

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.