c++driverwdk

wdk ddk compiler problems with std::string and std::wstring


I've started playing around with the WDK / DDK (I'm assuming they're the same thing) samples and in particular the printer port monitor example. I've got this compiling using their build tool and I can attach to the spooler process and debug through... good stuff!

.. Problem comes when I simply want to write some debug out. I really thought this would be simple (haven't doing c++ in a while!) but it appears not!

The current problem I'm having is simply trying to create an instance of std::wchar, as in below:

std::wstring test("Blah");

Problem is, when I compile with the wdk build tool I get these errors:

1>c:\winddk\7600.16385.1\src\print\monitors\localmon\localmon.c(361) :
 error C2143: syntax error : missing ';' before ':'
1>c:\winddk\7600.16385.1\src\print\monitors\localmon\localmon.c(363) :
 error C2143: syntax error : missing ';' before 'type'

I'm guessing that this is because the compiler doesn't understand the std:: bit maybe? The line number points to the wstring declaration above.

I've added include <string.h> but that didn't help and my sources file is below:

!IFNDEF MSC_WARNING_LEVEL
MSC_WARNING_LEVEL=/W3
!ENDIF
MSC_WARNING_LEVEL=$(MSC_WARNING_LEVEL) /WX


C_DEFINES=-DUNICODE -D_UNICODE -D_SPL_CLUST

TARGETNAME=ddklocalmon
TARGETTYPE=DYNLINK
DLLENTRY=_DllMainCRTStartup
DLLDEF=localmon.def
DLLORDER=localmon.prf
TARGETLIBS=$(SDK_LIB_PATH)\kernel32.lib     \
           $(SDK_LIB_PATH)\advapi32.lib     \
           $(SDK_LIB_PATH)\user32.lib       \
           $(SDK_LIB_PATH)\ws2_32.lib       \
           $(SDK_LIB_PATH)\spoolss.lib

INCLUDES=$(INCLUDES);     \
         $(DDK_INC_PATH); \


USE_MSVCRT=1

SOURCES=localmon.rc  \
        localmon.c   \
        winspool.c   \
        util.c       \
        config.c     \
        xcv.c        \
        irda.c       \
        mem.c        \

PRECOMPILED_INCLUDE=precomp.h

Also, if I ever got wstring working I was going to use this with OutputDebugString() to process my debug to the visual studio output console, but I think I've read somewhere that this may not work as the port monitor runs in kernel mode?

If anyone could shed any light on this I'd really appreciate it! :)

Andy.


Solution

  • std::string and std::wstring are C++ classes (actually typedefs for C++ classes), and you are compiling .c files.

    Using the C++ runtime libraries in drivers feels a bit strange, I don't know if it works.

    If you where to compile as C++ the include is <string> and not <string.h>.