We have VC6 driver project configured as described in Creating Driver project for Visual Studio 6.0 article. Our task is to build it with minimal efforts under Visual Studio 8 using DDK 2003. Also we want to keep compatibility with previous versions of Visual Studio and DDK. At least .MAK file generated from VC6 .DSP project shall work with nmake utility under all environments.
Note: Sometimes DDK 2003 comes under name DDK XP, but DDK 2003 has very specific inc and lib directory structure:
XP DDK DDK 2003
/inc
/lib
/i386
/inc
/atl21, /atl30, /crt, /ddk, /ifs,
/inc16, /mfc42, /w2k, /wnet, /wxp
/lib
/lib16
/w2k
/i386
/wnet
/amd64, /i386, /ia64
/wxp
/i386, /ia64
Problems
different directory layout (see above), and as result disability to find headers .H and libraries .LIB
new compiler (cl.exe) and linker (link.exe) options
cl : Command line warning D9035 : option 'GX' has been deprecated and will be removed
in a future release
cl : Command line warning D9036 : use 'EHsc' instead of 'GX'
string functions deprecation warning
c:/projects/src/driver/mycpp.cpp(22) :
warning C4996: 'strcpy' was declared deprecated
C:/Program Files/Microsoft Visual Studio 8/VC/INCLUDE/string.h(73) :
see declaration of 'strcpy'
Message: 'This function or variable may be unsafe. Consider using
strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE.
See online help for details.'
"unresolved external" errors
mycpp.obj : error LNK2001: unresolved external symbol ___security_cookie
mycpp.obj : error LNK2001: unresolved external symbol @__security_check_cookie@4
mycpp.obj : error LNK2001: unresolved external symbol __except_handler4
LINK : error LNK2001: unresolved external symbol __load_config_used
Solution N1 (by Alter)
Note: All these steps must be performed for each build configuration (Debug/Release).
Set still one environment variable - BASEDIR2K3 (I would recommend system one, not user-specific) like this:
BASEDIR2K3 = C:/Develop/DDK2003
Open VC6 project settings under C/C++ section
Add the following include seacrh paths to the end of list
$(BASEDIR2K3)/inc/ddk/wxp,$(BASEDIR2K3)/inc/ifs/wxp, $(BASEDIR2K3)/inc/wxp,
$(BASEDIR2K3)/inc/crt
for example my includes look so:
$(BASEDIRNT4)/inc,$(BASEDIR2K)/src/filesys/inc,$(BASEDIRXP)/inc/ddk,$(BASEDIRXP)/inc/ifs,
$(BASEDIRXP)/inc,$(BASEDIR2K3)/inc/ddk/wxp,$(BASEDIR2K3)/inc/ifs/wxp,
$(BASEDIR2K3)/inc/wxp,$(BASEDIR2K3)/inc/crt
Note: I used wxp subdirectory assuming that project could be built with XP DDK. Among this w2k and wnet options are available.
Replace /GX option for /EHsc, it is obviously what for :)
define the following constants:
_CRT_SECURE_NO_DEPRECATE
_CRT_NONSTDC_NO_DEPRECATE
_CRT_NON_CONFORMING_SWPRINTFS
This will solve "warning C4996: 'strcpy' was declared deprecated" problem. You can also define them in your common include file like this:
#define _CRT_SECURE_NO_DEPRECATE // For VS 2005
#define _CRT_NONSTDC_NO_DEPRECATE // For VS 2005
#define _CRT_NON_CONFORMING_SWPRINTFS // For VS 2005
Also, add /GS- option. It will solve problems with ___security_cookie and __except_handler4, though shall produce non-critical warning under VC6, since VC6 doesn't know this option.
Open Link section
Add the following library seacrh paths
$(BASEDIR2K3)/lib/wxp/i386
Also, add there /safeseh:no option. It will solve problems with __load_config_used, though shall produce non-critical warning under VC6 too.
Now export .MAK file and try to build project with it under Visual Studio 8. Note: by default Visual Studio 8 does not set neither system nor user INCLUDE and LIB environment variables. Since these variables may be required for successful build, it worth runing Visual Studio 2005 command prompt and executing nmake under this environment.
Solution N2 (by DeathSoft)
In order to get ___security_cookie, you have to add BufferOverflowK.lib to your project. You can get it from newer DDK. Set /entry:"GsDriverEntry@8" option, this information can also be found in MSDN. To have no problems with /safeseh:yes (it is the default in new Visual Studio) add the following file to project:
safeseh.c:
extern ULONG_PTR __security_cookie; /* /GS security cookie */
/*
* The following two names are automatically created by the linker for any
* image that has the safe exception table present.
* /
extern PVOID __safe_se_handler_table[]; /* base of safe handler entry table * /
extern UCHAR __safe_se_handler_count; /* absolute symbol whose address is
the count of table entries * /
typedef struct {
ULONG Size;
ULONG TimeDateStamp;
USHORT MajorVersion;
USHORT MinorVersion;
ULONG GlobalFlagsClear;
ULONG GlobalFlagsSet;
ULONG CriticalSectionDefaultTimeout;
ULONG DeCommitFreeBlockThreshold;
ULONG DeCommitTotalFreeThreshold;
ULONG LockPrefixTable; // VA
ULONG MaximumAllocationSize;
ULONG VirtualMemoryThreshold;
ULONG ProcessHeapFlags;
ULONG ProcessAffinityMask;
USHORT CSDVersion;
USHORT Reserved1;
ULONG EditList; // VA
ULONG_PTR *SecurityCookie;
PVOID *SEHandlerTable;
ULONG SEHandlerCount;
} IMAGE_LOAD_CONFIG_DIRECTORY32_2;
extern
const IMAGE_LOAD_CONFIG_DIRECTORY32_2 _load_config_used = {
sizeof(IMAGE_LOAD_CONFIG_DIRECTORY32_2),
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
&__security_cookie,
__safe_se_handler_table,
(ULONG)(ULONG_PTR) &__safe_se_handler_count
};
Solution N3
Take pre-configured empty driver project for VS 2005 and add there your sources. You can find it together with VC6 project for kernel mode driver. Look in archive in pch_cpp subfolder. Also you can create VS8 project yourself with help of this manual: VC8 project for kernel mode driver.
Practically, you will completley convert your project from VS6 to VS8.