My First Driver - Problem Building

Hi all,

I have problem building my driver (it is a HID mini driver which is setup as filter driver),- I can’t figure this simple problem out - what else do I need to include?

I receive the following error message:

error LNK2019: unresolved external symbol _TraceEvents referenced in function _DriverEntry@8

This is coming from my driver entry routine where my trace statements are. I have included all the includes from hidusbfx2.h and have the trace.h file in my directory.

My sources file builds just the single file that has driver entry routine. I added stubs for the other routines I need.

Also, is it bad to have both old DDK installed and the new DDK installed on the same development machine (they are in their respective directories 3790.1830, 7600.16385.1).

Here’s my code:

NTSTATUS
DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
{
NTSTATUS status = STATUS_SUCCESS;
WDF_DRIVER_CONFIG config;

//
// Initialize WPP Tracing
//
WPP_INIT_TRACING( DriverObject, RegistryPath );

TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT,
“VJoy Driver Built %s %s\n”, DATE, TIME);

WDF_DRIVER_CONFIG_INIT(&config, VJoyEvtDeviceAdd);

//
// Create a framework driver object to represent our driver.
//
status = WdfDriverCreate(DriverObject,
RegistryPath,
WDF_NO_OBJECT_ATTRIBUTES,
&config, // Driver Config Info
WDF_NO_HANDLE);

if (!NT_SUCCESS(status)) {
TraceEvents(TRACE_LEVEL_ERROR, DBG_INIT,
“WdfDriverCreate failed with status 0x%x\n”, status);
WPP_CLEANUP(DriverObject);
}

return status;
}

What does your sources file look like?

d

debt from my phone

-----Original Message-----
From: xxxxx@hotmail.com
Sent: Sunday, June 12, 2011 6:47 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] My First Driver - Problem Building

Hi all,

I have problem building my driver (it is a HID mini driver which is setup as filter driver),- I can’t figure this simple problem out - what else do I need to include?

I receive the following error message:

error LNK2019: unresolved external symbol _TraceEvents referenced in function _DriverEntry@8

This is coming from my driver entry routine where my trace statements are. I have included all the includes from hidusbfx2.h and have the trace.h file in my directory.

My sources file builds just the single file that has driver entry routine. I added stubs for the other routines I need.

Also, is it bad to have both old DDK installed and the new DDK installed on the same development machine (they are in their respective directories 3790.1830, 7600.16385.1).

Here’s my code:

NTSTATUS
DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
{
NTSTATUS status = STATUS_SUCCESS;
WDF_DRIVER_CONFIG config;

//
// Initialize WPP Tracing
//
WPP_INIT_TRACING( DriverObject, RegistryPath );

TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT,
“VJoy Driver Built %s %s\n”, DATE, TIME);

WDF_DRIVER_CONFIG_INIT(&config, VJoyEvtDeviceAdd);

//
// Create a framework driver object to represent our driver.
//
status = WdfDriverCreate(DriverObject,
RegistryPath,
WDF_NO_OBJECT_ATTRIBUTES,
&config, // Driver Config Info
WDF_NO_HANDLE);

if (!NT_SUCCESS(status)) {
TraceEvents(TRACE_LEVEL_ERROR, DBG_INIT,
“WdfDriverCreate failed with status 0x%x\n”, status);
WPP_CLEANUP(DriverObject);
}

return status;
}


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Really basic, probably is missing something - here is the entire content:

TARGETNAME=vjoy
TARGETTYPE=DRIVER

KMDF_VERSION_MAJOR=1

TARGETLIBS=$(DDK_LIB_PATH)\hidclass.lib \
$(DDK_LIB_PATH)\ntstrsafe.lib

INCLUDES=…\inc

SOURCES= \
driver.c

you need a RUN_WPP directive in your sources file. from src\hid\hidusbfx2\sys\sources

#ENABLE_EVENT_TRACING=1

!IFDEF ENABLE_EVENT_TRACING

C_DEFINES = $(C_DEFINES) -DEVENT_TRACING

Generate WPP tracing code

$(SOURCES) – run software preprocessor on files listed in SOURCES

-km – use kernel mode

-func – define function we’ll use for tracing

This would map all TraceEvents calls to

DoTraceMessage.

RUN_WPP= $(SOURCES) \
-km \
-func:TraceEvents(LEVEL,FLAGS,MSG,…) \
-gen:{km-WdfDefault.tpl}*.tmh
!ENDIF

you want to either uncomment

#ENABLE_EVENT_TRACING=1

or just remove the !IFDEF and !ENDIF and keep the guts in between

d


From: xxxxx@lists.osr.com [xxxxx@lists.osr.com] on behalf of xxxxx@hotmail.com [xxxxx@hotmail.com]
Sent: Sunday, June 12, 2011 8:44 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] My First Driver - Problem Building

Really basic, probably is missing something - here is the entire content:

TARGETNAME=vjoy
TARGETTYPE=DRIVER

KMDF_VERSION_MAJOR=1

