Click here to Skip to main content
16,011,527 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Printer Selection Pin
Tomasz Sowinski13-Sep-01 1:56
Tomasz Sowinski13-Sep-01 1:56 
GeneralRe: Printer Selection Pin
13-Sep-01 4:41
suss13-Sep-01 4:41 
GeneralRe: Printer Selection Pin
Tomasz Sowinski13-Sep-01 4:46
Tomasz Sowinski13-Sep-01 4:46 
GeneralGet ActiveX size !!! Pin
Hadi Rezaee12-Sep-01 23:36
Hadi Rezaee12-Sep-01 23:36 
GeneralHeader file to Library ... Pin
Hadi Rezaee12-Sep-01 23:34
Hadi Rezaee12-Sep-01 23:34 
GeneralRe: Header file to Library ... Pin
Steen Krogsgaard13-Sep-01 0:07
Steen Krogsgaard13-Sep-01 0:07 
GeneralRe: Header file to Library ... Pin
Hadi Rezaee13-Sep-01 0:31
Hadi Rezaee13-Sep-01 0:31 
GeneralRe: Header file to Library ... Pin
Steen Krogsgaard13-Sep-01 1:38
Steen Krogsgaard13-Sep-01 1:38 
Hi Hadi,

if you want to use the classes in your DLL outside the DLL you have to export them. And, in the program that uses the classes you have to import them. This is how you do that:
// export:
// header included in DLL files. Here's the declaration of your class
class __declspec(dllexport) CYourClass
{
public:
   int m_iSomeInt;
   void SomeMethod();
   ....
};

// cpp file included with DLL files. Here's the implementation of your class
void CYourClass::SomeMethod()
{
...
}

Now, put all this in a DLL project and compile it. It will produce a .dll file and a .lib file.

To use this class in another program you'd have to import it:
// put YourClass.DLL in the lib path in project settings
// include YourClass.h in your program

// YourClass.h:
class __declspec(dllimport) CYourClass
{
public:
   int m_iSomeInt;
   void SomeMethod();
   ....
};

// SomeOtherClass.h:
#include YourClass.h
class CSomeOtherClass : public CYourClass
{
.....
};

As you can see, the file YourClass.h contains the declaration of CYourClass in both the DLL project and in the application project. The only difference between the two YourClass.h files is the use of __declspec - to export the class you use __declspec(dllexport), to import it you use __declspec(dllimport). Since it's stupid to maintain two versions of the YourClass.h file MFC uses conditional compiles to solve it. The define AFX_EXT_CLASS is defined as __declspec(dllexport) in DLL projects (more precisely in MFC extension DLL projects where the symbol _AFXEXT is automatically defined) and as __declspec(dllimport) in MFC application projects (_AFXEXT is not defined).

So the bottom line is: Put the declaration of your extension class in a header, and put AFX_EXT_CLASS between the class keyword and the class name. Include this header in your extension dll project along with the cpp file containing the implementation of the class and compile it. Put the generated lib file in the lib path in the project settings of your application project, and include the header file (containing the declaration of the extension class) in the application project - but not the cpp file with the implemention. Then everything should work nicely!

Cheers
Steen.

"To claim that computer games influence children is rediculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
GeneralRe: Header file to Library ... Pin
Hadi Rezaee13-Sep-01 2:55
Hadi Rezaee13-Sep-01 2:55 
GeneralRe: Header file to Library ... Pin
Steen Krogsgaard13-Sep-01 3:04
Steen Krogsgaard13-Sep-01 3:04 
GeneralRe: Header file to Library ... Pin
Hadi Rezaee13-Sep-01 4:04
Hadi Rezaee13-Sep-01 4:04 
GeneralRe: Header file to Library ... Pin
Steen Krogsgaard13-Sep-01 4:12
Steen Krogsgaard13-Sep-01 4:12 
GeneralRe: Header file to Library ... Pin
Hadi Rezaee13-Sep-01 4:45
Hadi Rezaee13-Sep-01 4:45 
QuestionHow can I run my application before password in win98 Pin
12-Sep-01 22:29
suss12-Sep-01 22:29 
AnswerRe: How can I run my application before password in win98 Pin
Michael Dunn12-Sep-01 22:36
sitebuilderMichael Dunn12-Sep-01 22:36 
GeneralI hopethe pwd dialog display after my application end! Pin
12-Sep-01 23:12
suss12-Sep-01 23:12 
GeneralAutomatic Radio Buttons Pin
Derek Lakin12-Sep-01 22:20
Derek Lakin12-Sep-01 22:20 
GeneralRe: Automatic Radio Buttons Pin
Tomasz Sowinski13-Sep-01 1:51
Tomasz Sowinski13-Sep-01 1:51 
GeneralRe: Automatic Radio Buttons Pin
Derek Lakin13-Sep-01 2:02
Derek Lakin13-Sep-01 2:02 
GeneralRe: Automatic Radio Buttons Pin
Tomasz Sowinski13-Sep-01 2:17
Tomasz Sowinski13-Sep-01 2:17 
GeneralRe: Automatic Radio Buttons Pin
Derek Lakin13-Sep-01 2:21
Derek Lakin13-Sep-01 2:21 
Generalhelp with MSXML Pin
12-Sep-01 22:10
suss12-Sep-01 22:10 
GeneralRe: help with MSXML Pin
Michael Dunn12-Sep-01 22:30
sitebuilderMichael Dunn12-Sep-01 22:30 
GeneralRe: help with MSXML Pin
12-Sep-01 22:53
suss12-Sep-01 22:53 
GeneralRe: help with MSXML Pin
markkuk13-Sep-01 1:39
markkuk13-Sep-01 1:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.