Reputation: 121
I'm learning driver development for windows using a book. They gave the following example:
#include "ntddk.h"
void Unload(PDRIVER_OBJECT pDriverObject) {
DbgPrint("Driver unloading...\n");
return;
}
NTSTATUS DriverEntry(PDRIVER_OBJECT pDriverObject, PUNICODE_STRING RegPath) {
pDriverObject->DriverUnload=Unload;
DbgPrint("Driver has been loaded..");
return (STATUS_SUCCESS);
}
Whenever I try to compile this I get these errors and warnings:
error C2220: warning treated as error - no 'object' file generated
warning C4100: pDriverObject and RegPath: unreferenced formal parameter.
I've looked around stackoveflow for solutions but they don't seem to work in this case. I already tried disabling compiler warnings, still no luck.
can anyone shed some light?
Upvotes: 2
Views: 954
Reputation: 18358
Keeping the warnings at maximum level is the healthiest practice. In addition to the already suggested solutions, there is also a WDK macro that you can use inside the function body to indicate that the parameter isn't used - UNREFERENCED_PARAMETER(param)
.
Upvotes: 3
Reputation: 92261
One way to disable the warning is to remove the parameter's name. Then it is obvious (to the compiler) that you cannot use it. So you didn't just forget.
If you might use it later, or want to keep the name as a documentation, you can just comment it out:
void Unload(PDRIVER_OBJECT /* pDriverObject */) {
DbgPrint("Driver unloading...\n");
return;
}
Upvotes: 1
Reputation: 33273
The compiler warns that you don't use some of the function parameters. Your project also have the setting to treat warnings as errors.
There are a couple of ways to solve the problem.
Example of using the parameters:
void Unload(PDRIVER_OBJECT pDriverObject) {
DbgPrint("Driver of type %d unloading...\n", pDriverObject->Type);
return;
}
NTSTATUS DriverEntry(PDRIVER_OBJECT pDriverObject, PUNICODE_STRING RegPath) {
pDriverObject->DriverUnload=Unload;
DbgPrint("Driver has been loaded... (RegPath pointer=%p)\n", RegPath);
return (STATUS_SUCCESS);
}
Upvotes: 0