TARGETLIBS=$(DDK_LIB_PATH)\hidclass.lib \
$(DDK_LIB_PATH)\ntstrsafe.lib

INCLUDES=…\inc

SOURCES= \
driver.c


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

> Also, is it bad to have both old DDK installed and the new DDK installed on the same development machine (they

are in their respective directories 3790.1830, 7600.16385.1).

Nothing bad, but 3790 is long ago deprecated.

If you need w2k support, use 6001.18002.

If you can afford dropping w2k, use the latest Win7 7xxx WDK.

And, if you do not want to use ETW and WPP, have not studied the docs, and just want to build the simplest driver - then throw WPP_xxx and TraceEvents away completely.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

> Nothing bad, but 3790 is long ago deprecated.
Yea, I d/l 3790 because I needed to look at some old examples that are gone in the new versions,- I just did not want this to conflict with my current WINDDK.

On another note, I tried that but still same problem:
error LNK2019: unresolved external symbol _TraceEvents referenced in function _DriverEntry@8

Here’s my sources file now:

TARGETNAME=vjoy
TARGETTYPE=DRIVER

KMDF_VERSION_MAJOR=1

TARGETLIBS=$(DDK_LIB_PATH)\hidclass.lib \
$(DDK_LIB_PATH)\ntstrsafe.lib

INCLUDES=…\inc

SOURCES= \
driver.c

Comment the below line to disable tracing. All the debug traces

will be sent to the kernel-debugger.

#ENABLE_EVENT_TRACING=1

!IFDEF ENABLE_EVENT_TRACING

C_DEFINES = $(C_DEFINES) -DEVENT_TRACING

Generate WPP tracing code

$(SOURCES) – run software preprocessor on files listed in SOURCES

-km – use kernel mode

-func – define function we’ll use for tracing

This would map all TraceEvents calls to

DoTraceMessage.

RUN_WPP= $(SOURCES) \
-km \
-func:TraceEvents(LEVEL,FLAGS,MSG,…) \
-gen:{km-WdfDefault.tpl}*.tmh
!ENDIF

My driver.c looks like this:

#include <vjoy.h>

#if defined(EVENT_TRACING)
//
// The trace message header (.tmh) file must be included in a source file
// before any WPP macro calls and after defining a WPP_CONTROL_GUIDS
// macro (defined in toaster.h). During the compilation, WPP scans the source
// files for DoTraceMessage() calls and builds a .tmh file which stores a unique
// data GUID for each message, the text resource string for each message,
// and the data types of the variables passed in for each message. This file
// is automatically generated and used during post-processing.
//
#include “driver.tmh”
#else
ULONG DebugLevel = TRACE_LEVEL_INFORMATION;
ULONG DebugFlag = 0xff;
#endif

#ifdef ALLOC_PRAGMA
#pragma alloc_text( INIT, DriverEntry )
#pragma alloc_text( PAGE, VJoyEvtDeviceAdd )
#endif

NTSTATUS
DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
{
NTSTATUS status = STATUS_SUCCESS;
WDF_DRIVER_CONFIG config;

//
// Initialize WPP Tracing
//
WPP_INIT_TRACING( DriverObject, RegistryPath );

TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT,
“VJoy Driver Built %s %s\n”, DATE , TIME );

WDF_DRIVER_CONFIG_INIT(&config, VJoyEvtDeviceAdd);

//
// Create a framework driver object to represent our driver.
//
status = WdfDriverCreate(DriverObject,
RegistryPath,
WDF_NO_OBJECT_ATTRIBUTES,
&config, // Driver Config Info
WDF_NO_HANDLE);

if (!NT_SUCCESS(status)) {
TraceEvents(TRACE_LEVEL_ERROR, DBG_INIT,
“WdfDriverCreate failed with status 0x%x\n”, status);
WPP_CLEANUP(DriverObject);
}

return status;
}

…</vjoy.h>

What exactly is this “driver.tmh” file and where does it come from, can’t find it anywhere in local directory.
That maybe the problem.

It’s created by the WPP preprocessor.

I haven’t followed this thread, but have you considered just using
KdPrint()/DbgPrint()?

mm

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@hotmail.com
Sent: Monday, June 13, 2011 12:00 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] My First Driver - Problem Building

What exactly is this “driver.tmh” file and where does it come from, can’t
find it anywhere in local directory.
That maybe the problem.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

I get I could use these, is there any difference between these and Trace I am trying to get working?
Since I already stumbled across this problem and spent considerable time on it I would like to resolve it so I can sleep peacefully :slight_smile:

Uncomment this line and rebuild

#ENABLE_EVENT_TRACING=1

d

debt from my phone

-----Original Message-----
From: xxxxx@hotmail.com
Sent: Monday, June 13, 2011 8:53 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] My First Driver - Problem Building

Nothing bad, but 3790 is long ago deprecated.
Yea, I d/l 3790 because I needed to look at some old examples that are gone in the new versions,- I just did not want this to conflict with my current WINDDK.

On another note, I tried that but still same problem:
error LNK2019: unresolved external symbol _TraceEvents referenced in function _DriverEntry@8

