Develop a Virtual COM port driver for windows XP & above

>You shouldn’t need to download it. It is part of the WDK, just like

WUDFUpdate. In fact, it’s in the same directory as WUDFUpdate.

Yes got the winusbcoinstaller2.dll from Windows Kit folder & replaced it with the downloaded winusbcoinstaller2.dll file in the folder.

This seems more or less correct. Have you checked that your driver DLL
is present in System32\Drivers\UMDF?

No I don’t find my driver DLL in System32\Drivers\UMDF folder. when I install the sample VirtualSerial driver with the original .inf file with the following command.

devcon.exe install VirtualSerial.inf UMDF\VirtualSerial.inf

Then I can see the virtualSerial DLL in System32\Drivers\UMDF folder.
So instead of using

devcon.exe install VirtualSerial.inf “USB\VIDxxx&PIDxxxx”

command for installing the edited VirtualSerial driver I used the following command

devcon.exe update VirtualSerial.inf “UMDF\VIDxxx&PIDxxxx”

Still I cannot find the VirtualSerial Driver DLL in System32\Drivers\UMDF folder

Can you export the registry at
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Enum\USB\VID_1201&PID_4954
so we can see that it all got installed correctly?

Here You go…

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_1201&PID_4954]

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_1201&PID_4954\49-544C2D323030-ED]
“DeviceDesc”=“@oem42.inf,%virtualserialdevicename%;Practical Automation Driver”
“LocationInformation”=“Port_#0002.Hub_#0003
“Capabilities”=dword:00000014
“HardwareID”=hex(7):55,00,53,00,42,00,5c,00,56,00,49,00,44,00,5f,00,31,00,32,\
00,30,00,31,00,26,00,50,00,49,00,44,00,5f,00,34,00,39,00,35,00,34,00,26,00,\
52,00,45,00,56,00,5f,00,30,00,31,00,30,00,37,00,00,00,55,00,53,00,42,00,5c,\
00,56,00,49,00,44,00,5f,00,31,00,32,00,30,00,31,00,26,00,50,00,49,00,44,00,\
5f,00,34,00,39,00,35,00,34,00,00,00,00,00
“CompatibleIDs”=hex(7):55,00,53,00,42,00,5c,00,43,00,6c,00,61,00,73,00,73,00,\
5f,00,30,00,37,00,26,00,53,00,75,00,62,00,43,00,6c,00,61,00,73,00,73,00,5f,\
00,30,00,31,00,26,00,50,00,72,00,6f,00,74,00,5f,00,30,00,32,00,00,00,55,00,\
53,00,42,00,5c,00,43,00,6c,00,61,00,73,00,73,00,5f,00,30,00,37,00,26,00,53,\
00,75,00,62,00,43,00,6c,00,61,00,73,00,73,00,5f,00,30,00,31,00,00,00,55,00,\
53,00,42,00,5c,00,43,00,6c,00,61,00,73,00,73,00,5f,00,30,00,37,00,00,00,00,\
00
“ContainerID”=“{e88fe729-a210-5695-b65a-66ec4caec176}”
“ConfigFlags”=dword:00000000
“ClassGUID”=“{4d36e978-e325-11ce-bfc1-08002be10318}”
“Driver”=“{4d36e978-e325-11ce-bfc1-08002be10318}\0003”
“LowerFilters”=hex(7):57,00,69,00,6e,00,55,00,73,00,62,00,00,00,00,00
“Class”=“Ports”
“Mfg”=“@oem42.inf,%msftumdf%;Chetu1”
“Service”=“WUDFRd”
“FriendlyName”=“Practical Automation Driver (COM41)”

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_1201&PID_4954\49-544C2D323030-ED\Device Parameters]
“PortName”=“COM41”
“PollingPeriod”=dword:00000000
“WinUsbPowerPolicyOwnershipDisabled”=dword:00000001
“SymbolicName”=“\??\USB#VID_1201&PID_4954#49-544C2D323030-ED#{a5dcbf10-6530-11d2-901f-00c04fb951ed}”

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_1201&PID_4954\49-544C2D323030-ED\Device Parameters\WUDF]
“DriverList”=hex(7):56,00,69,00,72,00,74,00,75,00,61,00,6c,00,53,00,65,00,72,\
00,69,00,61,00,6c,00,00,00,00,00
“ImpersonationLevel”=dword:00000002
“KernelModeClientPolicy”=dword:00000001
“UmdfDispatcher”=“WinUSB”

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_1201&PID_4954\49-544C2D323030-ED\Device Parameters\WudfPowerPolicySettings]
“WdfDefaultIdleInWorkingState”=dword:00000001
“WdfDefaultWakeFromSleepState”=dword:00000001

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_1201&PID_4954\49-544C2D323030-ED\Device Parameters\WUDFDiagnosticInfo]
“LifetimeID”=“b5faf053-b310-4b54-9e4a-ba6954597164”
“HostPid”=hex(b):0c,0f,00,00,00,00,00,00
“RetrievalMode”=dword:00000000
“RwTransferMode”=dword:00000000
“IoctlTransferMode”=dword:00000000

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_1201&PID_4954\49-544C2D323030-ED\LogConf]

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_1201&PID_4954\49-544C2D323030-ED\Control]
“ActiveService”=“WUDFRd”

Have you done enough
debug prints to see that your driver is actually getting loaded?

I havn’t added any extra debug prints I’m relying on the default debug prints that was present in the sample VirtualSerial driver code

>You shouldn’t need to download it. It is part of the WDK, just like

WUDFUpdate. In fact, it’s in the same directory as WUDFUpdate.

Yes got the winusbcoinstaller2.dll from Windows Kit folder & replaced it with the downloaded winusbcoinstaller2.dll file in the folder.

This seems more or less correct. Have you checked that your driver DLL
is present in System32\Drivers\UMDF?

No I don’t find my driver DLL in System32\Drivers\UMDF folder. when I install the sample VirtualSerial driver with the original .inf file with the following command.

devcon.exe install VirtualSerial.inf UMDF\VirtualSerial.inf

Then I can see the virtualSerial DLL in System32\Drivers\UMDF folder.
So instead of using

devcon.exe install VirtualSerial.inf “USB\VIDxxx&PIDxxxx”

command for installing the edited VirtualSerial driver I used the following command

devcon.exe update VirtualSerial.inf “UMDF\VIDxxx&PIDxxxx”

Still I cannot find the VirtualSerial Driver DLL in System32\Drivers\UMDF folder

Can you export the registry at
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Enum\USB\VID_1201&PID_4954
so we can see that it all got installed correctly?

Here You go…

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_1201&PID_4954]

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_1201&PID_4954\49-544C2D323030-ED]
“DeviceDesc”=“@oem42.inf,%virtualserialdevicename%;Practical Automation Driver”
“LocationInformation”=“Port_#0002.Hub_#0003
“Capabilities”=dword:00000014
“HardwareID”=hex(7):55,00,53,00,42,00,5c,00,56,00,49,00,44,00,5f,00,31,00,32,\
00,30,00,31,00,26,00,50,00,49,00,44,00,5f,00,34,00,39,00,35,00,34,00,26,00,\
52,00,45,00,56,00,5f,00,30,00,31,00,30,00,37,00,00,00,55,00,53,00,42,00,5c,\
00,56,00,49,00,44,00,5f,00,31,00,32,00,30,00,31,00,26,00,50,00,49,00,44,00,\
5f,00,34,00,39,00,35,00,34,00,00,00,00,00
“CompatibleIDs”=hex(7):55,00,53,00,42,00,5c,00,43,00,6c,00,61,00,73,00,73,00,\
5f,00,30,00,37,00,26,00,53,00,75,00,62,00,43,00,6c,00,61,00,73,00,73,00,5f,\
00,30,00,31,00,26,00,50,00,72,00,6f,00,74,00,5f,00,30,00,32,00,00,00,55,00,\
53,00,42,00,5c,00,43,00,6c,00,61,00,73,00,73,00,5f,00,30,00,37,00,26,00,53,\
00,75,00,62,00,43,00,6c,00,61,00,73,00,73,00,5f,00,30,00,31,00,00,00,55,00,\
53,00,42,00,5c,00,43,00,6c,00,61,00,73,00,73,00,5f,00,30,00,37,00,00,00,00,\
00
“ContainerID”=“{e88fe729-a210-5695-b65a-66ec4caec176}”
“ConfigFlags”=dword:00000000
“ClassGUID”=“{4d36e978-e325-11ce-bfc1-08002be10318}”
“Driver”=“{4d36e978-e325-11ce-bfc1-08002be10318}\0003”
“LowerFilters”=hex(7):57,00,69,00,6e,00,55,00,73,00,62,00,00,00,00,00
“Class”=“Ports”
“Mfg”=“@oem42.inf,%msftumdf%;Chetu1”
“Service”=“WUDFRd”
“FriendlyName”=“Practical Automation Driver (COM41)”

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_1201&PID_4954\49-544C2D323030-ED\Device Parameters]
“PortName”=“COM41”
“PollingPeriod”=dword:00000000
“WinUsbPowerPolicyOwnershipDisabled”=dword:00000001
“SymbolicName”=“\??\USB#VID_1201&PID_4954#49-544C2D323030-ED#{a5dcbf10-6530-11d2-901f-00c04fb951ed}”

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_1201&PID_4954\49-544C2D323030-ED\Device Parameters\WUDF]
“DriverList”=hex(7):56,00,69,00,72,00,74,00,75,00,61,00,6c,00,53,00,65,00,72,\
00,69,00,61,00,6c,00,00,00,00,00
“ImpersonationLevel”=dword:00000002
“KernelModeClientPolicy”=dword:00000001
“UmdfDispatcher”=“WinUSB”

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_1201&PID_4954\49-544C2D323030-ED\Device Parameters\WudfPowerPolicySettings]
“WdfDefaultIdleInWorkingState”=dword:00000001
“WdfDefaultWakeFromSleepState”=dword:00000001

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_1201&PID_4954\49-544C2D323030-ED\Device Parameters\WUDFDiagnosticInfo]
“LifetimeID”=“b5faf053-b310-4b54-9e4a-ba6954597164”
“HostPid”=hex(b):0c,0f,00,00,00,00,00,00
“RetrievalMode”=dword:00000000
“RwTransferMode”=dword:00000000
“IoctlTransferMode”=dword:00000000

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_1201&PID_4954\49-544C2D323030-ED\LogConf]

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_1201&PID_4954\49-544C2D323030-ED\Control]
“ActiveService”=“WUDFRd”

