message map problem in dll
Ajay K Sanghi -- sanghi@giasdl01.vsnl.net.in Friday, January 31, 1997 Environment : VC++ 4.0, Windows 95. Hello, My requirement is to implement message map for a window class in a dll whose base window class is implemented in another mfc extension dll. I have class CBaseWnd derrived from CWnd. So the message map inplementation looks something like BEGIN_MESSAGE_MAP( CBaseWnd, CWnd ) ON_WM_LBUTTONDOWN() END_MESSAGE_MAP() This class CBaseWnd is there in a MFC Extension DLL. I have got another class CDerrivedWnd derrived from CBaseWnd and this derrived class is in another mfc extension dll. So my message map implementaion looks like BEGIN_MESSAGE_MAP( CDerrivedWnd, CBaseWnd ) ON_WM_SIZE() END_MESSAGE_MAP() While linking, it gives a linking error : error LNK2001: unresolved external symbol "protected: static struct AFX_MSGMAP const CBaseWnd::messageMap"(?messageMap@CBaseWnd@@1UAFX_MSGMAP@@B) If I put the implementation of the derrived class in a application project, then it does not give this linking error. or If I make the message map implemetation like BAGIN_MESSAGE_MAP( CDerrivedWnd, CWnd ) then it does not give any linking error but now all my message processing in the CBaseWnd class is lost. What do I need to do ? Thank you, ashok email: sanghi@giasdl01.vsnl.net.in
David A. Pickett -- dabbler@concentric.net Sunday, February 02, 1997 [Mini-digest: 3 responses] Make sure you include an import library for the DLL containing your CBaseWnd in the project with the CDerivedWnd. ---------- From: Ajay K Sanghi[SMTP:sanghi@giasdl01.vsnl.net.in] Sent: Friday, January 31, 1997 4:29 AM To: mfc-l@netcom.com Subject: message map problem in dll Environment : VC++ 4.0, Windows 95. Hello, My requirement is to implement message map for a window class in a dll whose base window class is implemented in another mfc extension dll. I have class CBaseWnd derrived from CWnd. So the message map inplementation looks something like BEGIN_MESSAGE_MAP( CBaseWnd, CWnd ) ON_WM_LBUTTONDOWN() END_MESSAGE_MAP() This class CBaseWnd is there in a MFC Extension DLL. I have got another class CDerrivedWnd derrived from CBaseWnd and this derrived class is in another mfc extension dll. So my message map implementaion looks like BEGIN_MESSAGE_MAP( CDerrivedWnd, CBaseWnd ) ON_WM_SIZE() END_MESSAGE_MAP() While linking, it gives a linking error : error LNK2001: unresolved external symbol "protected: static struct AFX_MSGMAP const CBaseWnd::messageMap"(?messageMap@CBaseWnd@@1UAFX_MSGMAP@@B) If I put the implementation of the derrived class in a application project, then it does not give this linking error. or If I make the message map implemetation like BAGIN_MESSAGE_MAP( CDerrivedWnd, CWnd ) then it does not give any linking error but now all my message processing in the CBaseWnd class is lost. What do I need to do ? Thank you, ashok email: sanghi@giasdl01.vsnl.net.in -----From: "Peter Hodgman"To solve your problem you need to export the class CBaseWnd from the DLL it is defined in and then use the DLL import library for this DLL when linking the second DLL. Your can export your classes with the declspec specifier as follows: #define EXPORTCLASS __declspec(dllimport) and #define EXPORTCLASS __declspec(dllexport) class EXPORTCLASS CBaseWnd { : : : }; when building the DLL that exports the class CBaseWnd the definition of EXPORTCLASS should be: #define EXPORTCLASS __declspec(dllexport) when building the DLL that imports/derives from this class (class CDerrivedWnd) the EXPORTCLASS should be: #define EXPORTCLASS __declspec(dllimport) Additionally, you must place the export library for the CBaseWnd DLL in your library list for the linking of the DLL's that use this class... Hope this helps.. Pete Hodgman (pgh@autodesk.com) ______________________________ Reply Separator _________________________________ Subject: message map problem in dll Author: mfc-l@netcom.com at SMTPCC3 Date: 2/1/97 9:27 PM Environment : VC++ 4.0, Windows 95. Hello, My requirement is to implement message map for a window class in a dll whose base window class is implemented in another mfc extension dll. I have class CBaseWnd derrived from CWnd. So the message map inplementation looks something like BEGIN_MESSAGE_MAP( CBaseWnd, CWnd ) ON_WM_LBUTTONDOWN() END_MESSAGE_MAP() This class CBaseWnd is there in a MFC Extension DLL. I have got another class CDerrivedWnd derrived from CBaseWnd and this derrived class is in another mfc extension dll. So my message map implementaion looks like BEGIN_MESSAGE_MAP( CDerrivedWnd, CBaseWnd ) ON_WM_SIZE() END_MESSAGE_MAP() While linking, it gives a linking error : error LNK2001: unresolved external symbol "protected: static struct AFX_MSGMAP const CBaseWnd::messageMap"(?messageMap@CBaseWnd@@1UAFX_MSGMAP@@B) If I put the implementation of the derrived class in a application project, then it does not give this linking error. or If I make the message map implemetation like BAGIN_MESSAGE_MAP( CDerrivedWnd, CWnd ) then it does not give any linking error but now all my message processing in the CBaseWnd class is lost. What do I need to do ? Thank you, ashok email: sanghi@giasdl01.vsnl.net.in -----From: "P. Senthil" Ajay K Sanghi wrote: > While linking, it gives a linking error : > > error LNK2001: unresolved external symbol "protected: static struct > AFX_MSGMAP > const CBaseWnd::messageMap"(?messageMap@CBaseWnd@@1UAFX_MSGMAP@@B) > Since you have the name mangled CBaseWnd::messageMap, all you have to do is export it. (EXPORTS section in the DEF file of the extension DLL which implements it). P.Senthil http://www.geocities.com/SiliconValley/Heights/6504/
Bing Hou -- hou@tfn.com Monday, February 03, 1997 Surround your derived class declaration with this compiler switch: #undef AFX_DATA #define AFX_DATA _declspec(dllimport) class CDerivedWnd : public CBaseWnd { ... }; #undef AFX_DATA #define AFX_DATA MFC uses AFX_DATA in its message map macros. By defining AFX_DATA to be _declspec(dllimport), you ensure that the static data member CBaseWnd::messageMap is imported correctly. Provided that the extension DLL which contains the CBaseWnd uses AFX_EXT_CLASS correctly to export CBaseWnd class or its data member. Bing Hou hou@tfn.com ------------------------------------------------------------------------ Recall it as often as yo wish, a happy memory never wears out. ______________________________ Reply Separator _________________________________ Subject: message map problem in dll Author: Ajay K Sanghiat Internet Date: 1/31/97 10:29 AM Environment : VC++ 4.0, Windows 95. Hello, My requirement is to implement message map for a window class in a dll whose base window class is implemented in another mfc extension dll. I have class CBaseWnd derrived from CWnd. So the message map inplementation looks something like BEGIN_MESSAGE_MAP( CBaseWnd, CWnd ) ON_WM_LBUTTONDOWN() END_MESSAGE_MAP() This class CBaseWnd is there in a MFC Extension DLL. I have got another class CDerrivedWnd derrived from CBaseWnd and this derrived class is in another mfc extension dll. So my message map implementaion looks like BEGIN_MESSAGE_MAP( CDerrivedWnd, CBaseWnd ) ON_WM_SIZE() END_MESSAGE_MAP() While linking, it gives a linking error : error LNK2001: unresolved external symbol "protected: static struct AFX_MSGMAP const CBaseWnd::messageMap"(?messageMap@CBaseWnd@@1UAFX_MSGMAP@@B) If I put the implementation of the derrived class in a application project, then it does not give this linking error. or If I make the message map implemetation like BAGIN_MESSAGE_MAP( CDerrivedWnd, CWnd ) then it does not give any linking error but now all my message processing in the CBaseWnd class is lost. What do I need to do ? Thank you, ashok email: sanghi@giasdl01.vsnl.net.in
TBielo@aol.com Tuesday, February 04, 1997 [Mini-digest: 2 responses] >> My requirement is to implement message map for a window class in a dll >> whose base window class is implemented in another mfc extension dll. >> >> I have class CBaseWnd derrived from CWnd. So the message map >> inplementation >> looks something like >> BEGIN_MESSAGE_MAP( CBaseWnd, CWnd ) >> ON_WM_LBUTTONDOWN() >> END_MESSAGE_MAP() >> >> This class CBaseWnd is there in a MFC Extension DLL. >> >> I have got another class CDerrivedWnd derrived from CBaseWnd and this >> derrived class is in another mfc extension dll. >> So my message map implementaion looks like I assume you are using the AFX_EXT_CLASS macro to export/import classes to/from your DLL? Problem is that if you import/export more than one level (e.g. have a DLL use a class in another DLL than uses a class in another DLL) AFX_EXT_CLASS macro gets confused. I implemented the following code at the beginning of my DLL external declarations. Use the /D"BUILD_ExampleDLL" compiler switch when building the DLL. This will set the class decl to export when building the DLL and will set the class decl to import when including the DLL decl in client source files. See technical note #33 for more information. #ifdef IMPORT_EXPORT_FLAG #undef IMPORT_EXPORT_FLAG #endif #ifdef BUILD_ExampleDLL #define IMPORT_EXPORT_FLAG __declspec(dllexport) #else #define IMPORT_EXPORT_FLAG __declspec(dllimport) #endif class IMPORT_EXPORT_FLAG Foo { }; #undef IMPORT_EXPORT_FLAG Tony -----From: Ajay K SanghiHi Netters: Thank you very much for helping me solve my problem. The problem is solved by explicitly importing the CBaseWnd class. Due to some early screw-up with our internet account, All mfc-l mails were getting forwarded to us through our old internet account through which we were subscribed to mfc-l. Suddenly, the ISP has stopped forwarding those mails and hence I did not receive any reply that were posted to net. I have requested for subscribtion again and hopefully Mr. Elliot would oblige. Special thanks to Mr. Bing, for sending me direct mail, which helped me solve the problem. Thank you all, Regards, -Ashok On Tue, 4 Feb 1997, Bing Hou wrote: > > I apologize, I didn't realize that your derived class is in another > extension DLL. > > As another person responded, you need to explicitly import the > CBaseWnd's messageMap data member in your .DEF file's IMPORTS clause, > then it should link fine. > > -Bing > > > ______________________________ Reply Separator _________________________________ > Subject: message map problem in dll > Author: Ajay K Sanghi at Internet > Date: 2/4/97 11:21 AM > > > Hi, > Thanks for your earlier response. > > I tried with the solution given by you, but now it gives compilation > errors. > > After making changes, derrive class declaration looks like > > #undef AFX_DATA > #define AFX_DATA _declspec( dllimport ) > > class AFX_EXT_CLASS CDerrivedWnd : public CBaseWnd > { > protected: > CStdTreeView(); // protected constructor used by > dynamic creation > DECLARE_DYNCREATE(CStdTreeView) > ------ > DECLARE_MESSAGE_MAP() > }; > > #undef AFX_DATA > #define AFX_DATA > > Compilation errors are : > error C2487: 'classCStdTreeView' : member of dll interface class may not > be declared with dll interface > > This error is repeated for DECLARE_DYNCREATE(CStdTreeView) and > DECLARE_MESSAGE_MAP() > > Note : I have not exported any members of the derrived class separately. > > Thanks, > > Ashok > Email : sanghi@giasdl01.vsnl.net.in > > > > > > > On Mon, 3 Feb 1997, Bing Hou wrote: > > > > > Surround your derived class declaration with this compiler switch: > > > > #undef AFX_DATA > > #define AFX_DATA _declspec(dllimport) > > > > class CDerivedWnd : public CBaseWnd > > { > > ... > > }; > > > > #undef AFX_DATA > > #define AFX_DATA > > > > MFC uses AFX_DATA in its message map macros. > > > > By defining AFX_DATA to be _declspec(dllimport), you ensure that the static > data > > member CBaseWnd::messageMap is imported correctly. Provided that the extension > > > DLL which contains the CBaseWnd uses AFX_EXT_CLASS correctly to export > CBaseWnd > > class or its data member. > > > > > > Bing Hou > > hou@tfn.com > > ------------------------------------------------------------------------ > > Recall it as often as yo wish, a happy memory never wears out. > > > > > > > > > > ______________________________ Reply Separator > _________________________________ > > Subject: message map problem in dll > > Author: Ajay K Sanghi at Internet > > Date: 1/31/97 10:29 AM > > > > > > Environment : VC++ 4.0, Windows 95. > > > > Hello, > > > > My requirement is to implement message map for a window class in a dll > > whose base window class is implemented in another mfc extension dll. > > > > I have class CBaseWnd derrived from CWnd. So the message map inplementation > > looks something like > > BEGIN_MESSAGE_MAP( CBaseWnd, CWnd ) > > ON_WM_LBUTTONDOWN() > > END_MESSAGE_MAP() > > > > This class CBaseWnd is there in a MFC Extension DLL. > > > > I have got another class CDerrivedWnd derrived from CBaseWnd and this > > derrived class is in another mfc extension dll. > > So my message map implementaion looks like > > > > BEGIN_MESSAGE_MAP( CDerrivedWnd, CBaseWnd ) > > ON_WM_SIZE() > > END_MESSAGE_MAP() > > > > While linking, it gives a linking error : > > > > error LNK2001: unresolved external symbol "protected: static struct > > AFX_MSGMAP > > const CBaseWnd::messageMap"(?messageMap@CBaseWnd@@1UAFX_MSGMAP@@B) > > > > > > If I put the implementation of the derrived class in a application > > project, then > > it does not give this linking error. > > > > or > > If I make the message map implemetation like > > BAGIN_MESSAGE_MAP( CDerrivedWnd, CWnd ) > > then it does not give any linking error but now all my message processing > > in the > > CBaseWnd class is lost. > > > > > > What do I need to do ? > > > > Thank you, > > > > > > ashok > > email: sanghi@giasdl01.vsnl.net.in > > >
Lin Sebastian Kayser -- Lin.Kayser@munich.netsurf.de Thursday, February 06, 1997 You should #define a specifier that is unique for each module, for = example use #ifdef MYMODULE_DECL #undef MYMODULE_DECL #endif #ifdef MYMODULE_EXPORT #define MYMODULE_DECL __declspec(dllexport)=20 #else=20 #define MYMODULE_DECL __declspec(dllimport)=20 #endif=20 class MYMODULE_DECL Foo { }; where MYMODULE is the name of your module; otherwise you will again run = into problems when importing a module within another module. Regards, Lin . . . . . . . . . . . . . . . . . . . . . . . . . . . . .=20 . Lin Sebastian Kayser, Kayser & Nass, Munich . . Lin.Kayser@Munich.Netsurf.de / Lin_Kayser@Compuserve.com . . http://ourworld.compuserve.com/homepages/Lin_Kayser . . Message composed at the 6-Feb-97 at 11:26 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . -----Original Message----- I assume you are using the AFX_EXT_CLASS macro to export/import classes = to/from your DLL? Problem is that if you import/export more than one = level (e.g. have a DLL use a class in another DLL than uses a class in = another DLL) AFX_EXT_CLASS macro gets confused. I implemented the following code at the beginning of my DLL external = declarations. Use the /D"BUILD_ExampleDLL" compiler switch when building the DLL. = This will set the class decl to export when building the DLL and will = set the class decl to import when including the DLL decl in client = source files. See technical note #33 for more information. #ifdef IMPORT_EXPORT_FLAG #undef IMPORT_EXPORT_FLAG #endif #ifdef BUILD_ExampleDLL #define IMPORT_EXPORT_FLAG __declspec(dllexport)=20 #else=20 #define IMPORT_EXPORT_FLAG __declspec(dllimport)=20 #endif=20 class IMPORT_EXPORT_FLAG Foo { }; #undef IMPORT_EXPORT_FLAG=20 Tony
Become an MFC-L member | Вернуться в корень Архива |