|
| |

Error String Display
The function GetLastError() returns a binary value that is
meaningful only to people who have arguments over undocumented functions and the
values returned in processor registers. For us (somewhat) more normal types, a
string is much more useful. That’s where FormatMessage comes in. It will convert
an error code into a language specific string.
CString csGetLastErrorString()
{
CString csReturn;
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
// Copy the error string into our return string.
csReturn = (TCHAR*)lpMsgBuf;
// The FormatMessage allocated this for us so we have to release it.
LocalFree( lpMsgBuf );
return csReturn;
}
Linker Problems
fcs42.lib(dllmodul.obj) :
error LNK2005: _DllMain@12 already defined in MSVCRT.lib(dllmain.obj)
mfcs42.lib(dllmodul.obj) : error LNK2005: __pRawDllMain already defined in
CorLock.obj
mfcs42.lib(dllmodul.obj) : warning LNK4006: _DllMain@12 already defined in
MSVCRT.lib(dllmain.obj); second definition ignored
mfcs42.lib(dllmodul.obj) : warning LNK4006: __pRawDllMain already defined in
CorLock.obj; second definition ignored
The basic problem here is a conflict between libraries. In
general, MFC libraries must be linked before CRT libraries.
- Open the Project Settings dialog box by clicking
Settings on the Build menu.
- Click the Link tab.
- Select Input in the Category combo box.
- In the Libraries to the Ignore edit box
and insert the conflicting library names. In this case, the conflict is
coming from MSVCRT.lib and mfcs42.lib so we’ll tell the linker to ignore
these particular libraries as part of its default link list.
- If we were to quit at this point and relink, we’d
still have a link time failure due to unresolved link errors. To get around
that, we now we want to tell the linker to include the libraries but we want
to make sure that they get included in a particular order. In the
Object/library Modules edit box, insert the library names. You must
ensure that these are listed in order and as the first two libraries in the
line (for example, mfcs42.lib MSVCRT.lib).

|