Upgrading VB6 API to VB.NET API calls

S

Shayne H

I have a VB6 UDT used in an API call as follows:

Type RASCONN
hRasConn As Long
sEntryName As String
sDeviceType As String
sDeviceName As String
sPhonebook As String
lngSubEntry As Long
guidEntry(15) As Byte
End Type

So converting to VB.NET structure:

Structure RASCONN
Public hRasConn As Integer
Public sEntryName As String
Public sDeviceType As String
Public sDeviceName As String
Public sPhonebook As String
Public lngSubEntry As Integer
Public guidEntry(15) As Byte **
End Stucture

** The last field, guidEntry(15) cannot be used in a VB.NET structure
because structure members cannot be declared with an intitial size.
What is the best way to work around this in VB.NET?
Any links to guidelines on making API calls from VB.NET would be greatly
appreciated.
I have looked for references on the web, but all of them were at a basic
level.
 
J

Jay B. Harlow [MVP - Outlook]

Shayne,
guidEntry(15) As Byte
Is guidEntry as GUID?

If it is, I would use System.Guid instead of an array of bytes.
What is the best way to work around this in VB.NET?
Alternatively there is a way to use MarshalAs attribute to indicate that
guidEntry is to be marshaled as a 16 byte array. See
System.Runtime.InteropServices.MarshalAsAttribute, I don't have a sample
immediately available.
Any links to guidelines on making API calls from VB.NET would be greatly
appreciated.

I've been using Adam Nathan's book ".NET and COM - The Complete
Interoperability Guide" from SAMS press. Very complete (too complete?) :)

Also you can ask 'down the hall' in the
microsoft.public.dotnet.framework.interop newsgroups for help on API calls.

Hope this helps
Jay
 
T

Tom Shelton

I have a VB6 UDT used in an API call as follows:

Type RASCONN
hRasConn As Long
sEntryName As String
sDeviceType As String
sDeviceName As String
sPhonebook As String
lngSubEntry As Long
guidEntry(15) As Byte
End Type

So converting to VB.NET structure:

Should look something like the following - of course you'll want to
define the contants:

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
Structure RASCONN
Public hRasConn As IntPtr

<MarshalAs(UnmanagedType.LPTStr, SizeConst:=RAS_MaxEntryName)> _
Public sEntryName As String

<MarshalAs(UnmanagedType.LPTStr, SizeConst:=RAS_MaxDeviceType)> _
Public sDeviceType As String

<MarshalAs(UnmanagedType.LPTStr, SizeConst:=RAS_MaxDeviceName)> _
Public sDeviceName As String

<MarshalAs(UnmanagedType.LPTStr, SizeConst:=MAX_PATH)> _
Public sPhonebook As String

Public lngSubEntry As Integer

Public guidEntry As System.Guid
End Stucture

Now, if those string fields are filled in by the API calls - then you
might want to replace the string types with System.Text.StringBuilder.
Anyway, this is the declare I would try off the top of my head.

Tom Shelton
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top