GetDefaultCommConfig VB v C#

Discussion in 'Microsoft C# .NET' started by rollasoc, Feb 19, 2004.

  1. rollasoc

    rollasoc Guest

    Hi,

    I'm trying to get a list of COM ports on my machine using the API
    GetDefaultCommConfig.

    I've found an example in VB of how to do this but wanted to C# it up.

    This works fine but is very slow in C#

    In VB it searches for 16 COM Ports in less than a second.

    In C# it searches for 10 COM Ports in about 3 seconds.

    Why the difference in speed?

    I did note in the Output window that the VB does the following once

    'WindowsApplication2.exe': Loaded
    'c:\winnt\assembly\gac\microsoft.visualbasic\7.0.5000.0__b03f5f7f11d50a3a\mi
    crosoft.visualbasic.dll', No symbols loaded.

    In C# I get the following in the Output window for each iteration

    'MyApp.exe': Loaded 'C:\WINNT\system32\cfgmgr32.dll', No symbols loaded.
    'MyApp.exe': Unloaded 'C:\WINNT\system32\cfgmgr32.dll'

    plus several
    'MyApp.exe': Loaded 'C:\WINNT\system32\serialui.dll', No symbols loaded.
    'MyApp.exe': Unloaded 'C:\WINNT\system32\serialui.dll'

    I'm assuming the extra time being taken is in the loading and unloading of
    the libraries many many times.

    How can I speed this up? (Seems a bit daft to have to create a whole VB
    DLL just for one function call.

    Any ideas?

    Rollasoc
     
    rollasoc, Feb 19, 2004
    #1
    1. Advertisements

  2. rollasoc

    BuddyWork Guest

    If you just want a list of COM ports on your machine then
    use the Windows API EnumPorts, I've added a link to a
    similar message.

    http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-
    8&threadm=85LT7hUkDHA.1928%
    40cpmsftngxa06.phx.gbl&rnum=2&prev=/groups%3Fq%3Ddotnet%
    2Bhow%2Bto%2Bget%2BCOM%2Bports%26hl%3Den%26lr%3D%26ie%
    3DUTF-8%26oe%3DUTF-8%26selm%3D85LT7hUkDHA.1928%
    2540cpmsftngxa06.phx.gbl%26rnum%3D2

    Hope this helps.

    >-----Original Message-----
    >Hi,
    >
    >I'm trying to get a list of COM ports on my machine using

    the API
    >GetDefaultCommConfig.
    >
    >I've found an example in VB of how to do this but wanted

    to C# it up.
    >
    >This works fine but is very slow in C#
    >
    >In VB it searches for 16 COM Ports in less than a second.
    >
    >In C# it searches for 10 COM Ports in about 3 seconds.
    >
    >Why the difference in speed?
    >
    >I did note in the Output window that the VB does the

    following once
    >
    >'WindowsApplication2.exe': Loaded
    >'c:\winnt\assembly\gac\microsoft.visualbasic\7.0.5000.0__b

    03f5f7f11d50a3a\mi
    >crosoft.visualbasic.dll', No symbols loaded.
    >
    >In C# I get the following in the Output window for each

    iteration
    >
    >'MyApp.exe': Loaded 'C:\WINNT\system32\cfgmgr32.dll', No

    symbols loaded.
    >'MyApp.exe': Unloaded 'C:\WINNT\system32\cfgmgr32.dll'
    >
    >plus several
    >'MyApp.exe': Loaded 'C:\WINNT\system32\serialui.dll', No

    symbols loaded.
    >'MyApp.exe': Unloaded 'C:\WINNT\system32\serialui.dll'
    >
    >I'm assuming the extra time being taken is in the loading

    and unloading of
    >the libraries many many times.
    >
    >How can I speed this up? (Seems a bit daft to have to

    create a whole VB
    >DLL just for one function call.
    >
    >Any ideas?
    >
    >Rollasoc
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >.
    >
     
    BuddyWork, Feb 19, 2004
    #2
    1. Advertisements

  3. rollasoc

    rollasoc Guest

    Cheers I'll check it out.

    I did try using the System.Management namespace functions, but that could
    only see physical COM ports on the machine and none of the USB To Serial
    type COM Ports. GetDefaultCommConfig appears to give me these.

    Rollasoc

    "BuddyWork" <> wrote in message
    news:1264701c3f6e3$a4abd6c0$...
    > If you just want a list of COM ports on your machine then
    > use the Windows API EnumPorts, I've added a link to a
    > similar message.
    >
    > http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-
    > 8&threadm=85LT7hUkDHA.1928%
    > 40cpmsftngxa06.phx.gbl&rnum=2&prev=/groups%3Fq%3Ddotnet%
    > 2Bhow%2Bto%2Bget%2BCOM%2Bports%26hl%3Den%26lr%3D%26ie%
    > 3DUTF-8%26oe%3DUTF-8%26selm%3D85LT7hUkDHA.1928%
    > 2540cpmsftngxa06.phx.gbl%26rnum%3D2
    >
    > Hope this helps.
    >
    > >-----Original Message-----
    > >Hi,
    > >
    > >I'm trying to get a list of COM ports on my machine using

    > the API
    > >GetDefaultCommConfig.
    > >
    > >I've found an example in VB of how to do this but wanted

    > to C# it up.
    > >
    > >This works fine but is very slow in C#
    > >
    > >In VB it searches for 16 COM Ports in less than a second.
    > >
    > >In C# it searches for 10 COM Ports in about 3 seconds.
    > >
    > >Why the difference in speed?
    > >
    > >I did note in the Output window that the VB does the

    > following once
    > >
    > >'WindowsApplication2.exe': Loaded
    > >'c:\winnt\assembly\gac\microsoft.visualbasic\7.0.5000.0__b

    > 03f5f7f11d50a3a\mi
    > >crosoft.visualbasic.dll', No symbols loaded.
    > >
    > >In C# I get the following in the Output window for each

    > iteration
    > >
    > >'MyApp.exe': Loaded 'C:\WINNT\system32\cfgmgr32.dll', No

    > symbols loaded.
    > >'MyApp.exe': Unloaded 'C:\WINNT\system32\cfgmgr32.dll'
    > >
    > >plus several
    > >'MyApp.exe': Loaded 'C:\WINNT\system32\serialui.dll', No

    > symbols loaded.
    > >'MyApp.exe': Unloaded 'C:\WINNT\system32\serialui.dll'
    > >
    > >I'm assuming the extra time being taken is in the loading

    > and unloading of
    > >the libraries many many times.
    > >
    > >How can I speed this up? (Seems a bit daft to have to

    > create a whole VB
    > >DLL just for one function call.
    > >
    > >Any ideas?
    > >
    > >Rollasoc
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >.
    > >
     
    rollasoc, Feb 19, 2004
    #3
  4. rollasoc

    rollasoc Guest

    http://tinyurl.com/2u8kw

    for an easier link


    "BuddyWork" <> wrote in message
    news:1264701c3f6e3$a4abd6c0$...
    > If you just want a list of COM ports on your machine then
    > use the Windows API EnumPorts, I've added a link to a
    > similar message.
    >
    > http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-
    > 8&threadm=85LT7hUkDHA.1928%
    > 40cpmsftngxa06.phx.gbl&rnum=2&prev=/groups%3Fq%3Ddotnet%
    > 2Bhow%2Bto%2Bget%2BCOM%2Bports%26hl%3Den%26lr%3D%26ie%
    > 3DUTF-8%26oe%3DUTF-8%26selm%3D85LT7hUkDHA.1928%
    > 2540cpmsftngxa06.phx.gbl%26rnum%3D2
    >
    > Hope this helps.
    >
    > >-----Original Message-----
    > >Hi,
    > >
    > >I'm trying to get a list of COM ports on my machine using

    > the API
    > >GetDefaultCommConfig.
    > >
    > >I've found an example in VB of how to do this but wanted

    > to C# it up.
    > >
    > >This works fine but is very slow in C#
    > >
    > >In VB it searches for 16 COM Ports in less than a second.
    > >
    > >In C# it searches for 10 COM Ports in about 3 seconds.
    > >
    > >Why the difference in speed?
    > >
    > >I did note in the Output window that the VB does the

    > following once
    > >
    > >'WindowsApplication2.exe': Loaded
    > >'c:\winnt\assembly\gac\microsoft.visualbasic\7.0.5000.0__b

    > 03f5f7f11d50a3a\mi
    > >crosoft.visualbasic.dll', No symbols loaded.
    > >
    > >In C# I get the following in the Output window for each

    > iteration
    > >
    > >'MyApp.exe': Loaded 'C:\WINNT\system32\cfgmgr32.dll', No

    > symbols loaded.
    > >'MyApp.exe': Unloaded 'C:\WINNT\system32\cfgmgr32.dll'
    > >
    > >plus several
    > >'MyApp.exe': Loaded 'C:\WINNT\system32\serialui.dll', No

    > symbols loaded.
    > >'MyApp.exe': Unloaded 'C:\WINNT\system32\serialui.dll'
    > >
    > >I'm assuming the extra time being taken is in the loading

    > and unloading of
    > >the libraries many many times.
    > >
    > >How can I speed this up? (Seems a bit daft to have to

    > create a whole VB
    > >DLL just for one function call.
    > >
    > >Any ideas?
    > >
    > >Rollasoc
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >.
    > >
     
    rollasoc, Feb 19, 2004
    #4
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page