Solved

MFC ---VC++

Posted on 2001-09-16
9
689 Views
Last Modified: 2013-11-20
We are able to make classes using __declspec(dllexport)
& __declspec(dllimport )also  then
i can write this   either of __declspec(dllexport) or __declspec(dllimport )in  header file which is included at the client and server side of dll
i don't have to have to specifically write __declspec(dllexport) at server and __declspec(dllimport) on client in the header file. Either of them works

what is the meaning of AFX_EXT_CLASS in making classes as DLL's?


0
Comment
Question by:prashant_gh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
9 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 6486751
Less typing for you?  You may wish to trawl through MFC code and look at the definition of this macro.

The first method also works for C functions.
0
 
LVL 31

Accepted Solution

by:
Zoppo earned 50 total points
ID: 6486822
Using __declspec(dllimport) or (dllexport) directly may give the problem that you can't directly
re-use header of i.e. a class of DLL in the application which want to use that class loaded from
a DLL, coz there's a __declspec(dllexport) in the definition of the class.

Now, the macro AFX_EXT_CLASS is defined as __declspec(dllexport) if _AFXEXT is defined and
otherwise it's defined as __declspec(dllimport) ... so, whenever you want to import a class or a
function which is exported from a DLL you can re-use the header without modification in an
application with _AFXEXT not defined...

BTW: I don't see any reason why AFX_EXT_CLASS shouldn't work for C functions too...

hope that helps,

ZOPPO
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9532358
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by: Zoppo

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Roshan Davis
EE Cleanup Volunteer
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9538291
The question implies that the questioner is not a complete novice.

AFX_EXT_CLASS is defined such that the dllexport/dllimport is applied conditionally (if one does do as I suggested and look at it's definition).
One uses the MFC because it is a large collection of code that saves you re-inventing the wheel.  Less typing as I pointed out.

The final part of the question Zoppo answered with the same answer as I had already posted - Yes.


So is it fair that Zoppo is awarded the answer.  From my viewpoint NO.  I had answered with brevity but accuracy.

Bear in mind numbers of questions are answered with such as
look at www.programcodecollection.gadget.htm.


Zoppo did provide more explanation so I will accept a split answer with him assisting.
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 9538398
Well ... I don't absolutely agree ... your comment just told: 'Look yourself at the macro's code to see what it does'.

If I would recieve such a comment on a question like 'What is the meaning of ...?' I wouldn't accept this as
an answer or grade it better than 'C'

Allthough I don't want to offend anyone  here ... I don't mind that some points ...  I let roshmon decide.

regards

ZOPPO

0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9538437
>>  I had answered with brevity but accuracy.
I can't agree with that.
From Zoppo's comment itself the questioner can get the idea (with out any code reference or in MSDN).

Rosh :)
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9538719
Zoppo - I don't have any quarrel with you, please don't think I do.
The site is set up to promote competetiveness with the answer grading and points system, I am just playing the game.

Roshmon.
the questioner asked 'what is the meaning of AFX_EXT_CLASS in making classes as DLL's'  That I took as the main question he was interested in.
I answered with  Less typing for you?
An alternative could be 'to stop you re-inventing the wheel?'
To clarify I suggested he look at the definition of AFX_EXT_CLASS which is as follows.


and this just took me a few seconds to find

// for classes
#ifndef AFX_CLASS_EXPORT
      #define AFX_CLASS_EXPORT __declspec(dllexport)
#endif
#ifndef AFX_CLASS_IMPORT
      #define AFX_CLASS_IMPORT __declspec(dllimport)
#endif

and

      #ifdef _AFXEXT
            #define AFX_EXT_CLASS       AFX_CLASS_EXPORT
            #define AFX_EXT_API         AFX_API_EXPORT
            #define AFX_EXT_DATA        AFX_DATA_EXPORT
            #define AFX_EXT_DATADEF
      #else
            #define AFX_EXT_CLASS       AFX_CLASS_IMPORT
            #define AFX_EXT_API         AFX_API_IMPORT
            #define AFX_EXT_DATA        AFX_DATA_IMPORT
            #define AFX_EXT_DATADEF
      #endif

For anyone that is not a novice (and I do not think a novice would be programming dll's) I would think it is very clear what it does and how it does it.


Thats my reasoning.  I leave it up to you.
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9538772
If the Questioner know how to look at the definition, he might not ask this question. I prefer a full text comment as answer if this was my question. I'm leaving this upto the Moderator

Rosh :)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Suggested Courses

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question