FIX: Using CString or Collection Class Links in CWinApp CodeLast reviewed: September 16, 1997Article ID: Q107436 |
1.00
WINDOWS
kbprg kbfixlist kbbuglist
The information in this article applies to:
SYMPTOMSUsing a CString object or collection object (CObList, CStringArray, and so forth) in an application forces the code for CWinApp to be linked into the application whether or not a CWinApp object is defined. The CWinApp code requires that SHELL.LIB and COMMDLG.LIB be specified in the link options. If you are not linking with SHELL.LIB and COMMDLG.LIB, and you use a CString or collection object without a CWinApp object, you will receive the following linker errors:
error L2029: 'GETFILETITLE' : unresolved external error L2029: 'REGSETVALUE' : unresolved external error L2029: 'REGQUERYVALUE' : unresolved external error L2029: 'DRAGFINISH' : unresolved external error L2029: 'DRAGQUERYFILE' :unresolved external CAUSEThe problem described above is caused by a compiler/linker bug. To understand the problem, consider the code:
extern int somevariable; __inline void func(){ somevariable=1;} void main(){ return;}If the code above is compiled with "/c /AM /Z7" or with "/c /f- /AL" and then linked, the unresolved external linker error (L2029) occurs. The linker is searching for the "somevariable" variable even though the func() function isn't referenced and tries to link it into the application. The Microsoft Foundation Class (MFC) libraries do something similar in the AFXWIN.INL file located in the \MSVC\MFC\INCLUDE directory. The code is as follows:
_AFXWIN_INLINE CWinApp* AFXAPI AfxGetApp() { return afxCurrentWinApp; } _AFXWIN_INLINE HINSTANCE AFXAPI AfxGetInstanceHandle() { ASSERT(afxCurrentInstanceHandle != NULL); return afxCurrentInstanceHandle; } _AFXWIN_INLINE HINSTANCE AFXAPI AfxGetResourceHandle() { ASSERT(afxCurrentResourceHandle != NULL); return afxCurrentResourceHandle; } _AFXWIN_INLINE void AFXAPI AfxSetResourceHandle(HINSTANCE hInstResource) { ASSERT(hInstResource != NULL); afxCurrentResourceHandle = hInstResource; } _AFXWIN_INLINE const char* AFXAPI AfxGetAppName() { ASSERT(afxCurrentAppName != NULL); return afxCurrentAppName; }Therefore, modules compiling with AFXWIN.INL can force the CWinApp code to be linked into an application.
RESOLUTIONTo work around this problem, do one of the following:
STATUSMicrosoft has confirmed this to be a problem with Microsoft Foundation Classes version 2.0. This problem has been corrected in version 2.5 of the Microsoft Foundation Classes, which is included with Visual C++ version 1.5.
MORE INFORMATIONTo reproduce the problem, compile and link the sample program below:
Sample Code
/* Compile options needed: /AM /GA* Link options needed: link without SHELL.LIB and COMMDLG.LIB * link with MAFXCW.LIB */ #include <afxwin.h> void main(void){ CString func("hello"); } Additional Reference Words: 1.00 2.00 |
KBCategory: kbprg kbfixlist kbbuglist kbfasttip
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |