none
VisualBasic: OpenSerialPort throws ArgumentException RRS feed

  • Question

  • I wrote a driver for a virtual Serial device. When I use VisualBasic/OpenSerialPort to open the device I get an "ArgumentException".

    How can I make sure that my driver can be used from VisualBasic? Do I perhaps need a valid (official) digital signature?

     

    Tuesday, July 16, 2013 1:42 PM

Answers

  • This should not be due to lack of a signature.  Debug your driver and see if you get the call and what is the return from the call.   If you don't get the open call, then you need to check higher by debugging the visual basic code and its underlying support routines.  If you do get the call, see what error is occuring.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com Blog: http://msmvps.com/blogs/WinDrvr

    Tuesday, July 16, 2013 1:54 PM
  • I found a Workaround for this Problem. I do not use OpenSerialPort() but CreateFile() as described at http://www.mikrocontroller.net/topic/66465

    But a much better solution is to edit virtualserial.inx and after this line:

    [VirtualSerial_Install.NT.hw]

    insert 3 more lines:

    AddReg=SetDeviceType_AddReg

    [SetDeviceType_AddReg]

    HKR,,DeviceType,0x10001,0x0000001b  ; 0x1b = FILE_DEVICE_SERIAL_PORT

    The resulting device can then be opened using OpenSerialPort().

    • Marked as answer by Paul Sievers Monday, August 5, 2013 11:32 AM
    • Edited by Paul Sievers Wednesday, October 22, 2014 6:15 AM better solution
    Monday, August 5, 2013 11:31 AM