Have you done enough
debug prints to see that your driver is actually getting loaded?

I havn’t added any extra debug prints I’m relying on the default debug prints that was present in the sample VirtualSerial driver code

>Have you checked that your driver DLL

is present in System32\Drivers\UMDF?

My virtualSerial.dll is present in System32\Drivers\UMDF?. I uninstalled the driver & re installed it the VirtualSerial.dll modified date changes to todays date. So yes wheni install my deiver with the following command it VirtualSerial.dll gets updated or cor reated in System32\Drivers\UMDF?

devcon.exe install VirtualSerial.inf “UMDF\VIDxxx&PIDxxxx”

Can you export the registry at
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Enum\USB\VID_1201&PID_4954
so we can see that it all got installed correctly?

Here You go…

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_1201&PID_4954]

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_1201&PID_4954\49-544C2D323030-ED]
“DeviceDesc”=“@oem42.inf,%virtualserialdevicename%;Practical Automation Driver”
“LocationInformation”=“Port_#0002.Hub_#0003
“Capabilities”=dword:00000014
“HardwareID”=hex(7):55,00,53,00,42,00,5c,00,56,00,49,00,44,00,5f,00,31,00,32,\
00,30,00,31,00,26,00,50,00,49,00,44,00,5f,00,34,00,39,00,35,00,34,00,26,00,\
52,00,45,00,56,00,5f,00,30,00,31,00,30,00,37,00,00,00,55,00,53,00,42,00,5c,\
00,56,00,49,00,44,00,5f,00,31,00,32,00,30,00,31,00,26,00,50,00,49,00,44,00,\
5f,00,34,00,39,00,35,00,34,00,00,00,00,00
“CompatibleIDs”=hex(7):55,00,53,00,42,00,5c,00,43,00,6c,00,61,00,73,00,73,00,\
5f,00,30,00,37,00,26,00,53,00,75,00,62,00,43,00,6c,00,61,00,73,00,73,00,5f,\
00,30,00,31,00,26,00,50,00,72,00,6f,00,74,00,5f,00,30,00,32,00,00,00,55,00,\
53,00,42,00,5c,00,43,00,6c,00,61,00,73,00,73,00,5f,00,30,00,37,00,26,00,53,\
00,75,00,62,00,43,00,6c,00,61,00,73,00,73,00,5f,00,30,00,31,00,00,00,55,00,\
53,00,42,00,5c,00,43,00,6c,00,61,00,73,00,73,00,5f,00,30,00,37,00,00,00,00,\
00
“ContainerID”=“{e88fe729-a210-5695-b65a-66ec4caec176}”
“ConfigFlags”=dword:00000000
“ClassGUID”=“{4d36e978-e325-11ce-bfc1-08002be10318}”
“Driver”=“{4d36e978-e325-11ce-bfc1-08002be10318}\0003”
“LowerFilters”=hex(7):57,00,69,00,6e,00,55,00,73,00,62,00,00,00,00,00
“Class”=“Ports”
“Mfg”=“@oem42.inf,%msftumdf%;Chetu1”
“Service”=“WUDFRd”
“FriendlyName”=“Practical Automation Driver (COM41)”

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_1201&PID_4954\49-544C2D323030-ED\Device Parameters]
“PortName”=“COM41”
“PollingPeriod”=dword:00000000
“WinUsbPowerPolicyOwnershipDisabled”=dword:00000001
“SymbolicName”=“\??\USB#VID_1201&PID_4954#49-544C2D323030-ED#{a5dcbf10-6530-11d2-901f-00c04fb951ed}”

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_1201&PID_4954\49-544C2D323030-ED\Device Parameters\WUDF]
“DriverList”=hex(7):56,00,69,00,72,00,74,00,75,00,61,00,6c,00,53,00,65,00,72,\
00,69,00,61,00,6c,00,00,00,00,00
“ImpersonationLevel”=dword:00000002
“KernelModeClientPolicy”=dword:00000001
“UmdfDispatcher”=“WinUSB”

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_1201&PID_4954\49-544C2D323030-ED\Device Parameters\WudfPowerPolicySettings]
“WdfDefaultIdleInWorkingState”=dword:00000001
“WdfDefaultWakeFromSleepState”=dword:00000001

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_1201&PID_4954\49-544C2D323030-ED\Device Parameters\WUDFDiagnosticInfo]
“LifetimeID”=“b5faf053-b310-4b54-9e4a-ba6954597164”
“HostPid”=hex(b):0c,0f,00,00,00,00,00,00
“RetrievalMode”=dword:00000000
“RwTransferMode”=dword:00000000
“IoctlTransferMode”=dword:00000000

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_1201&PID_4954\49-544C2D323030-ED\LogConf]

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_1201&PID_4954\49-544C2D323030-ED\Control]
“ActiveService”=“WUDFRd”

Have you done enough
debug prints to see that your driver is actually getting loaded?

I havn’t added any extra debug prints I’m relying on the default debug prints that was present in the sample VirtualSerial driver code

xxxxx@chetu.com wrote:

command for installing the edited VirtualSerial driver I used the following command

devcon.exe update VirtualSerial.inf “UMDF\VIDxxx&PIDxxxx”

Still I cannot find the VirtualSerial Driver DLL in System32\Drivers\UMDF folder

Hard to see how that can happen. The CopyFiles section is first in the
INF file. If ANYTHING had been done, that should be done. Have you
scanned through \windows\inf\setupapi.dev.log to see what happened
during the installation?

> Have you done enough
> debug prints to see that your driver is actually getting loaded?
I havn’t added any extra debug prints I’m relying on the default debug prints that was present in the sample VirtualSerial driver code

That doesn’t answer the question.


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

>Hard to see how that can happen. The CopyFiles section is first in the

INF file. If ANYTHING had been done, that should be done. Have you
scanned through \windows\inf\setupapi.dev.log to see what happened
during the installation?

I am able to see the Virtualserial.dll in System32\Drivers\UMDF

but still not able to debug the code facing the same issue as followed

"An unexpected and fatal error has occurred- details:

drivers\wdf\kmdf\tests\tools\wdfverifier\devicelist.cpp(296)
void_thiscall AllWdfDevices::AddUmdfDriversTo(struct
_SP_DEVINFO_DATA &,class WdfQa::Common::ObjectArray &)
Error 2<2> encountered
System Mesage: The system cannot find the file specified."

Hello There,

Now I am trying to debug the WudfHost.exe process(host process of my VirtualSerial UMDF driver) that gets created when once I attach my device to the PC. In msdn i have read that in order to debug a driver we need to attach the host process of that driver to the Windbg.

The process that i followed are as follows as shown in above videos:

  1. I successfully compiled the Virtual COM port driver, traversed to the Debug
    folder of Virtual COM port driver then copied the content of the Debug folder to
    a new folder in my C:\ drive.
  2. I copied the devcon.exe , wdfverifier.exe , windbg.exe & wudfext.dll, WUDFUPDATE_01009.dll and winusbcoinstaller2.dll to the new folder
  3. Then I opened the Windbg.exe in administrator mode.
  4. Clicked on the “File” tab in Windbg window then selected “Symbol File Path…”, Symbol Search Path window pops up, in that I browse to the new folder that contains the virtualserial.pbd( sysmbol file ) & selects OK.
  5. Then I click the “File” tab in Windbg then I select “Attach to a process…” from the Attach a Process window I sort the process “By Executable” & then select WudfHost.exe from the list of process & click OK.

