473,387 Members | 1,791 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,387 software developers and data experts.

AddPortEx Trouble

Trying to use AddPortEx but I'm getting an error. I modified the code I
found that Randy Birch did for VB6.
Public Structure PORT_INFO_1
Dim pPortName As String
End Structure

Public Declare Function AddPortEx Lib "winspool.drv" Alias "AddPortExA"
(ByVal pName As String, ByVal pLevel As Integer, ByVal lpBuffer As Object,
ByVal pMonitorName As String) As Integer

Dim PortInfo1 As PORT_INFO_1
PortInfo1.pPortName = FilePath
Dim x As Integer = AddPortEx(Nothing, 1, PortInfo1, "Local Port")
<--Exception thrown here

The error i'm getting is "Value does not fall within the expected range"

Looking for help getting this to work.

Thanks.
Feb 24 '07 #1
1 1898
On 2007-02-24, Terry Olsen <to******@hotmail.comwrote:
Trying to use AddPortEx but I'm getting an error. I modified the code I
found that Randy Birch did for VB6.
Public Structure PORT_INFO_1
Dim pPortName As String
End Structure

Public Declare Function AddPortEx Lib "winspool.drv" Alias "AddPortExA"
(ByVal pName As String, ByVal pLevel As Integer, ByVal lpBuffer As Object,
ByVal pMonitorName As String) As Integer

Dim PortInfo1 As PORT_INFO_1
PortInfo1.pPortName = FilePath
Dim x As Integer = AddPortEx(Nothing, 1, PortInfo1, "Local Port")
<--Exception thrown here

The error i'm getting is "Value does not fall within the expected range"

Looking for help getting this to work.

Thanks.

I can't find any information on AddPortEx. The closest I can find is a
definition for AddPortEx that looks different from the above declare, and was
made obolete with NT4. That funciton looks like:

Public Auto Function AddPortEx Lib "winspool.drv" ( _
ByVal hMonitor As IntPtr,
ByVal pName As String, _
ByVal Level As Integer, _
ByRef lpBuffer As PORT_INFO_1, _
ByVal lpMonitorName As String) As Boolean
So, my advice to you... Declare the function Auto and loose the alias. That
isn't needed in VB.NET for A/W functions.

You should declare the PORT_INFO_1 function like:

<StructLayout (StructLayout := LayoutKind.Sequential, CharSet:=CharSet.Auto)_
Public Structure PORT_INFO_1
Public pPortName As String
End Structure

Anyway, calling it:

If AddPortEx (IntPtr.Zero, Nothing, 1, PortInfo1, "Local Port") Then
'Do cool stuff
Else
' don't do cool stuff
End If

HTH,

--
Tom Shelton
Feb 24 '07 #2

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

Similar topics

1
by: Jim Bancroft | last post by:
Hi everyone, I'm running into a problem with my ASP.Net application. I've just created a new aspx page which uses some new components of mine that inherit from ServicedComponent and are...
6
by: Daniel Walzenbach | last post by:
Hi, I have a web application which sometimes throws an “out of memory” exception. To get an idea what happens I traced some values using performance monitor and got the following values (for...
2
by: JLupear | last post by:
I am having trouble with my code again, I had prepared a question and the code to upload, however I am having trouble posting it, are there limits to the amount of lines you can post? I split it...
0
by: mrchatgroup | last post by:
news from http://www.mrchat.net/myblog/myblog/small-accidents-mean-big-trouble-for-supercollider.html Small Accidents Mean Big Trouble for Supercollider Image Scientists expect startup...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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.