Andy
Andy

Reputation: 2997

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.

Upvotes: 1

Views: 2783

Answers (3)

Serge Dundich
Serge Dundich

Reputation: 4439

std::string and std::wstring is a part of C++ standard library (included in header file - NOT that is part of C standard library as @dalle already posted).

And as @dalle already posted you compile C source code (samples are written in C) - the right format for C++ source file name is *.cpp

Full C++ support is available in user-mode. So since you have user-mode DLL using C++ is OK it you rename files to *.cpp (but looks ugly because you embed C++ chunks into pure-C code samples).

In kernel-mode code however the C++ support is very limited.

If you really need full C++ language support in kernel-mode you may use some tricks to enable it but it is very complicated thing to do by yourself that requires lots of knowledge and experience (though there are some incomplete solutions available to the public).

Upvotes: 0

Roger Lipscombe
Roger Lipscombe

Reputation: 91865

Almost all, if not all, of the DDK uses C, not C++.

Upvotes: 1

dalle
dalle

Reputation: 18507

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>.

Upvotes: 2

Related Questions