Windbg:10.0.1.10586.567 X86 window pops up & displays the following

Microsoft (R) Windows Debugger Version 6.1.7601.17514 X86
Copyright (c) Microsoft Corporation. All rights reserved.

*** wait with pending attach
The call to LoadLibrary(ext) failed, Win32 error 0n2
“The system cannot find the file specified.”
Please check your debugger configuration and/or network access.
The call to LoadLibrary(exts) failed, Win32 error 0n2
“The system cannot find the file specified.”
Please check your debugger configuration and/or network access.
The call to LoadLibrary(uext) failed, Win32 error 0n2
“The system cannot find the file specified.”
Please check your debugger configuration and/or network access.
The call to LoadLibrary(ntsdexts) failed, Win32 error 0n2
“The system cannot find the file specified.”
Please check your debugger configuration and/or network access.
Symbol search path is: C:\Users\amitm2\Desktop\Prctical Package
Executable search path is:
ModLoad: 00220000 00253000 C:\Windows\System32\WUDFHost.exe
ModLoad: 77360000 7749c000 C:\Windows\SYSTEM32\ntdll.dll
ModLoad: 75bd0000 75ca4000 C:\Windows\system32\kernel32.dll
ModLoad: 75380000 753cb000 C:\Windows\system32\KERNELBASE.dll
ModLoad: 759e0000 75a80000 C:\Windows\system32\ADVAPI32.dll
ModLoad: 758b0000 7595c000 C:\Windows\system32\msvcrt.dll
ModLoad: 75970000 75989000 C:\Windows\SYSTEM32\sechost.dll
ModLoad: 77150000 771f1000 C:\Windows\system32\RPCRT4.dll
ModLoad: 75b00000 75bc9000 C:\Windows\system32\USER32.dll
ModLoad: 774b0000 774fe000 C:\Windows\system32\GDI32.dll
ModLoad: 75960000 7596a000 C:\Windows\system32\LPK.dll
ModLoad: 75d30000 75dcd000 C:\Windows\system32\USP10.dll
ModLoad: 77200000 7735c000 C:\Windows\system32\ole32.dll
ModLoad: 6aca0000 6accd000 C:\Windows\System32\WUDFPlatform.dll
ModLoad: 75dd0000 75f6d000 C:\Windows\system32\SETUPAPI.dll
ModLoad: 75400000 75427000 C:\Windows\system32\CFGMGR32.dll
ModLoad: 763a0000 7642f000 C:\Windows\system32\OLEAUT32.dll
ModLoad: 75630000 75642000 C:\Windows\system32\DEVOBJ.dll
ModLoad: 748f0000 748f9000 C:\Windows\System32\VERSION.dll
ModLoad: 75ae0000 75aff000 C:\Windows\system32\IMM32.DLL
ModLoad: 77080000 7714c000 C:\Windows\system32\MSCTF.dll
ModLoad: 68740000 6882b000 C:\Windows\System32\dbghelp.dll
ModLoad: 75270000 7527c000 C:\Windows\System32\CRYPTBASE.dll
ModLoad: 75430000 7545d000 C:\Windows\system32\WINTRUST.dll
ModLoad: 754f0000 7560d000 C:\Windows\system32\CRYPT32.dll
ModLoad: 75350000 7535c000 C:\Windows\system32\MSASN1.dll
ModLoad: 0fae0000 0fb7a000 C:\Windows\System32\WUDFx.dll
ModLoad: 759d0000 759d5000 C:\Windows\system32\PSAPI.DLL
ModLoad: 511a0000 511c2000 C:\Windows\System32\drivers\UMDF\Virtualserial.dll
ModLoad: 69a20000 69a23000 C:\Windows\system32\api-ms-win-core-synch-l1-2-0.DLL
(1ae8.1f08): Break instruction exception - code 80000003 (first chance)
eax=7ffd8000 ebx=00000000 ecx=00000000 edx=773ff1d3 esi=00000000 edi=00000000
eip=77394108 esp=00cbfb90 ebp=00cbfbbc iopl=0 nv up ei pl zr na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000246
*** ERROR: Symbol file could not be found. Defaulted to export symbols for C:\Windows\SYSTEM32\ntdll.dll -
ntdll!DbgBreakPoint:
77394108 cc int 3
*** ERROR: Symbol file could not be found. Defaulted to export symbols for C:\Windows\system32\kernel32.dll -

Now Im clueless that after giving the path of the symbol file it still is not able to locate it.?
Is this the wright way of debugging the virtualSerial driver?

