Question DLL & C++

Question DLL & C++

Post by Eddy » Sat, 15 Jan 2000 04:00:00



Hi,

I am a novice in Windows programming.

My program is all written in C++.  I would like to extend it with plugins.
Ideally those plugins would implement some abstract class.  Thus, each plugins
would be a DLL written in C++.

I understand how I load a DLL at runtime if it is written in C.  However, I am
lost if the DLL is written in C++.  

How exactly do I armed with the name of DLL known only at runtime, load it and
use the classes contain within.

Any example, URL, books people can refer me to would be very nice.

Thanks.
Eddy

 
 
 

Question DLL & C++

Post by Tomas Restrep » Sat, 15 Jan 2000 04:00:00


Eddy,
 I am a novice in Windows programming.

Quote:

> My program is all written in C++.  I would like to extend it with plugins.
> Ideally those plugins would implement some abstract class.  Thus, each
plugins
> would be a DLL written in C++.

> I understand how I load a DLL at runtime if it is written in C.  However,
I am
> lost if the DLL is written in C++.

> How exactly do I armed with the name of DLL known only at runtime, load it
and
> use the classes contain within.

One way, which I favor, is to have the DLLs export a function, which creates
an instance of the Class for the exe. This is a simple pattern called a
"Class factory". In fact, this is very much what com does with Inproc dlls,
although COMs version is more complicated (and somewhat more flexible).
Finally, you might want to consider using COM for the plugins, if that suits
your app.

--
Tomas Restrepo
http://members.xoom.com/trestrep/

 
 
 

Question DLL & C++

Post by gd.. » Wed, 09 Feb 2000 04:00:00


Simple,
once you have a DLL you can load it using:
LoadLibrary("LibName");
Then you have a handle to it, which you can use.
You can get a function pointer within the DLL if you
use: GetProcAddress.
Once you're through, don't forget to FreeLibrary().

In the DLL itself, better use the VC wizard, you have
the DllMain, which is called whenever a process/thread attaches
the dll. Also you implement the entry points (functions) you
want to export and declare them with _cdecl(dllexport) in the
DLL and dllimport in the program itself.

Better see more documentation in the platform SDK.

Dror



Quote:> Hi,

> I am a novice in Windows programming.

> My program is all written in C++.  I would like to extend it with
plugins.
> Ideally those plugins would implement some abstract class.  Thus,
each plugins
> would be a DLL written in C++.

> I understand how I load a DLL at runtime if it is written in C.
However, I am
> lost if the DLL is written in C++.

> How exactly do I armed with the name of DLL known only at runtime,
load it and
> use the classes contain within.

> Any example, URL, books people can refer me to would be very nice.

> Thanks.
> Eddy

Sent via Deja.com http://www.deja.com/
Before you buy.