473,470 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 1900
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: 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
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.