Please help me out guys am horribly stuck. From past two weeks I am trying to debug my driver but unable to do so. Due to this I am not able to proceed in my development & the dead line of this task is nearing :-(.

So please help me out

When debugging UMDF, which runs in user mode, you can use the Visual Studio debugger instead of WINDBG. Just select “DEBUG|Attach to Process” from the Visual Studio menu.

* Bob

? Bob Ammerman
? xxxxx@ramsystems.biz
716.864.8337

138 Liston St
Buffalo, NY 14223
www.ramsystems.biz

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:bounce-612502-
xxxxx@lists.osr.com] On Behalf Of xxxxx@chetu.com
Sent: Thursday, July 14, 2016 10:44 AM
To: Windows System Software Devs Interest List
> Subject: RE:[ntdev] Develop a Virtual COM port driver for windows XP &
> above
>
> Hello There,
>
> Now I am trying to debug the WudfHost.exe process(host process of my
> VirtualSerial UMDF driver) that gets created when once I attach my device to
> the PC. In msdn i have read that in order to debug a driver we need to attach
> the host process of that driver to the Windbg.
>
> The process that i followed are as follows as shown in above videos:
>
> 1) I successfully compiled the Virtual COM port driver, traversed to the
> Debug folder of Virtual COM port driver then copied the content of the
> Debug folder to a new folder in my C:\ drive.
> 2) I copied the devcon.exe , wdfverifier.exe , windbg.exe & wudfext.dll,
> WUDFUPDATE_01009.dll and winusbcoinstaller2.dll to the new folder
> 3) Then I opened the Windbg.exe in administrator mode.
> 4) Clicked on the “File” tab in Windbg window then selected “Symbol File
> Path…”, Symbol Search Path window pops up, in that I browse to the new
> folder that contains the virtualserial.pbd( sysmbol file ) & selects OK.
> 5) Then I click the “File” tab in Windbg then I select “Attach to a process…”
> from the Attach a Process window I sort the process “By Executable” & then
> select WudfHost.exe from the list of process & click OK.
>
> Windbg:10.0.1.10586.567 X86 window pops up & displays the following
>
>
> Microsoft (R) Windows Debugger Version 6.1.7601.17514 X86 Copyright (c)
> Microsoft Corporation. All rights reserved.
>
> wait with pending attach
> The call to LoadLibrary(ext) failed, Win32 error 0n2
> “The system cannot find the file specified.”
> Please check your debugger configuration and/or network access.
> The call to LoadLibrary(exts) failed, Win32 error 0n2
> “The system cannot find the file specified.”
> Please check your debugger configuration and/or network access.
> The call to LoadLibrary(uext) failed, Win32 error 0n2
> “The system cannot find the file specified.”
> Please check your debugger configuration and/or network access.
> The call to LoadLibrary(ntsdexts) failed, Win32 error 0n2
> “The system cannot find the file specified.”
> Please check your debugger configuration and/or network access.
> Symbol search path is: C:\Users\amitm2\Desktop\Prctical Package
> Executable search path is:
> ModLoad: 00220000 00253000 C:\Windows\System32\WUDFHost.exe
> ModLoad: 77360000 7749c000 C:\Windows\SYSTEM32\ntdll.dll
> ModLoad: 75bd0000 75ca4000 C:\Windows\system32\kernel32.dll
> ModLoad: 75380000 753cb000 C:\Windows\system32\KERNELBASE.dll
> ModLoad: 759e0000 75a80000 C:\Windows\system32\ADVAPI32.dll
> ModLoad: 758b0000 7595c000 C:\Windows\system32\msvcrt.dll
> ModLoad: 75970000 75989000 C:\Windows\SYSTEM32\sechost.dll
> ModLoad: 77150000 771f1000 C:\Windows\system32\RPCRT4.dll
> ModLoad: 75b00000 75bc9000 C:\Windows\system32\USER32.dll
> ModLoad: 774b0000 774fe000 C:\Windows\system32\GDI32.dll
> ModLoad: 75960000 7596a000 C:\Windows\system32\LPK.dll
> ModLoad: 75d30000 75dcd000 C:\Windows\system32\USP10.dll
> ModLoad: 77200000 7735c000 C:\Windows\system32\ole32.dll
> ModLoad: 6aca0000 6accd000 C:\Windows\System32\WUDFPlatform.dll
> ModLoad: 75dd0000 75f6d000 C:\Windows\system32\SETUPAPI.dll
> ModLoad: 75400000 75427000 C:\Windows\system32\CFGMGR32.dll
> ModLoad: 763a0000 7642f000 C:\Windows\system32\OLEAUT32.dll
> ModLoad: 75630000 75642000 C:\Windows\system32\DEVOBJ.dll
> ModLoad: 748f0000 748f9000 C:\Windows\System32\VERSION.dll
> ModLoad: 75ae0000 75aff000 C:\Windows\system32\IMM32.DLL
> ModLoad: 77080000 7714c000 C:\Windows\system32\MSCTF.dll
> ModLoad: 68740000 6882b000 C:\Windows\System32\dbghelp.dll
> ModLoad: 75270000 7527c000 C:\Windows\System32\CRYPTBASE.dll
> ModLoad: 75430000 7545d000 C:\Windows\system32\WINTRUST.dll
> ModLoad: 754f0000 7560d000 C:\Windows\system32\CRYPT32.dll
> ModLoad: 75350000 7535c000 C:\Windows\system32\MSASN1.dll
> ModLoad: 0fae0000 0fb7a000 C:\Windows\System32\WUDFx.dll
> ModLoad: 759d0000 759d5000 C:\Windows\system32\PSAPI.DLL
> ModLoad: 511a0000 511c2000
> C:\Windows\System32\drivers\UMDF\Virtualserial.dll
> ModLoad: 69a20000 69a23000 C:\Windows\system32\api-ms-win-core-
> synch-l1-2-0.DLL
> (1ae8.1f08): Break instruction exception - code 80000003 (first chance)
> eax=7ffd8000 ebx=00000000 ecx=00000000 edx=773ff1d3 esi=00000000
> edi=00000000
> eip=77394108 esp=00cbfb90 ebp=00cbfbbc iopl=0 nv up ei pl zr na pe nc
> cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000246
>
ERROR: Symbol file could not be found. Defaulted to export symbols for
> C:\Windows\SYSTEM32\ntdll.dll -
> ntdll!DbgBreakPoint:
> 77394108 cc int 3
> *** ERROR: Symbol file could not be found. Defaulted to export symbols for
> C:\Windows\system32\kernel32.dll -
>
>
> Now Im clueless that after giving the path of the symbol file it still is not able
> to locate it.?
> Is this the wright way of debugging the virtualSerial driver?
>
> Please help me out guys am horribly stuck. From past two weeks I am trying
> to debug my driver but unable to do so. Due to this I am not able to proceed
> in my development & the dead line of this task is nearing :-(.
>
> So please help me out
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list online at:
> http:
>
> MONTHLY seminars on crash dump analysis, WDF, Windows internals and
> software drivers!
> Details at http:
>
> To unsubscribe, visit the List Server section of OSR Online at
> http:</http:></http:></http:>

Make sure you are running VS elevated, otherwise it doesn’t have permission to attach to wudfhost.

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Robert Ammerman
Sent: Thursday, July 14, 2016 8:58 AM
To: Windows System Software Devs Interest List
Subject: RE: RE:[ntdev] Develop a Virtual COM port driver for windows XP & above

When debugging UMDF, which runs in user mode, you can use the Visual Studio debugger instead of WINDBG. Just select “DEBUG|Attach to Process” from the Visual Studio menu.

* Bob

? Bob Ammerman
? xxxxx@ramsystems.biz
716.864.8337

138 Liston St
Buffalo, NY 14223
www.ramsystems.biz

> -----Original Message-----
> From: xxxxx@lists.osr.com [mailto:bounce-612502-
> xxxxx@lists.osr.com] On Behalf Of xxxxx@chetu.com
> Sent: Thursday, July 14, 2016 10:44 AM
> To: Windows System Software Devs Interest List
> Subject: RE:[ntdev] Develop a Virtual COM port driver for windows XP &
> above
>
> Hello There,
>
> Now I am trying to debug the WudfHost.exe process(host process of my
> VirtualSerial UMDF driver) that gets created when once I attach my device to
> the PC. In msdn i have read that in order to debug a driver we need to attach
> the host process of that driver to the Windbg.
>
> The process that i followed are as follows as shown in above videos:
>
> 1) I successfully compiled the Virtual COM port driver, traversed to the
> Debug folder of Virtual COM port driver then copied the content of the
> Debug folder to a new folder in my C:\ drive.
> 2) I copied the devcon.exe , wdfverifier.exe , windbg.exe & wudfext.dll,
> WUDFUPDATE_01009.dll and winusbcoinstaller2.dll to the new folder
> 3) Then I opened the Windbg.exe in administrator mode.
> 4) Clicked on the “File” tab in Windbg window then selected “Symbol File
> Path…”, Symbol Search Path window pops up, in that I browse to the new
> folder that contains the virtualserial.pbd( sysmbol file ) & selects OK.
> 5) Then I click the “File” tab in Windbg then I select “Attach to a process…”
> from the Attach a Process window I sort the process “By Executable” & then
> select WudfHost.exe from the list of process & click OK.
>
> Windbg:10.0.1.10586.567 X86 window pops up & displays the following
>
>
> Microsoft (R) Windows Debugger Version 6.1.7601.17514 X86 Copyright (c)
> Microsoft Corporation. All rights reserved.
>
> wait with pending attach
> The call to LoadLibrary(ext) failed, Win32 error 0n2
> “The system cannot find the file specified.”
> Please check your debugger configuration and/or network access.
> The call to LoadLibrary(exts) failed, Win32 error 0n2
> “The system cannot find the file specified.”
> Please check your debugger configuration and/or network access.
> The call to LoadLibrary(uext) failed, Win32 error 0n2
> “The system cannot find the file specified.”
> Please check your debugger configuration and/or network access.
> The call to LoadLibrary(ntsdexts) failed, Win32 error 0n2
> “The system cannot find the file specified.”
> Please check your debugger configuration and/or network access.
> Symbol search path is: C:\Users\amitm2\Desktop\Prctical Package
> Executable search path is:
> ModLoad: 00220000 00253000 C:\Windows\System32\WUDFHost.exe
> ModLoad: 77360000 7749c000 C:\Windows\SYSTEM32\ntdll.dll
> ModLoad: 75bd0000 75ca4000 C:\Windows\system32\kernel32.dll
> ModLoad: 75380000 753cb000 C:\Windows\system32\KERNELBASE.dll
> ModLoad: 759e0000 75a80000 C:\Windows\system32\ADVAPI32.dll
> ModLoad: 758b0000 7595c000 C:\Windows\system32\msvcrt.dll
> ModLoad: 75970000 75989000 C:\Windows\SYSTEM32\sechost.dll
> ModLoad: 77150000 771f1000 C:\Windows\system32\RPCRT4.dll
> ModLoad: 75b00000 75bc9000 C:\Windows\system32\USER32.dll
> ModLoad: 774b0000 774fe000 C:\Windows\system32\GDI32.dll
> ModLoad: 75960000 7596a000 C:\Windows\system32\LPK.dll
> ModLoad: 75d30000 75dcd000 C:\Windows\system32\USP10.dll
> ModLoad: 77200000 7735c000 C:\Windows\system32\ole32.dll
> ModLoad: 6aca0000 6accd000 C:\Windows\System32\WUDFPlatform.dll
> ModLoad: 75dd0000 75f6d000 C:\Windows\system32\SETUPAPI.dll
> ModLoad: 75400000 75427000 C:\Windows\system32\CFGMGR32.dll
> ModLoad: 763a0000 7642f000 C:\Windows\system32\OLEAUT32.dll
> ModLoad: 75630000 75642000 C:\Windows\system32\DEVOBJ.dll
> ModLoad: 748f0000 748f9000 C:\Windows\System32\VERSION.dll
> ModLoad: 75ae0000 75aff000 C:\Windows\system32\IMM32.DLL
> ModLoad: 77080000 7714c000 C:\Windows\system32\MSCTF.dll
> ModLoad: 68740000 6882b000 C:\Windows\System32\dbghelp.dll
> ModLoad: 75270000 7527c000 C:\Windows\System32\CRYPTBASE.dll
> ModLoad: 75430000 7545d000 C:\Windows\system32\WINTRUST.dll
> ModLoad: 754f0000 7560d000 C:\Windows\system32\CRYPT32.dll
> ModLoad: 75350000 7535c000 C:\Windows\system32\MSASN1.dll
> ModLoad: 0fae0000 0fb7a000 C:\Windows\System32\WUDFx.dll
> ModLoad: 759d0000 759d5000 C:\Windows\system32\PSAPI.DLL
> ModLoad: 511a0000 511c2000
> C:\Windows\System32\drivers\UMDF\Virtualserial.dll
> ModLoad: 69a20000 69a23000 C:\Windows\system32\api-ms-win-core-
> synch-l1-2-0.DLL
> (1ae8.1f08): Break instruction exception - code 80000003 (first chance)
> eax=7ffd8000 ebx=00000000 ecx=00000000 edx=773ff1d3 esi=00000000
> edi=00000000
> eip=77394108 esp=00cbfb90 ebp=00cbfbbc iopl=0 nv up ei pl zr na pe nc
> cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000246
>
ERROR: Symbol file could not be found. Defaulted to export symbols for
> C:\Windows\SYSTEM32\ntdll.dll -
> ntdll!DbgBreakPoint:
> 77394108 cc int 3
> *** ERROR: Symbol file could not be found. Defaulted to export symbols for
> C:\Windows\system32\kernel32.dll -
>
>
> Now Im clueless that after giving the path of the symbol file it still is not able
> to locate it.?
> Is this the wright way of debugging the virtualSerial driver?
>
> Please help me out guys am horribly stuck. From past two weeks I am trying
> to debug my driver but unable to do so. Due to this I am not able to proceed
> in my development & the dead line of this task is nearing :-(.
>
> So please help me out
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list online at:
> http:
>
> MONTHLY seminars on crash dump analysis, WDF, Windows internals and
> software drivers!
> Details at http:
>
> To unsubscribe, visit the List Server section of OSR Online at
> http:


NTDEV is sponsored by OSR

Visit the list online at: http:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at http:

To unsubscribe, visit the List Server section of OSR Online at http:</http:></http:></http:></http:></http:></http:>

xxxxx@chetu.com wrote:

Now I am trying to debug the WudfHost.exe process(host process of my VirtualSerial UMDF driver) that gets created when once I attach my device to the PC. In msdn i have read that in order to debug a driver we need to attach the host process of that driver to the Windbg.

ModLoad: 511a0000 511c2000 C:\Windows\System32\drivers\UMDF\Virtualserial.dll
ModLoad: 69a20000 69a23000 C:\Windows\system32\api-ms-win-core-synch-l1-2-0.DLL

Note that your driver is included in the loaded module list. That’s a
Good Thing.

(1ae8.1f08): Break instruction exception - code 80000003 (first chance)
eax=7ffd8000 ebx=00000000 ecx=00000000 edx=773ff1d3 esi=00000000 edi=00000000
eip=77394108 esp=00cbfb90 ebp=00cbfbbc iopl=0 nv up ei pl zr na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000246
*** ERROR: Symbol file could not be found. Defaulted to export symbols for C:\Windows\SYSTEM32\ntdll.dll -
ntdll!DbgBreakPoint:
77394108 cc int 3
*** ERROR: Symbol file could not be found. Defaulted to export symbols for C:\Windows\system32\kernel32.dll -

Now Im clueless that after giving the path of the symbol file it still is not able to locate it.?
Is this the wright way of debugging the virtualSerial driver?

Did you even read the messages? It’s complaining about ntdll.dll and
kernel32.dll. It isn’t complaining about your driver. Have you tried
to set some breakpoints in your driver? That will tell you whether it
likes the symbols for your DLL or not.


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

Thank you everyone for your patience that you show wile answering my basic questions. with all your support I now able to debug my virtualserial driver code using VS.

I would like to list down my steps, that i followed for debugging the code,before jumping to my next question so that in the near future it might help some novice like me :slight_smile:

  1. i installed my virtualserial driver on my system.
  2. copied virtualserial.pdb, that was generate in my project folder after compiling my driver project, at C:\Windows\System32\drivers\UMDF
  3. went to the registry & fill some random non zero value(0x40) against HostProcessDbgBreakOnDriverLoad key
  4. Opened the driver project in VS placed a break point at CreateInstance function & at Onwrite function.
  5. Unplugged & replugged my USB printer.
  6. Quickly In VS I went to Debug–> Attach a process…
  7. refreshed the new window that appeared till I could see the WUDFHost.exe process in the list of process that was displaying.
  8. then I selected the Host process & clicked on.
  9. then i was interrupted by VS for a breakpoint, when i clicked Ok the controller jumped to CreateInstance.
  10. then I opened my serial application & tried to send a data to my USB printer.
  11. as the file write function of my serial application got executed the breakpoint at Onwrite function of my driver was hit. i was super excited to see that :-p
    Hope this helps any new windows driver developer.

Now it is clear from my virtualserial.inf, that i had posted earlier, that I an making WINUSB as my target drive,r & trying to modify the data received from serial application as per WINUsb, by adding the following lines to the virtualserial.inf file

UmdfDispatcher=WinUsb

but my printer is USB class & printer so should I make usbprint.sys as my target driver instead of winusb??

No, keep it winusb. It stays winusb because you sending USB up requests to it, if you put USBprint (not supported regardless) you woild have to send windows print IOs. If you wanted the latter you woild just install USBprint and not have a virtual serial driver

Get Outlook for Androidhttps:

On Mon, Jul 18, 2016 at 7:06 AM -0700, “xxxxx@chetu.com” > wrote:

Thank you everyone for your patience that you show wile answering my basic questions. with all your support I now able to debug my virtualserial driver code using VS.

I would like to list down my steps, that i followed for debugging the code,before jumping to my next question so that in the near future it might help some novice like me :slight_smile:

1) i installed my virtualserial driver on my system.
2) copied virtualserial.pdb, that was generate in my project folder after compiling my driver project, at C:\Windows\System32\drivers\UMDF
3) went to the registry & fill some random non zero value(0x40) against HostProcessDbgBreakOnDriverLoad key
4) Opened the driver project in VS placed a break point at CreateInstance function & at Onwrite function.
5) Unplugged & replugged my USB printer.
6) Quickly In VS I went to Debug–> Attach a process…
7) refreshed the new window that appeared till I could see the WUDFHost.exe process in the list of process that was displaying.
8) then I selected the Host process & clicked on.
9) then i was interrupted by VS for a breakpoint, when i clicked Ok the controller jumped to CreateInstance.
10) then I opened my serial application & tried to send a data to my USB printer.
11) as the file write function of my serial application got executed the breakpoint at Onwrite function of my driver was hit. i was super excited to see that :-p
Hope this helps any new windows driver developer.

