|
Using MFC classes with C++ Builder can be difficult, since there are conflicts
between the definitions in the MFC header files and the VCL header files. However,
after some simple changes, you can combine the two.
C++ Builder 1 and 3
| Problem |
Fix |
| AFXV_W32.H (131) AND WINREG.H (39) conflict over
definition of HKEY |
I changed AFXV_W32.H by commenting out the lines below.
This causes HKEY to default to being a WORD as in WINREG .
struct HKEY__;
typedef struct HKEY__ *HKEY; |
| afxwin.h 798 & 793 Multiple declare of CDC::DrawState |
Apparently this is not polymorphically two distinct
routines due to the equivalence of some typedefs or #defines.
I commented out one of the routine definitions. I also had to comment out
afxwin1.inl 686 because "Body already defined" for the same reason. |
| afxwin.h 1247, 1250, 1253, 1283 , 1286 ambiguities
in "IUnknown" etc. |
Resolved by "::"; in other words, the typedef should
always use the local struct not the MFC definition. |
| afxwin1.inl 554 cannot convert long to void * |
Comment out
//_AFXWIN_INLINE int CDC::EnumObjects(int nObjectType,
// int (CALLBACK* lpfn)(LPVOID, LPARAM), LPARAM lpData)
// { ASSERT(m_hAttribDC != NULL); return ::EnumObjects(m_hAttribDC, nObjectType,
(GOBJENUMPROC)lpfn, (void *) lpData); }
at line 552-554 |
| afxdisp.h 597, 743 747 more ambiguity |
Resolved by :: (i.e. ::IClassFactory2, not IClassFactory2) |
Of course, a -Vf has to be added to each project makefile by hand (MFC compatibility),
as does a reference to the MFC link library (nafxcw.lib, in your Borland C++
5.02 /lib directory).
Also, if you use any message mapping, the MFC definition of BEGIN_MESSAGE_MAP...
etc. differs from the Borland definition and will cause mysterious compile failures.
Remove the lines from afxwin.h:
#ifdef _AFXDLL
#define BEGIN_MESSAGE_MAP(theClass, baseClass) \
const AFX_MSGMAP* PASCAL theClass::_GetBaseMessageMap()
\
{ return &baseClass::messageMap;
} \
const AFX_MSGMAP* theClass::GetMessageMap() const
\
{ return &theClass::messageMap;
} \
AFX_DATADEF const AFX_MSGMAP theClass::messageMap
= \
{ &theClass::_GetBaseMessageMap, &theClass::_messageEntries[0]
}; \
const AFX_MSGMAP_ENTRY theClass::_messageEntries[]
= \
{ \
#else
#define BEGIN_MESSAGE_MAP(theClass, baseClass) \
const AFX_MSGMAP* theClass::GetMessageMap() const
\
{ return &theClass::messageMap;
} \
AFX_DATADEF const AFX_MSGMAP theClass::messageMap
= \
{ &baseClass::messageMap, &theClass::_messageEntries[0]
}; \
const AFX_MSGMAP_ENTRY theClass::_messageEntries[]
= \
{ \
#endif
#define END_MESSAGE_MAP() \
{0, 0, 0, 0, AfxSig_end, (AFX_PMSG)0
} \
}; \
// Message map signature values and macros in separate header
#include <afxmsg_.h> |
C++ Builder 4
| Problem |
Fix |
| afxv_w32.h and winreg.h conflict over definition
of HKEY |
I changed AFXV_W32.H by commenting out the lines below.
This causes HKEY to default to being a WORD as in WINREG .
struct HKEY__;
typedef struct HKEY__ *HKEY; |
| afxwin.h 799 & 803 Multiple declare of CDC::DrawState |
Apparently this is not polymorphically two distinct
routines due to the equivalence of some typedefs or #defines.
I commented out one of the routine definitions. I also had to comment out
afxwin1.inl 691 because "Body already defined" for the same reason. |
| afxwin.h ambiguities in "IUnknown" etc. |
Resolved by "::"; in other words, the typedef should always use the local
struct not the MFC definition.
Change these typedefs:
struct IUnknown;
typedef ::IUnknown* LPUNKNOWN;
struct IDispatch;
typedef ::IDispatch* LPDISPATCH;
struct IConnectionPoint;
typedef ::IConnectionPoint* LPCONNECTIONPOINT;
struct IEnumOLEVERB;
typedef ::IEnumOLEVERB* LPENUMOLEVERB;
There is also one IUnknown reference to be changed:
IUnknown* GetDSCCursor();
|
| afxwin1.inl cannot convert long to void * |
Comment out
_AFXWIN_INLINE int CDC::EnumObjects(int nObjectType,
int (CALLBACK* lpfn)(LPVOID, LPARAM), LPARAM lpData)
{ ASSERT(m_hAttribDC != NULL); return ::EnumObjects(m_hAttribDC, nObjectType,
(GOBJENUMPROC)lpfn, (void *) lpData); }
at line 558 |
| afxdisp.h 634 more ambiguity |
Resolved by :: (i.e. ::IClassFactory2, not IClassFactory2)
|
| Problem with BEGIN_MESSAGE_MAP |
in afxwin.h change BEGIN_MESSAGE_MAP and END_MESSAGE_MAP
to CBEGIN_MESSAGE_MAP and CEND_MESSAGE_MAP to
eliminate conflicts between the definition of these macros in VCL and MFC |
| afxres 238 |
comment out #define ID_HELP 0xE146 // first attempt for F1 |
| afxmsg_h 129 |
comment out #define CN_COMMAND 0 |
| Missing close */ |
#define PFA_JUSTIFY 4 /* New paragraph-alignment option 2.0 (*)
*/ |
|
|