PC Review


Reply
Thread Tools Rate Thread

AddPortEx Trouble

 
 
Terry Olsen
Guest
Posts: n/a
 
      24th Feb 2007
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.


 
Reply With Quote
 
 
 
 
Tom Shelton
Guest
Posts: n/a
 
      24th Feb 2007
On 2007-02-24, Terry Olsen <(E-Mail Removed)> wrote:
> 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
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble with wireless connection. Would appreciate suggestions on where to trouble shoot or where to look for problems. Ronald DIY PC 2 24th Sep 2007 11:54 AM
SP2 Trouble Jason Brewster Windows XP Performance 3 21st Sep 2004 06:07 PM
Log on trouble Tracey Windows XP Performance 1 11th Sep 2004 01:59 PM
trouble with ie hans Windows XP Internet Explorer 1 7th Sep 2004 04:03 PM
Trouble with Admin rights and thus trouble installing/updating programs =?Utf-8?B?aGtydWc2NA==?= Windows XP General 0 18th Jan 2004 06:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:03 AM.