• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 727
  • Last Modified:

MFC ---VC++

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
prashant_gh
Asked:
prashant_gh
  • 3
  • 3
  • 2
1 Solution
 
AndyAinscowFreelance programmer / ConsultantCommented:
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
 
ZoppoCommented:
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
 
Roshan DavisCommented:
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
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
AndyAinscowFreelance programmer / ConsultantCommented:
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
 
ZoppoCommented:
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
 
Roshan DavisCommented:
>>  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
 
AndyAinscowFreelance programmer / ConsultantCommented:
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
 
Roshan DavisCommented:
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now