Now it is clear from my virtualserial.inf, that i had posted earlier, that I an making WINUSB as my target drive,r & trying to modify the data received from serial application as per WINUsb, by adding the following lines to the virtualserial.inf file

UmdfDispatcher=WinUsb

but my printer is USB class & printer so should I make usbprint.sys as my target driver instead of winusb??


NTDEV is sponsored by OSR

Visit the list online at: http:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at http:

To unsubscribe, visit the List Server section of OSR Online at http:</http:></http:></http:></https:>

Thanks Doron.
So I need to stick with with WinUSB. Now i am trying to format the incoming serial data as per the WinUsb & for this right now i am only modifying Onwrite function of virtualserial sample porject. Initially the On write function of virtualserial was as follows

VOID
STDMETHODCALLTYPE
CMyQueue::OnWrite(
In IWDFIoQueue *pWdfQueue,
In IWDFIoRequest *pWdfRequest,
In SIZE_T BytesToWrite
)
{
WDFMemory* pRequestMemory = NULL;
IWDFIoRequest* pSavedRequest = NULL;
SIZE_T availableData = 0;
SIZE_T savedRequestBufferSize = 0;
HRESULT hr = S_OK;

UNREFERENCED_PARAMETER(pWdfQueue);

//
// Get memory object
//

pWdfRequest->GetInputMemory(&pRequestMemory);

//
// Process input
//

ProcessWriteBytes((PUCHAR)pRequestMemory->GetDataBuffer(NULL), BytesToWrite);

//
// Release memory object and complete request
//
SAFE_RELEASE(pRequestMemory);
pWdfRequest->CompleteWithInformation(hr, BytesToWrite);

//
// Get the amount of data available in the ring buffer
//
m_RingBuffer.GetAvailableData(&availableData);

if (availableData > 0)
{
//
// Continue with the next request, if there is one pending
//
hr = m_FxReadQueue->RetrieveNextRequest(&pSavedRequest);
if ((pSavedRequest == NULL) || (FAILED(hr)))
{
goto Exit;
}

pSavedRequest->GetReadParameters(&savedRequestBufferSize, NULL, NULL);

OnRead(m_FxQueue,
pSavedRequest,
savedRequestBufferSize);

//
// RetrieveNextRequest from a manual queue increments the reference
// counter by 1. We need to decrement it, otherwise the request will
// not be released and there will be an object leak.
//
SAFE_RELEASE(pSavedRequest);
}

//Exit:
return;

}