All replies

  • This should not be due to lack of a signature.  Debug your driver and see if you get the call and what is the return from the call.   If you don't get the open call, then you need to check higher by debugging the visual basic code and its underlying support routines.  If you do get the call, see what error is occuring.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com Blog: http://msmvps.com/blogs/WinDrvr

    Tuesday, July 16, 2013 1:54 PM
  • Also, see if the create suceeds and then you receive Io (read, write, ioctls) that you fail immediately after the create

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Tuesday, July 16, 2013 2:28 PM
  • How can I debug the  underlying support routines? I do a SingleStep (F11) on the code-line:

               comport = My.Computer.Ports.OpenSerialPort("COM7")

    VisualStudio immediately complains about the ArgumentException. It does not step into any support routines.

    Also, my driver does not get any requests when I do this.

    Wednesday, July 17, 2013 11:13 AM
  • You need to use Windbg just like you would for your driver.  Put breakpoints on the ZwCreateFile and ZwOpenFile in NTDLL and see what error gets returned to Visual Basic's runtimes.

    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com Blog: http://msmvps.com/blogs/WinDrvr

    Wednesday, July 17, 2013 11:30 AM
  • I use VisualStudio to debug my UMDF-Driver. I don't know much about WinDbg.  Here is what I got:

    *** wait with pending attach
    Symbol search path is: SRV*http://msdl.microsoft.com/download/symbols
    Executable search path is: C:\Users\paul.sievers\MSD4011Konfig\SerialDriverTest\XMCommTest\XMCommTest\bin\Debug
    ModLoad: 01200000 0120e000   C:\Users\paul.sievers\MSD4011Konfig\SerialDriverTest\XMCommTest\XMCommTest\bin\Debug\XMCommTest.exe
    ModLoad: 77c60000 77d9c000   C:\Windows\SYSTEM32\ntdll.dll
    ModLoad: 71af0000 71b3a000   C:\Windows\SYSTEM32\MSCOREE.DLL
    ModLoad: 77470000 77544000   C:\Windows\system32\KERNEL32.dll
    ModLoad: 75d20000 75d6b000   C:\Windows\system32\KERNELBASE.dll
    ModLoad: 77330000 773d0000   C:\Windows\system32\ADVAPI32.dll
    ModLoad: 76f10000 76fbc000   C:\Windows\system32\msvcrt.dll
    ModLoad: 77da0000 77db9000   C:\Windows\SYSTEM32\sechost.dll
    ModLoad: 76000000 760a1000   C:\Windows\system32\RPCRT4.dll
    ModLoad: 719d0000 71a4a000   C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscoreei.dll
    ModLoad: 771a0000 771f7000   C:\Windows\system32\SHLWAPI.dll
    ModLoad: 776b0000 776fe000   C:\Windows\system32\GDI32.dll
    ModLoad: 761f0000 762b9000   C:\Windows\system32\USER32.dll
    ModLoad: 76100000 7610a000   C:\Windows\system32\LPK.dll
    ModLoad: 773d0000 7746d000   C:\Windows\system32\USP10.dll
    ModLoad: 761c0000 761df000   C:\Windows\system32\IMM32.DLL
    ModLoad: 77200000 772cc000   C:\Windows\system32\MSCTF.dll
    ModLoad: 54460000 54af3000   C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
    ModLoad: 70410000 704e3000   C:\Windows\system32\MSVCR110_CLR0400.dll
    ModLoad: 52990000 5395a000   C:\Windows\assembly\NativeImages_v4.0.30319_32\mscorlib\bf2ecabcd96ec8238dc385b0a3ffa084\mscorlib.ni.dll
    ModLoad: 77550000 776ac000   C:\Windows\system32\ole32.dll
    ModLoad: 75c20000 75c2c000   C:\Windows\system32\CRYPTBASE.dll
    ModLoad: 74cb0000 74cf0000   C:\Windows\system32\uxtheme.dll
    ModLoad: 52010000 5298d000   C:\Windows\assembly\NativeImages_v4.0.30319_32\System\9c7c3cd390aa067130df3a89c0d3b6e4\System.ni.dll
    ModLoad: 50d40000 513ef000   C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Core\0e5a4b9b215047e0ef087a95683e4ece\System.Core.ni.dll
    ModLoad: 5da00000 5dbd6000   C:\Windows\assembly\NativeImages_v4.0.30319_32\Microsoft.V9921e851#\b85aa32a551577438012a5fb0c9a07df\Microsoft.VisualBasic.ni.dll
    ModLoad: 711b0000 7121e000   C:\Windows\Microsoft.NET\Framework\v4.0.30319\clrjit.dll
    ModLoad: 56180000 56311000   C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Drawing\9cab1291edbd51be678afdaf86c643c4\System.Drawing.ni.dll
    ModLoad: 513f0000 5200f000   C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Windows.Forms\94fc97289ba0902a9237cdbfc19cdcc1\System.Windows.Forms.ni.dll
    ModLoad: 73490000 73514000   C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.7601.17514_none_ec83dffa859149af\comctl32.dll
    ModLoad: 71220000 71232000   C:\Windows\Microsoft.NET\Framework\v4.0.30319\nlssorting.dll
    ModLoad: 5f980000 5fa6e000   C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Configuration\d87de4bbcefb0a67eaae225f35964a4f\System.Configuration.ni.dll
    ModLoad: 61be0000 62319000   C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Xml\858e88af3a72319bdce4f6e1f9492f46\System.Xml.ni.dll
    ModLoad: 745c0000 745d3000   C:\Windows\system32\dwmapi.dll
    ModLoad: 64aa0000 64b63000   C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Runt73a1fc9d#\e42fcb372586d8b433cc3f5e23c5ab4e\System.Runtime.Remoting.ni.dll
    ModLoad: 74a10000 74ba0000   C:\Windows\WinSxS\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.7601.18120_none_72d2e82386681b36\gdiplus.dll
    ModLoad: 74cf0000 74e8e000   C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.7601.17514_none_41e6975e2bd6f2b2\comctl32.dll
    ModLoad: 77110000 7719f000   C:\Windows\system32\OLEAUT32.DLL
    (1ea4.1f4c): Break instruction exception - code 80000003 (first chance)
    eax=7ffde000 ebx=00000000 ecx=00000000 edx=77cff17d esi=00000000 edi=00000000
    eip=77c9410c esp=055ffee4 ebp=055fff10 iopl=0         nv up ei pl zr na pe nc
    cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000246
    ntdll!DbgBreakPoint:
    77c9410c cc              int     3
    0:005> bm ZwCreateFile
    breakpoint 0 redefined
      0: 77ca55c8          @!"ntdll!ZwCreateFile"
    0:005> bm ZwOpenFile
    breakpoint 1 redefined
      1: 77ca5cd8          @!"ntdll!ZwOpenFile"
    0:005> .sympath SRV*http://msdl.microsoft.com/download/symbols
    Symbol search path is: SRV*http://msdl.microsoft.com/download/symbols
    Expanded Symbol search path is: srv*http://msdl.microsoft.com/download/symbols
    0:005> g
    Breakpoint 0 hit
    eax=0013ed54 ebx=00000000 ecx=0013ecf8 edx=00000000 esi=77ca55c8 edi=00000000
    eip=77ca55c8 esp=0013ecbc ebp=0013ed5c iopl=0         nv up ei ng nz na po nc
    cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000282
    ntdll!NtCreateFile:
    77ca55c8 b842000000      mov     eax,42h
    *** WARNING: Unable to verify checksum for C:\Windows\assembly\NativeImages_v4.0.30319_32\System\9c7c3cd390aa067130df3a89c0d3b6e4\System.ni.dll
    *** WARNING: Unable to verify checksum for C:\Windows\assembly\NativeImages_v4.0.30319_32\Microsoft.V9921e851#\b85aa32a551577438012a5fb0c9a07df\Microsoft.VisualBasic.ni.dll
    *** WARNING: Unable to verify checksum for C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Windows.Forms\94fc97289ba0902a9237cdbfc19cdcc1\System.Windows.Forms.ni.dll

    I see the following code:

    ntdll!NtCreateFile:
    77ca55c8 b842000000      mov     eax,42h
    77ca55cd ba0003fe7f      mov     edx,offset SharedUserData!SystemCallStub (7ffe0300)
    77ca55d2 ff12            call    dword ptr [edx]
    77ca55d4 c22c00          ret     2Ch

    When eip reaches 77ca55d4 I see the following Register values:

    eax 0, ebx 0, ecx 1, edx ffffffff, efl 282

    Where can I find the returned error code?

    Wednesday, July 17, 2013 2:08 PM
  • You need two instances of VS running. First one is attached to your app. The second is attached to your umdf driver. You can also use .net reflector or another IL dumping tool to show you exactly what OpenSerialPort does

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Wednesday, July 17, 2013 6:44 PM
  • I set breakpoints on all toplevel functions of my driver (I didn't check functions defined in header files). No breakpoint (in the driver)was reached before the ArgumentException was thrown.

    My driver is derived from the virtual serial sample driver (http://code.msdn.microsoft.com/windowshardware/Virtual-serial-driver-8383ea42 ). The original sample driver shows the same problem. So, it should be possible to reproduce the problem without using any of my code. I stepped (StepOver, F10) through all the code from the breakpoint (at ntdll!NtCreateFile) until the exception was thrown. It is a lot. I do not really see a chance to find the problem that way (even if I had access to the source code, which I did not manage to see). So, could someone at Microsoft investigate this?

    I use Windows 7 Professional, Service Pack 1. I use the following VB source code for my tests:

     Public Class Form1
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim comport As IO.Ports.SerialPort = Nothing
            comport = My.Computer.Ports.OpenSerialPort("COM7")
         End Sub
    End Class




    • Edited by Paul Sievers Thursday, July 18, 2013 9:29 AM clarity
    Thursday, July 18, 2013 8:34 AM
  • I found a Workaround for this Problem. I do not use OpenSerialPort() but CreateFile() as described at http://www.mikrocontroller.net/topic/66465

    But a much better solution is to edit virtualserial.inx and after this line:

    [VirtualSerial_Install.NT.hw]

    insert 3 more lines:

    AddReg=SetDeviceType_AddReg

    [SetDeviceType_AddReg]

    HKR,,DeviceType,0x10001,0x0000001b  ; 0x1b = FILE_DEVICE_SERIAL_PORT

    The resulting device can then be opened using OpenSerialPort().

    • Marked as answer by Paul Sievers Monday, August 5, 2013 11:32 AM
    • Edited by Paul Sievers Wednesday, October 22, 2014 6:15 AM better solution
    Monday, August 5, 2013 11:31 AM