Solved

MFC ---VC++

Posted on 2001-09-16
9
673 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
  • 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 30

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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 30

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

759 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now