徐艺波个人网站 | Make everything as simple as possible, but not simpler. Albert Einstein | ||
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 |
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'
c:projectssrcdrivermycpp.cpp(22) : warning C4996: 'strcpy' was declared deprecated C:Program FilesMicrosoft Visual Studio 8VCINCLUDEstring.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.'
mycpp.obj : error LNK2001: unresolved external symbol ___security_cookie mycpp.obj : error LNK2001: unresolved external symbol @[email protected] mycpp.obj : error LNK2001: unresolved external symbol __except_handler4 LINK : error LNK2001: unresolved external symbol __load_config_used
Note: All these steps must be performed for each build configuration (Debug/Release).
BASEDIR2K3 = C:DevelopDDK2003
$(BASEDIR2K3)incddkwxp,$(BASEDIR2K3)incifswxp, $(BASEDIR2K3)incwxp, $(BASEDIR2K3)inccrtfor example my includes look so:
$(BASEDIRNT4)inc,$(BASEDIR2K)srcfilesysinc,$(BASEDIRXP)incddk,$(BASEDIRXP)incifs, $(BASEDIRXP)inc,$(BASEDIR2K3)incddkwxp,$(BASEDIR2K3)incifswxp, $(BASEDIR2K3)incwxp,$(BASEDIR2K3)inccrtNote: I used wxp subdirectory assuming that project could be built with XP DDK. Among this w2k and wnet options are available.
_CRT_SECURE_NO_DEPRECATE _CRT_NONSTDC_NO_DEPRECATE _CRT_NON_CONFORMING_SWPRINTFSThis 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
$(BASEDIR2K3)libwxpi386
In order to get ___security_cookie, you have to add BufferOverflowK.lib to your project. You can get it from newer DDK. Set /entry:”[email protected]″ 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:
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 };
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.