473,386 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

I need clarification on how to use EnumPorts

Ken
Hello Everyone,

I would like to use EnumPorts twice on my form. The first
time I want to use Port_Info_1 to just list the Port
Names. The second instance where I need EnumPorts , is
when I receive the Combo.SelectedIndexChanged event. I
want to use EnumPorts to get the Port_Info_2 based on the
Port Name. I have it working for Port_Info_1, however I am
having a problem understanding what I should send to
EnumPorts(,,,,). How do I find the info for just that
port? and how do I avoid getting errors when that port is
listed, but it has no info?

Thank You in Advance for Your Help,
Ken
Nov 15 '05 #1
1 3579

Hi Ken,

You can call the EnumPorts API to get the PORT_INFO_1 in .Net like this:

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
struct PORT_INFO_1
{
[MarshalAs(UnmanagedType.LPTStr)]
public string pName;
}

[DllImport("winspool.drv", CharSet=CharSet.Auto)]
static extern bool EnumPorts(string pName, int level, IntPtr bufptr,int
cbBuf, out int pcbNeeded, out int pcReturned);

int pcReturned = 0;
int pcbNeeded = 0;
IntPtr outb = IntPtr.Zero;

EnumPorts(null, 1, outb, 0, out pcbNeeded, out pcReturned);
outb = Marshal.AllocHGlobal(pcbNeeded+1);
EnumPorts(null, 1, outb, pcbNeeded, out pcbNeeded, out pcReturned);
PORT_INFO_1[] manyArr = new PORT_INFO_1[pcReturned];

IntPtr current = outb;
for (int i=0; i<pcReturned; i++)
{
manyArr[i] = (PORT_INFO_1) Marshal.PtrToStructure(current,
typeof(PORT_INFO_1));
current=(IntPtr)((int)current+Marshal.SizeOf(typeo f(PORT_INFO_1)));
}
Marshal.FreeHGlobal(outb);

You can use the same logic to get the PORT_INFO_2, then you can get the
information of certian port like by comparing the port name.

Hope this helps,

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| Content-Class: urn:content-classes:message
| From: "Ken" <kk*****@mindspring.com>
| Sender: "Ken" <kk*****@mindspring.com>
| Subject: I need clarification on how to use EnumPorts
| Date: Thu, 9 Oct 2003 09:49:08 -0700
| Lines: 17
| Message-ID: <2c****************************@phx.gbl>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Thread-Index: AcOOhUG67BaNny/kTfiSMBBrSlaccQ==
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Newsgroups: microsoft.public.dotnet.languages.csharp
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:190304
| NNTP-Posting-Host: TK2MSFTNGXA06 10.40.1.53
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Hello Everyone,
|
| I would like to use EnumPorts twice on my form. The first
| time I want to use Port_Info_1 to just list the Port
| Names. The second instance where I need EnumPorts , is
| when I receive the Combo.SelectedIndexChanged event. I
| want to use EnumPorts to get the Port_Info_2 based on the
| Port Name. I have it working for Port_Info_1, however I am
| having a problem understanding what I should send to
| EnumPorts(,,,,). How do I find the info for just that
| port? and how do I avoid getting errors when that port is
| listed, but it has no info?
|
| Thank You in Advance for Your Help,
| Ken
|
|
|

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jimmy Johns | last post by:
Hi all, I have some class hierarchy as follows: class S {}; class A {}; class B {public: vector<S*> v_; virtual ~B();}; class C : public virtual A, public virtual B { // do I need to define...
3
by: John D. Sanders | last post by:
I have just upgraded MySQL from version 3.23 to version 4.1.8 and now I am getting the following error when I try to run a script that worked: install_driver(mysql) failed: Can't load...
70
by: rahul8143 | last post by:
hello, 1) First how following program get executed i mean how output is printed and also why following program gives different output in Turbo C++ compiler and Visual c++ 6 compiler? void main()...
8
by: Sai Kit Tong | last post by:
In the article, the description for "Modiy DLL That Contains Consumers That Use Managed Code and DLL Exports or Managed Entry Points" suggests the creation of the class ManagedWrapper. If I...
7
by: raulavi | last post by:
on a msg on 2/20/05 8:16 am pst you state (talking about arguments) >>Depending on the application, certain parameter values need to be put between double quotes, for example, file names containing...
17
by: Alan Silver | last post by:
Hello, I have a generic method in a utility class that grabs an sqldatareader and returns it. Due to the fact that (AFAIK), you can't close the database connection before you've read the data,...
9
by: wizwx | last post by:
what does the following mean? int func2(); According to C++, it surely means func2 is a function that takes no argument and returns an integer. But what about in C? Does it have the same...
3
by: a | last post by:
Hi, I need clarification for virtual method and pure virtual method. e.g Class Base{ virtual void func(){ ---- } } Class Child : public Base{ void func()
2
by: ravir | last post by:
Hi, I am new to this group. I am working in Perl and shellscripts. I have a clarification regarding perl grep and pattern matching. I am writing a perl script to automate the process of code...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.