GetDefaultCommConfig VB v C#

  • Thread starter Thread starter rollasoc
  • Start date Start date
R

rollasoc

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
 
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.
 
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
 
http://tinyurl.com/2u8kw

for an easier link


BuddyWork said:
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.
 
Back
Top