Then i modified this function as per the OnWrite function in umdf_fx usb example code.

VOID
STDMETHODCALLTYPE
CMyQueue::OnWrite(
In IWDFIoQueue *pWdfQueue,
In IWDFIoRequest *pWdfRequest,
In SIZE_T BytesToWrite
)
{

HRESULT hr = S_OK;
IWDFMemory * pInputMemory = NULL;
UNREFERENCED_PARAMETER(pWdfQueue);
BytesToWrite = 5;
//
// Get memory object
//

//UNREFERENCED_PARAMETER(pWdfQueue);

// Amlendra Implemented code for write

IWDFUsbTargetPipe * pOutputPipe = m_Device->GetOutputPipe();

// pWdfRequest->GetInputMemory(&pRequestMemory);

pWdfRequest->GetInputMemory(&pInputMemory);

hr = pOutputPipe->FormatRequestForWrite(
pWdfRequest,
NULL, //pFile
pInputMemory,
NULL, //Memory offset
NULL //DeviceOffset
);

if (FAILED(hr))
{
pWdfRequest->Complete(hr);
}
else
{
ForwardFormattedRequest(pWdfRequest, pOutputPipe);
}

SAFE_RELEASE(pInputMemory);

return;
}

Now when I try to debug the virtualserial driver code with modified Onwrite function then it throws an exception at

hr = pOutputPipe->FormatRequestForWrite(
pWdfRequest,
NULL, //pFile
pInputMemory,
NULL, //Memory offset
NULL //DeviceOffset
);

that says as follows:

Exception thrown: read access violation
pOutputPipe was 0x30F9C288

I know im doing it wrong, but I am not getting the right way. please guide me through the right path so that I can transfer the data that is being sent by the serial application to the printer.

Debug the read access violation. Does it look like a dereference off of null or something that looks near a valid address? Maybe you want to write a simple umdf USB driver that is not serial so you can build up your knowledge of how to write and debug a umdf driver without the complexity of serial added on top

Get Outlook for Androidhttps:

On Mon, Jul 18, 2016 at 10:57 AM -0700, “xxxxx@chetu.com” > wrote:

Thanks Doron.
So I need to stick with with WinUSB. Now i am trying to format the incoming serial data as per the WinUsb & for this right now i am only modifying Onwrite function of virtualserial sample porject. Initially the On write function of virtualserial was as follows

VOID
STDMETHODCALLTYPE
CMyQueue::OnWrite(
In IWDFIoQueue pWdfQueue,
In IWDFIoRequest pWdfRequest,
In SIZE_T BytesToWrite
)
{
WDFMemory
pRequestMemory = NULL;
IWDFIoRequest
pSavedRequest = NULL;
SIZE_T availableData = 0;
SIZE_T savedRequestBufferSize = 0;
HRESULT hr = S_OK;

UNREFERENCED_PARAMETER(pWdfQueue);

//
// Get memory object
//

pWdfRequest->GetInputMemory(&pRequestMemory);

//
// Process input
//

ProcessWriteBytes((PUCHAR)pRequestMemory->GetDataBuffer(NULL), BytesToWrite);

//
// Release memory object and complete request
//
SAFE_RELEASE(pRequestMemory);
pWdfRequest->CompleteWithInformation(hr, BytesToWrite);

//
// Get the amount of data available in the ring buffer
//
m_RingBuffer.GetAvailableData(&availableData);

if (availableData > 0)
{
//
// Continue with the next request, if there is one pending
//
hr = m_FxReadQueue->RetrieveNextRequest(&pSavedRequest);
if ((pSavedRequest == NULL) || (FAILED(hr)))
{
goto Exit;
}

pSavedRequest->GetReadParameters(&savedRequestBufferSize, NULL, NULL);

OnRead(m_FxQueue,
pSavedRequest,
savedRequestBufferSize);

//
// RetrieveNextRequest from a manual queue increments the reference
// counter by 1. We need to decrement it, otherwise the request will
// not be released and there will be an object leak.
//
SAFE_RELEASE(pSavedRequest);
}

//Exit:
return;

}

Then i modified this function as per the OnWrite function in umdf_fx usb example code.

VOID
STDMETHODCALLTYPE
CMyQueue::OnWrite(
In IWDFIoQueue *pWdfQueue,
In IWDFIoRequest *pWdfRequest,
In SIZE_T BytesToWrite
)
{

HRESULT hr = S_OK;
IWDFMemory * pInputMemory = NULL;
UNREFERENCED_PARAMETER(pWdfQueue);
BytesToWrite = 5;
//
// Get memory object
//

//UNREFERENCED_PARAMETER(pWdfQueue);

// Amlendra Implemented code for write

IWDFUsbTargetPipe * pOutputPipe = m_Device->GetOutputPipe();

// pWdfRequest->GetInputMemory(&pRequestMemory);

pWdfRequest->GetInputMemory(&pInputMemory);

hr = pOutputPipe->FormatRequestForWrite(
pWdfRequest,
NULL, //pFile
pInputMemory,
NULL, //Memory offset
NULL //DeviceOffset
);

if (FAILED(hr))
{
pWdfRequest->Complete(hr);
}
else
{
ForwardFormattedRequest(pWdfRequest, pOutputPipe);
}

SAFE_RELEASE(pInputMemory);

return;
}

Now when I try to debug the virtualserial driver code with modified Onwrite function then it throws an exception at

hr = pOutputPipe->FormatRequestForWrite(
pWdfRequest,
NULL, //pFile
pInputMemory,
NULL, //Memory offset
NULL //DeviceOffset
);

that says as follows:

Exception thrown: read access violation
pOutputPipe was 0x30F9C288

I know im doing it wrong, but I am not getting the right way. please guide me through the right path so that I can transfer the data that is being sent by the serial application to the printer.


NTDEV is sponsored by OSR

Visit the list online at: http:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at http:

To unsubscribe, visit the List Server section of OSR Online at http:</http:></http:></http:></https:>

xxxxx@chetu.com wrote:

Then i modified this function as per the OnWrite function in umdf_fx usb example code.

