Hi, All.
I have an example driver. Its written in C++ and consists of many .cpp
and .h files.
I need the main source file(where we have DriverEntry) to be in C.
When I just change the extension to .c, I’m getting many errors in
header files included by main.c(cause they are in C++).
Can I somehow avoid that?
Maybe passing some directives to #include?
Thanks.
You need to wrap DriverEntry with “extern “C””, like this:
extern “C”
{
NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath);
}
You will also need to add any WDM or KMDF callbacks to this scope.
Gary G. Little
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@voliacable.com
Sent: Thursday, July 27, 2006 9:32 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] DDK & C++
Hi, All.
I have an example driver. Its written in C++ and consists of many .cpp
and .h files.
I need the main source file(where we have DriverEntry) to be in C.
When I just change the extension to .c, I’m getting many errors in
header files included by main.c(cause they are in C++).
Can I somehow avoid that?
Maybe passing some directives to #include?
Thanks.
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
> You need to wrap DriverEntry with “extern “C””
extern “C” NTSTATUS DriverEntry(… is good enough.
Additionally, be ready to:
- wrap some or all headers into
extern “C” {
#include <some_header.h>
}
(if your DDK is old enough; otherwise you get linker errors “can’t find
DdkFunc@#$!h*&^…” - linker looks for a C++ aka decorated name)
2) declare functions that are mentioned in alloc_text pragmas as extern
“C”.
----- Original Message -----
From:
To: “Windows System Software Devs Interest List”
Sent: Thursday, July 27, 2006 10:40 AM
Subject: RE: [ntdev] DDK & C++
> You need to wrap DriverEntry with “extern “C””, like this:
>
> extern “C”
> {
> NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject,
> IN PUNICODE_STRING RegistryPath);
> }
>
> You will also need to add any WDM or KMDF callbacks to this scope.
>
> Gary G. Little
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of
> xxxxx@voliacable.com
> Sent: Thursday, July 27, 2006 9:32 AM
> To: Windows System Software Devs Interest List
> Subject: [ntdev] DDK & C++
>
> Hi, All.
>
> I have an example driver. Its written in C++ and consists of many .cpp
> and .h files.
>
> I need the main source file(where we have DriverEntry) to be in C.
> When I just change the extension to .c, I’m getting many errors in
> header files included by main.c(cause they are in C++).
>
> Can I somehow avoid that?
> Maybe passing some directives to #include?
>
>
> Thanks.
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer</some_header.h>
Slowly putting on flame proof outerwear…
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@seagate.com
Sent: Thursday, July 27, 2006 10:41 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] DDK & C++
You need to wrap DriverEntry with “extern “C””, like this:
extern “C”
{
NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath);
}
You will also need to add any WDM or KMDF callbacks to this scope.
Gary G. Little
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@voliacable.com
Sent: Thursday, July 27, 2006 9:32 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] DDK & C++
Hi, All.
I have an example driver. Its written in C++ and consists of many .cpp
and .h files.
I need the main source file(where we have DriverEntry) to be in C.
When I just change the extension to .c, I’m getting many errors in
header files included by main.c(cause they are in C++).
Can I somehow avoid that?
Maybe passing some directives to #include?
Thanks.
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
#ifdef __cplusplus can help. Defined during C++ compile, not defined during
C compile.
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com
----- Original Message -----
From: “Shadow”
To: “Windows System Software Devs Interest List”
Sent: Thursday, July 27, 2006 6:31 PM
Subject: [ntdev] DDK & C++
> Hi, All.
>
> I have an example driver. Its written in C++ and consists of many .cpp
> and .h files.
>
> I need the main source file(where we have DriverEntry) to be in C.
> When I just change the extension to .c, I’m getting many errors in
> header files included by main.c(cause they are in C++).
>
> Can I somehow avoid that?
> Maybe passing some directives to #include?
>
>
> Thanks.
>
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
Oh … OUTTER wear … first time I read that, my elder eyes read UNDER
wear … 
Gary G. Little
-----Original Message-----
xxxxx@lists.osr.com] On Behalf Of Roddy, Mark
Sent: Thursday, July 27, 2006 10:23 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] DDK & C++
Slowly putting on flame proof outerwear…
> I have an example driver. Its written in C++ and consists of many .cpp
and .h files.
I need the main source file(where we have DriverEntry) to be in C.
When I just change the extension to .c, I’m getting many errors in
header files included by main.c(cause they are in C++).
Can I somehow avoid that?
Maybe passing some directives to #include?
Don’t want to sound annoying but why do you need your main source file to be
in C? You would save a lot of headache if you could have it in C++.
Option 1/See what functions is your main .c file calling and in the .cpp
files declare them as extern “C”. Write a minimal .h with the appropriate
declaration (without extern “C” since it’s a C++ keyword meaning, hello I’m
doing C++ and I’d like to link C…) and voilà!
Option 2/Try extern “C++” around your .h
Like this
extern “C++”
{
#include <omg.h>
#include <cplusplusuberalles.h>
…
}
I’m not sure it’s supported in this way (“Hello I’m doing C and I’d like to
link C++” but you could give it a try. The problem is that your .h might
have declarations which are not C compliant, such as classes. If this is the
case you need to go for option 1.
Hope this helps.
–
EA</cplusplusuberalles.h></omg.h>