Here’s my sources file now:

TARGETNAME=vjoy
TARGETTYPE=DRIVER

KMDF_VERSION_MAJOR=1

TARGETLIBS=$(DDK_LIB_PATH)\hidclass.lib \
$(DDK_LIB_PATH)\ntstrsafe.lib

INCLUDES=…\inc

SOURCES= \
driver.c

Comment the below line to disable tracing. All the debug traces

will be sent to the kernel-debugger.

#ENABLE_EVENT_TRACING=1

!IFDEF ENABLE_EVENT_TRACING

C_DEFINES = $(C_DEFINES) -DEVENT_TRACING

Generate WPP tracing code

$(SOURCES) – run software preprocessor on files listed in SOURCES

-km – use kernel mode

-func – define function we’ll use for tracing

This would map all TraceEvents calls to

DoTraceMessage.

RUN_WPP= $(SOURCES) \
-km \
-func:TraceEvents(LEVEL,FLAGS,MSG,…) \
-gen:{km-WdfDefault.tpl}*.tmh
!ENDIF

My driver.c looks like this:

#include <vjoy.h>

#if defined(EVENT_TRACING)
//
// The trace message header (.tmh) file must be included in a source file
// before any WPP macro calls and after defining a WPP_CONTROL_GUIDS
// macro (defined in toaster.h). During the compilation, WPP scans the source
// files for DoTraceMessage() calls and builds a .tmh file which stores a unique
// data GUID for each message, the text resource string for each message,
// and the data types of the variables passed in for each message. This file
// is automatically generated and used during post-processing.
//
#include “driver.tmh”
#else
ULONG DebugLevel = TRACE_LEVEL_INFORMATION;
ULONG DebugFlag = 0xff;
#endif

#ifdef ALLOC_PRAGMA
#pragma alloc_text( INIT, DriverEntry )
#pragma alloc_text( PAGE, VJoyEvtDeviceAdd )
#endif

NTSTATUS
DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
{
NTSTATUS status = STATUS_SUCCESS;
WDF_DRIVER_CONFIG config;

//
// Initialize WPP Tracing
//
WPP_INIT_TRACING( DriverObject, RegistryPath );

TraceEvents(TRACE_LEVEL_INFORMATION, DBG_INIT,
“VJoy Driver Built %s %s\n”, DATE , TIME );

WDF_DRIVER_CONFIG_INIT(&config, VJoyEvtDeviceAdd);

//
// Create a framework driver object to represent our driver.
//
status = WdfDriverCreate(DriverObject,
RegistryPath,
WDF_NO_OBJECT_ATTRIBUTES,
&config, // Driver Config Info
WDF_NO_HANDLE);

if (!NT_SUCCESS(status)) {
TraceEvents(TRACE_LEVEL_ERROR, DBG_INIT,
“WdfDriverCreate failed with status 0x%x\n”, status);
WPP_CLEANUP(DriverObject);
}

return status;
}




NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer</vjoy.h>

xxxxx@hotmail.com wrote:

What exactly is this “driver.tmh” file and where does it come from, can’t find it anywhere in local directory.

“driver.tmh” is created by the WPP pre-processor when you have
ENABLE_EVENT_TRACING defined. You don’t have it defined.

That maybe the problem.

Yup.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

> Uncomment this line and rebuild #ENABLE_EVENT_TRACING=1

It worked after I rebuilded it :slight_smile:

I did try it uncommenting the line before and still was getting linker problem but that’s because I did not clean my last build, - like you mentioned I had to rebuild it …

Thanks,

lk

Because of the way that BUILD works/doesn’t work, performing a clean build
every time (build -ceZ) is probably a good idea.

Good luck,

mm

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@hotmail.com
Sent: Monday, June 13, 2011 1:33 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] My First Driver - Problem Building

Uncomment this line and rebuild #ENABLE_EVENT_TRACING=1

It worked after I rebuilded it :slight_smile:

I did try it uncommenting the line before and still was getting linker
problem but that’s because I did not clean my last build, - like you
mentioned I had to rebuild it …

Thanks,

lk


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Thanks …

Can you guys tell me what is the difference between the WPP trace framework and just using KdPrint/DbgPrint?

Is there any advantages of using WPP trace?

xxxxx@hotmail.com wrote:

Can you guys tell me what is the difference between the WPP trace framework and just using KdPrint/DbgPrint?

Is there any advantages of using WPP trace?

Unfortunately, that’s a religious argument…

The advantage of WPP tracing is that you can send your driver out to
clients with the trace calls intact. Your clients will never see the
messages in their kernel debugger, but if they send you a crash dump,
you can use the trace facilities to dump the trace log, in all its
glory, because you have the secret decoder ring – the TMF file.

The disadvantage is that is somewhat less convenient for a driver
developer while active debugging is going on. Many of us have tried to
get excited about WPP, but have found the developer experience to be too
awkward, and have fallen back to KdPrint. You should try it both ways
– maybe you have the right mindset for WPP.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.