VOID
STDMETHODCALLTYPE
CMyQueue::OnWrite(
In IWDFIoQueue *pWdfQueue,
In IWDFIoRequest *pWdfRequest,
In SIZE_T BytesToWrite
)
{

HRESULT hr = S_OK;
IWDFMemory * pInputMemory = NULL;
UNREFERENCED_PARAMETER(pWdfQueue);
BytesToWrite = 5;
//
// Get memory object
//

//UNREFERENCED_PARAMETER(pWdfQueue);

// Amlendra Implemented code for write

IWDFUsbTargetPipe * pOutputPipe = m_Device->GetOutputPipe();

The VirtualSerial driver source does not have a function called
GetOutputPipe, largely because it does not deal with USB at all. Have
you actually added code to create an IWDFUsbTargetDevice and configure
the endpoints?


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

Tim Roberts wrote:

The VirtualSerial driver source does not have a function
called GetOutputPipe, largely because it does not deal with
USB at all. Have you actually added code to create an
IWDFUsbTargetDevice and configure the endpoints?

It seems in this case, you need to just “study” the code a little more closely…

// Amlendra Implemented code for write

IWDFUsbTargetPipe * pOutputPipe = m_Device->GetOutputPipe();

Surely “Amlendra” has taken care of all the necessary details…

Thank You Tim & Chris.

The VirtualSerial driver source does not have a function called
GetOutputPipe, largely because it does not deal with USB at all. Have
you actually added code to create an IWDFUsbTargetDevice and configure
the endpoints?

After your comments on my previous post I checked out the of Umdf_fx2 that to create an IWDFUsbTargetDevice and configure the endpoints.

In Umdf_fx2 code there is function called CMyDevice::OnPrepareHardware (In IWDFDevice * ) it is in this function tha creates the USB target by calling the following function

if (SUCCEEDED(hr))
{
hr = CreateUsbIoTargets(); //This routine creates Usb device, interface and pipe objects
}

after that it retrives device information by calling the following function

hr = m_pIUsbTargetDevice->RetrieveDeviceInformation(DEVICE_SPEED, &length, &m_Speed) ;

Then it configures the USB pipes & setup power-management settings on the device by the following functions

if (SUCCEEDED(hr))
{
hr = ConfigureUsbPipes();
}

if (SUCCEEDED(hr))
{
hr = SetPowerManagement();
}

So I added these functions along with other variables & functions that are required for a USB to the CMyDevice cass in my virtuslserial driver code.

So the CMyDevice class of virtualseriala driver, before adding the USB functions looked like this:

class CMyDevice :
public CUnknown,
public IObjectCleanup
{

//
// Private data members.
//
private:

IWDFDevice *m_FxDevice;
ULONG m_BaudRate;
ULONG m_MCR;
ULONG m_FCR;
ULONG m_LCR;
UCHAR m_ValidDataMask;
SERIAL_TIMEOUTS m_Timeouts;
BOOL m_CreatedLegacyHardwareKey;

IWDFNamedPropertyStore2 * m_LegacyHardwarePropertyStore;

PWCHAR m_PdoName;
//
// Private methods.
//

private:

CMyDevice( VOID ) :
m_FxDevice(NULL),
m_BaudRate(0),
m_MCR(0),
m_FCR(0),
m_LCR(0),
m_ValidDataMask(0),
m_CreatedLegacyHardwareKey(FALSE),
m_LegacyHardwarePropertyStore(NULL),
m_PdoName(NULL)
{
ZeroMemory(&m_Timeouts, sizeof(SERIAL_TIMEOUTS));
}

HRESULT Initialize(In IWDFDriver *FxDriver, In IWDFDeviceInitialize *FxDeviceInit );

HRESULT CMyDevice::GetPdoName(Out LPWSTR *PdoName );
//
// Public methods
//
public:

//
// The factory method used to create an instance of this driver.
//

static HRESULT CreateInstance(In IWDFDriver *FxDriver, In IWDFDeviceInitialize *FxDeviceInit, Out PCMyDevice *Device );

HRESULT Configure( VOID );

//
// COM methods
//
public:

//
// IUnknown methods.
//

virtual ULONG STDMETHODCALLTYPE AddRef( VOID )
{
return __super::AddRef();
}

At(this, __drv_freesMem(object)) virtual ULONG STDMETHODCALLTYPE Release(VOID)
{
return __super::Release();
}

virtual HRESULT STDMETHODCALLTYPE QueryInterface(In REFIID InterfaceId, Out PVOID *Object );

IObjectCleanup * QueryIObjectCleanup( VOID )
{
AddRef();
return static_cast(this);
}

virtual void STDMETHODCALLTYPE OnCleanup(IWDFObject* pWdfObject );

ULONG GetBaudRate( VOID )
{
return m_BaudRate;
}

void SetBaudRate(In ULONG BaudRate )
{
m_BaudRate = BaudRate;
return;
}

ULONG * GetModemControlRegisterPtr( VOID)
{
return &m_MCR;
}

ULONG * GetFifoControlRegisterPtr( VOID )
{
return &m_FCR;
}

ULONG * GetLineControlRegisterPtr( VOID )
{
return &m_LCR;
}

VOID SetValidDataMask(In UCHAR Mask)
{
m_ValidDataMask = Mask;
}

VOID SetTimeouts( In SERIAL_TIMEOUTS Timeouts )
{
m_Timeouts = Timeouts;
}

VOID GetTimeouts( Out SERIAL_TIMEOUTS *Timeouts )
{
*Timeouts = m_Timeouts;;
}
};

and after adding the USB functions variables the CMyDevice looks like this

class CMyDevice :
public CUnknown,
public IObjectCleanup, public IPnpCallbackHardware, public IPnpCallback
{

//
// Private data members.
//
private:

IWDFDevice *m_FxDevice;

//IWDFDevice2 *m_FxDevice;

ULONG m_BaudRate;

ULONG m_MCR;

ULONG m_FCR;

ULONG m_LCR;

IWDFUsbTargetDevice * m_pIUsbTargetDevice;

IWDFUsbInterface * m_pIUsbInterface;

//
// USB Input pipe for Reads
//
IWDFUsbTargetPipe * m_pIUsbInputPipe;

//
// USB Output pipe for writes
//
IWDFUsbTargetPipe * m_pIUsbOutputPipe;

//
// USB interrupt pipe
//
IWDFUsbTargetPipe * m_pIUsbInterruptPipe;

//
// USB interrupt pipe state management
//
IWDFIoTargetStateManagement * m_pIoTargetInterruptPipeStateMgmt;

//
// Device Speed (Low, Full, High)
//
UCHAR m_Speed;

UCHAR m_ValidDataMask;

SERIAL_TIMEOUTS m_Timeouts;

//
// Legacy hardware key property store
//
BOOL m_CreatedLegacyHardwareKey;

IWDFNamedPropertyStore2 * m_LegacyHardwarePropertyStore;

PWCHAR m_PdoName;
//
// Private methods.
//

private:

CMyDevice(
VOID
) :
m_FxDevice(NULL),
m_BaudRate(0),
m_MCR(0),
m_FCR(0),
m_LCR(0),
//Amlendra
m_pIUsbTargetDevice(NULL),
m_pIUsbInterface(NULL),
m_pIUsbInputPipe(NULL),
m_pIUsbOutputPipe(NULL),
m_pIUsbInterruptPipe(NULL),
m_Speed(0),
//mishra
m_ValidDataMask(0),
m_CreatedLegacyHardwareKey(FALSE),
m_LegacyHardwarePropertyStore(NULL),
m_PdoName(NULL)
{
ZeroMemory(&m_Timeouts, sizeof(SERIAL_TIMEOUTS));
}

HRESULT
Initialize(
In IWDFDriver *FxDriver,
In IWDFDeviceInitialize *FxDeviceInit
);

HRESULT
CMyDevice::GetPdoName(
Out LPWSTR *PdoName
);

HRESULT
CreateUsbIoTargets( //Amlendra
VOID
);

HRESULT
ConfigureUsbPipes(
);

HRESULT
SetPowerManagement(
VOID
);

//
// Public methods
//
public:

//
// The factory method used to create an instance of this driver.
//

static
HRESULT
CreateInstance(
In IWDFDriver *FxDriver,
In IWDFDeviceInitialize *FxDeviceInit,
Out PCMyDevice *Device
);

HRESULT
Configure(
VOID
);

//
// COM methods
//
public:

IWDFUsbTargetDevice *
GetUsbTargetDevice(
)
{
return m_pIUsbTargetDevice;
}

IWDFUsbTargetPipe
GetInputPipe(
)
{
return m_pIUsbInputPipe;
}

IWDFUsbTargetPipe
GetOutputPipe(
)
{
return m_pIUsbOutputPipe;
}

HRESULT
ConfigContReaderForInterruptEndPoint(
VOID
);

virtual
ULONG
STDMETHODCALLTYPE
AddRef(
VOID
)
{
return __super::AddRef();
}

At(this,__drv_freesMem(object))
virtual
ULONG
STDMETHODCALLTYPE
Release(
VOID
)
{
return __super::Release();
}

virtual
HRESULT
STDMETHODCALLTYPE
QueryInterface(
In REFIID InterfaceId,
Out PVOID Object
);

IObjectCleanup
QueryIObjectCleanup(
VOID
)
{
AddRef();
return static_cast(this);
}

virtual
void
STDMETHODCALLTYPE
OnCleanup(
IWDFObject
pWdfObject
);

//
// IPnpCallbackHardware

virtual
HRESULT
STDMETHODCALLTYPE
OnPrepareHardware(
In IWDFDevice FxDevice
);

//
// IPnpCallback
//
virtual
HRESULT
STDMETHODCALLTYPE
OnD0Entry(
In IWDFDevice
pWdfDevice,
In WDF_POWER_DEVICE_STATE previousState
);

virtual
HRESULT
STDMETHODCALLTYPE
OnD0Exit(
In IWDFDevice
pWdfDevice,
In WDF_POWER_DEVICE_STATE previousState
);

virtual
void
STDMETHODCALLTYPE
OnSurpriseRemoval(
In IWDFDevice
pWdfDevice
);

virtual
HRESULT
STDMETHODCALLTYPE
OnReleaseHardware(
In IWDFDevice FxDevice
);

virtual HRESULT STDMETHODCALLTYPE OnQueryRemove(In IWDFDevice
pWdfDevice);

virtual HRESULT STDMETHODCALLTYPE OnQueryStop(In IWDFDevice
pWdfDevice);

ULONG GetBaudRate( VOID )
{
return m_BaudRate;
}

void SetBaudRate( In ULONG BaudRate )
{
m_BaudRate = BaudRate;
return;
}

ULONG * GetModemControlRegisterPtr( VOID )
{
return &m_MCR;
}

ULONG * GetFifoControlRegisterPtr( VOID )
{
return &m_FCR;
}

ULONG * GetLineControlRegisterPtr( VOID )
{
return &m_LCR;
}

VOID SetValidDataMask(In UCHAR Mask )
{
m_ValidDataMask = Mask;
}

VOID SetTimeouts(In SERIAL_TIMEOUTS Timeouts )
{
m_Timeouts = Timeouts;
}

VOID GetTimeouts( Out SERIAL_TIMEOUTS *Timeouts )
{
*Timeouts = m_Timeouts;;
}
};

When I installed the newly edited virtualserial driver with USB addition & try to debug the code, I found that the control never comes to CMyDevice::OnPrepareHardware() function in my virtualserial driver.

along with that when we try to send some data to the device to the serial application then the control comes to

CMyQueue::OnWrite(
In IWDFIoQueue *pWdfQueue,
In IWDFIoRequest *pWdfRequest,
In SIZE_T BytesToWrite
)

but when we step in through the function then

hr = pOutputPipe->FormatRequestForWrite(
pWdfRequest,
NULL, //pFile
pInputMemory,
NULL, //Memory offset
NULL //DeviceOffset
);

function returns null & we get an exception. According to me it happens coz we haven’t initialise the USB target device.

So please guide through the right path by which I can create the USBIOTraget device & configure the same.

xxxxx@chetu.com wrote:

After your comments on my previous post I checked out the of Umdf_fx2 that to create an IWDFUsbTargetDevice and configure the endpoints.

In Umdf_fx2 code there is function called CMyDevice::OnPrepareHardware (In IWDFDevice * ) it is in this function tha creates the USB target by calling the following function

if (SUCCEEDED(hr))
{
hr = CreateUsbIoTargets(); //This routine creates Usb device, interface and pipe objects
}

if (SUCCEEDED(hr))
{
hr = ConfigureUsbPipes();
}

if (SUCCEEDED(hr))
{
hr = SetPowerManagement();
}

So I added these functions along with other variables & functions that are required for a USB to the CMyDevice cass in my virtuslserial driver code.

Forgive me for being blunt, but it seems like you are just throwing
large chunks of code from multiple projects into a single basket and
shaking them up, hoping that something will stick together and
accidentally product magic. Have you gone through all of those code to
make sure it does what you need, and that it does it in the right way?
YOU need to design YOUR driver, and then fill in code that implemented
YOUR design.

and after adding the USB functions variables the CMyDevice looks like this

class CMyDevice :
public CUnknown,
public IObjectCleanup, public IPnpCallbackHardware, public IPnpCallback

Implementing IPnpCallback and IPnpCallbackHardware is one step, but in
order for those interfaces to be visible to the outside world, you have
to be able to return them in your QueryInterface. Did you modify your
QueryInterface code to return those new interfaces?

When I installed the newly edited virtualserial driver with USB addition & try to debug the code, I found that the control never comes to CMyDevice::OnPrepareHardware() function in my virtualserial driver.

If you are not checking for IPnpCallbackHardware in QueryInterface, then
the framework has no way to call that function.

hr = pOutputPipe->FormatRequestForWrite(
pWdfRequest,
NULL, //pFile
pInputMemory,
NULL, //Memory offset
NULL //DeviceOffset
);

function returns null & we get an exception.

That’s not null. An HRESULT of 0 is “S_OK” – success.

So please guide through the right path by which I can create the USBIOTraget device & configure the same.

Have you read any of the documentation on writing a UMDF driver?


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

Tim Roberts wrote:

Forgive me for being blunt, but it seems like you are just
throwing large chunks of code from multiple projects into
a single basket and shaking them up, hoping that something
will stick together and accidentally product magic.

Driver development, +91 style.

Have you read any of the documentation on writing a UMDF
driver?

Of course he hasn’t. Doron told him earlier in the thread to just make a simplified bulk I/O driver, free of the serial cruft, to learn UMDF and USB driver debugging. You’ll note that this “advice” was quickly “ignored”.

Let’s rewind a little bit earlier in this thread:

Please help me out guys am horribly stuck. From past two weeks
I am trying to debug my driver but unable to do so. Due to this I
am not able to proceed in my development & the dead line of this
task is nearing :-(.

So OP, it’s been a week and you’re no closer. Are you going to stop throwing sh** at the wall to see what sticks, and actually try to learn what you’re doing? Or not?

I sincerely apologize for my deed.
Tom & Chris you were right as i had a time constrain & this my 1st experience with Windows device driver initially I was trying to put every thing into one basket & desperately trying to make it work without knowing much about what I was I doing.

Thank you for the eye opener. I promise I would not repeat that mistake.

That is the reason I have been going through all the available documents, blogs links etc that I can find from the internet on UMDF drivers especially USB drivers.

>Of course he hasn’t. Doron told him earlier in the thread to just make a
>simplified bulk I/O driver, free of the serial cruft, to learn UMDF and USB
>driver debugging. You’ll note that this “advice” was quickly “ignored”.

Sorry It was unintentional. Right now I am following the same path as advised by Doron. I am write a UMDF driver project through which a PC application can communicate with my USB printer device and Doron was right, through this process I have & still learning a lot about UMDF drivers

I have been going through the MSDN documents on UMDF drivers especially USB drivers.

This is what I have been doing since the 24th of this month.

I created a new USB UMDF V1 driver project & trying to write a simple USB driver that could write to my USB printer.

In the new project I added code in CMyDevice::OnPrepareHardware function to create USB target device, then I retrieved the interface & End point information from my device & selected the appropriate End points & interface. I have added the CMyDevice::OnPrepareHardware function to QI so now it is getting invoked by the frame work.

I also added the code for CMyIoQueue::Onwrite function & added it to the QueryInterface as well.
.
When I install the USB driver I found that the CMyIoQueue::Onwrite() function gets invokes once I call writefile() function from my Win32 application.

While debugging the CMyDevice::OnPrepareHardware function I found out that when I retrieve the address of the output Endpoints(pIUsbPipe) through

if (pIUsbPipe->IsOutEndPoint() && (UsbdPipeTypeBulk == pIUsbPipe->GetType()))
{
m_pIUsbOutputPipe = pIUsbPipe;
}

I get a valid a 32 bit address but along with the address i get the following statement
“Information not available no symbols were loaded for WUDFX.dl”

when I take pIUsbPipe in the watch window it lokes like this:

0x009368b81.

but the code doesn’t break or throw any exception.

Then when I invoke the writefile() Win32 API from my application the control comes to CMyIoQueue::Onwrite function then I step into it till i reach the following code line

pOutputPipe = m_Device->GetOutputPipe()

when I step over this line & add pOutputPipe to watch window i get the following address against it

0x009368b8l

hr = pOutputPipe->FormatRequestForWrite(
pWdfRequest,
NULL, //pFile
pInputMemory,
NULL, //Memory offset
NULL //DeviceOffset
);

I get the following exception

pOutputPipe-> was nullptr

So question is in the previous line pOutputPipe was pointing to 0x009368b8l address then how can it be a nullptr.??

xxxxx@chetu.com wrote:

I created a new USB UMDF V1 driver project & trying to write a simple USB driver that could write to my USB printer.

In the new project I added code in CMyDevice::OnPrepareHardware function to create USB target device, then I retrieved the interface & End point information from my device & selected the appropriate End points & interface. I have added the CMyDevice::OnPrepareHardware function to QI so now it is getting invoked by the frame work.

I also added the code for CMyIoQueue::Onwrite function & added it to the QueryInterface as well.

When I install the USB driver I found that the CMyIoQueue::Onwrite() function gets invokes once I call writefile() function from my Win32 application.

That’s good. A lot of stuff has to be working to get that far.

While debugging the CMyDevice::OnPrepareHardware function I found out that when I retrieve the address of the output Endpoints(pIUsbPipe) through

if (pIUsbPipe->IsOutEndPoint() && (UsbdPipeTypeBulk == pIUsbPipe->GetType()))
{
m_pIUsbOutputPipe = pIUsbPipe;
}

I get a valid a 32 bit address but along with the address i get the following statement
“Information not available no symbols were loaded for WUDFX.dl”

when I take pIUsbPipe in the watch window it lokes like this:
0x009368b81.
> but the code doesn’t break or throw any exception.

This is a data structure on the heap. It’s probably trying to load
symbols so it can show you the contents of IWDFUsbTargetPipe, but
because that’s an interface, it doesn’t contain any data, so there’s
nothing to look at anyway. It is unusual that it would be at an odd
address, however. If you dump the memory at that address, does it look
like a C++ interface? That is, a set of function pointers?

> Then when I invoke the writefile() Win32 API from my application the control comes to CMyIoQueue::Onwrite function then I step into it till i reach the following code line
>
> pOutputPipe = m_Device->GetOutputPipe()
>
> when I step over this line & add pOutputPipe to watch window i get the following address against it
> 0x009368b8l

Good that it is the same address, even if it is an odd number.

> hr = pOutputPipe->FormatRequestForWrite(
> pWdfRequest,
> NULL, //pFile
> pInputMemory,
> NULL, //Memory offset
> NULL //DeviceOffset
> );
>
> I get the following exception
>
> pOutputPipe-> was nullptr

Where do you see that exception? Are you seeing that in the watch
window? If so, forget about it. Don’t ever trust the debugger,
especially with local variables. Too much information is lost during
compilation. If the driver did not crash at that point, then obviously
the pointer was not null. You can try debugging the assembler, or
printing stuff out to the debug log.

> So question is in the previous line pOutputPipe was pointing to 0x009368b8l address then how can it be a nullptr.??

Clearly it can’t, so it isn’t.


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