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

Converting VB6 Structures to .NET

In VB6, the code for a structure is

Structure zFuheader
Dim Id1(80) As Byte
Dim Id2(80) As Byte
End Structure

However, in .NET, it doesn't let you declare the array size in the
structure.

I am trying to use an old external .dll that worked with the VB6 structure
syntax but doesn't appear to be working when I try and do it in .NET.

The problem in a little more detail:

I am using a number of "Declare Function" statments to access the functions
in the .dll. I am getting an error when I try to pass the structure to one
of the functions in the .dll. (Header Pointer is Null or somthing like that).

Module MainMod

Declare Function initFuHeader Lib "mtsadfconv.dll" Alias
"_initFuHeader_VB@4" _ (ByVal zHeader As zFuheader) As Integer

Public Structure zFuheader
Dim Id1() As Byte 'in VB6 declared to size 80
Dim Id2() As Byte 'in VB6 declared to size 80
End Structure

Public Sub Main()
Dim zHead As zFuheader
Dim result As Integer

result = initFuHeader(zHead) '<-- This returns a "result" that Header
Pointer is Null

End Sub

End Module

So I'm wondering if the error is because the structure doesn't declare a
size for the arrays??? If so, does anyone know a work around?

John
Aug 23 '06 #1
5 2106
I wonder if this will work:

Dim zHead As zFuheader

redim zHead.Id1(79)

Just a thought.
Steve

"redeagle" <re******@discussions.microsoft.comwrote in message
news:7F**********************************@microsof t.com...
In VB6, the code for a structure is

Structure zFuheader
Dim Id1(80) As Byte
Dim Id2(80) As Byte
End Structure

However, in .NET, it doesn't let you declare the array size in the
structure.

I am trying to use an old external .dll that worked with the VB6 structure
syntax but doesn't appear to be working when I try and do it in .NET.

The problem in a little more detail:

I am using a number of "Declare Function" statments to access the
functions
in the .dll. I am getting an error when I try to pass the structure to
one
of the functions in the .dll. (Header Pointer is Null or somthing like
that).
>
Module MainMod

Declare Function initFuHeader Lib "mtsadfconv.dll" Alias
"_initFuHeader_VB@4" _ (ByVal zHeader As zFuheader) As Integer

Public Structure zFuheader
Dim Id1() As Byte 'in VB6 declared to size 80
Dim Id2() As Byte 'in VB6 declared to size 80
End Structure

Public Sub Main()
Dim zHead As zFuheader
Dim result As Integer

result = initFuHeader(zHead) '<-- This returns a "result" that
Header
Pointer is Null

End Sub

End Module

So I'm wondering if the error is because the structure doesn't declare a
size for the arrays??? If so, does anyone know a work around?

John

Aug 23 '06 #2
Hi Steve-

Thanks for the reply. Unfortunatly it does not. Although in the interest
of complete disclosure, the actual structure I am trying to pass (zFuheader)
references another structure that also has an array.

Structure zChType
Dim Ref() As Byte '8
Dim Res() As Byte '8
End Structure

Structure zFuheader
Dim Id1() As Byte '20
Dim Id2() As Byte '20
Dim ch() As zChType
End Structure

"Steve Long" wrote:
I wonder if this will work:

Dim zHead As zFuheader

redim zHead.Id1(79)

Just a thought.
Steve

"redeagle" <re******@discussions.microsoft.comwrote in message
news:7F**********************************@microsof t.com...
In VB6, the code for a structure is

Structure zFuheader
Dim Id1(80) As Byte
Dim Id2(80) As Byte
End Structure

However, in .NET, it doesn't let you declare the array size in the
structure.

I am trying to use an old external .dll that worked with the VB6 structure
syntax but doesn't appear to be working when I try and do it in .NET.

The problem in a little more detail:

I am using a number of "Declare Function" statments to access the
functions
in the .dll. I am getting an error when I try to pass the structure to
one
of the functions in the .dll. (Header Pointer is Null or somthing like
that).

Module MainMod

Declare Function initFuHeader Lib "mtsadfconv.dll" Alias
"_initFuHeader_VB@4" _ (ByVal zHeader As zFuheader) As Integer

Public Structure zFuheader
Dim Id1() As Byte 'in VB6 declared to size 80
Dim Id2() As Byte 'in VB6 declared to size 80
End Structure

Public Sub Main()
Dim zHead As zFuheader
Dim result As Integer

result = initFuHeader(zHead) '<-- This returns a "result" that
Header
Pointer is Null

End Sub

End Module

So I'm wondering if the error is because the structure doesn't declare a
size for the arrays??? If so, does anyone know a work around?

John


Aug 23 '06 #3

redeagle wrote:
In VB6, the code for a structure is

Structure zFuheader
Dim Id1(80) As Byte
Dim Id2(80) As Byte
End Structure

However, in .NET, it doesn't let you declare the array size in the
structure.

I am trying to use an old external .dll that worked with the VB6 structure
syntax but doesn't appear to be working when I try and do it in .NET.

The problem in a little more detail:

I am using a number of "Declare Function" statments to access the functions
in the .dll. I am getting an error when I try to pass the structure to one
of the functions in the .dll. (Header Pointer is Null or somthing like that).

Module MainMod

Declare Function initFuHeader Lib "mtsadfconv.dll" Alias
"_initFuHeader_VB@4" _ (ByVal zHeader As zFuheader) As Integer

Public Structure zFuheader
Dim Id1() As Byte 'in VB6 declared to size 80
Dim Id2() As Byte 'in VB6 declared to size 80
End Structure

Public Sub Main()
Dim zHead As zFuheader
Dim result As Integer

result = initFuHeader(zHead) '<-- This returns a "result" that Header
Pointer is Null

End Sub

End Module

So I'm wondering if the error is because the structure doesn't declare a
size for the arrays??? If so, does anyone know a work around?

John
Ok... Your dealing with interop, so things are little different. You
have to add marshalling attributes to this structure, so that the
runtime marshaller knows how to pass it to the dll call. Here is what
my first stab would be:
Declare Function initFuHeader Lib "mtsadfconv.dll" Alias _
"_initFuHeader_VB@4" _ (ByVal zHeader As zFuheader) As Integer
I have to question this declare a little bit. First question I have
to ask - is this the original VB6 or declare? Because if it is, the As
Integer should be As Short. VB.NET changed the size of the data types.
A Integer in .NET is 32-bit, not 16-bit (though, this would probably
not cause you the error your receiving - though it might give
unexpected return results). Further, is this function actually
updating this structure? Because if it is, then you should probably be
passing it ByRef rather then ByVal. That would most likely cause the
error your receiving...
>
Public Structure zFuheader
Dim Id1() As Byte 'in VB6 declared to size 80
Dim Id2() As Byte 'in VB6 declared to size 80
End Structure
I would probably declare this as:

<StructLayout (LayoutKind.Sequential)_ ' not strictly necessary
Public Structure zFuheader
<MarshalAs (UnmanagedType.ByValArray, SizeConst:=80)_
Public Id1() As Byte 'in VB6 declared to size 80

<MarshalAs (UnmanagedType.ByValArray, SizeConst:=80)_
Public Id2() As Byte 'in VB6 declared to size 80
End Structure

Anyway, give it a go, and let us know what happens :)

--
Tom Shelton

Aug 23 '06 #4
Hi Tom-

Thanks for the tips.

In VB6 the original declare was "As Long" so I changed it to "As Integer" in
..NET.
Further, is this function actually
updating this structure? Because if it is, then you should probably be
passing it ByRef rather then ByVal. That would most likely cause the
error your receiving...
I actually don't know what its doing. This dll was written by a third party
software vendor for its customers to use to interact with its proprietary
file types. The dll was written in VB6 and they released a "user guide" for
the dll. In the user guide, their example uses ByVal. Maybe it is a typo.
I will try ByRef.

I will also add the Marshalling attributes.

I'll keep let you know how it goes...

John

"Tom Shelton" wrote:
>
redeagle wrote:
In VB6, the code for a structure is

Structure zFuheader
Dim Id1(80) As Byte
Dim Id2(80) As Byte
End Structure

However, in .NET, it doesn't let you declare the array size in the
structure.

I am trying to use an old external .dll that worked with the VB6 structure
syntax but doesn't appear to be working when I try and do it in .NET.

The problem in a little more detail:

I am using a number of "Declare Function" statments to access the functions
in the .dll. I am getting an error when I try to pass the structure to one
of the functions in the .dll. (Header Pointer is Null or somthing like that).

Module MainMod

Declare Function initFuHeader Lib "mtsadfconv.dll" Alias
"_initFuHeader_VB@4" _ (ByVal zHeader As zFuheader) As Integer

Public Structure zFuheader
Dim Id1() As Byte 'in VB6 declared to size 80
Dim Id2() As Byte 'in VB6 declared to size 80
End Structure

Public Sub Main()
Dim zHead As zFuheader
Dim result As Integer

result = initFuHeader(zHead) '<-- This returns a "result" that Header
Pointer is Null

End Sub

End Module

So I'm wondering if the error is because the structure doesn't declare a
size for the arrays??? If so, does anyone know a work around?

John

Ok... Your dealing with interop, so things are little different. You
have to add marshalling attributes to this structure, so that the
runtime marshaller knows how to pass it to the dll call. Here is what
my first stab would be:
Declare Function initFuHeader Lib "mtsadfconv.dll" Alias _
"_initFuHeader_VB@4" _ (ByVal zHeader As zFuheader) As Integer

I have to question this declare a little bit. First question I have
to ask - is this the original VB6 or declare? Because if it is, the As
Integer should be As Short. VB.NET changed the size of the data types.
A Integer in .NET is 32-bit, not 16-bit (though, this would probably
not cause you the error your receiving - though it might give
unexpected return results). Further, is this function actually
updating this structure? Because if it is, then you should probably be
passing it ByRef rather then ByVal. That would most likely cause the
error your receiving...

Public Structure zFuheader
Dim Id1() As Byte 'in VB6 declared to size 80
Dim Id2() As Byte 'in VB6 declared to size 80
End Structure

I would probably declare this as:

<StructLayout (LayoutKind.Sequential)_ ' not strictly necessary
Public Structure zFuheader
<MarshalAs (UnmanagedType.ByValArray, SizeConst:=80)_
Public Id1() As Byte 'in VB6 declared to size 80

<MarshalAs (UnmanagedType.ByValArray, SizeConst:=80)_
Public Id2() As Byte 'in VB6 declared to size 80
End Structure

Anyway, give it a go, and let us know what happens :)

--
Tom Shelton

Aug 24 '06 #5
You are the MAN!

I added the Marshalling attributes and changed the "Function Declare"
statements from "ByVal" to "ByRef" (that is apparantly a typo throughout the
"user guide").

Everything seems to be working now!

Thanks again Tom (and Steve) I appreciate your time.

John

"Tom Shelton" wrote:
>
redeagle wrote:
In VB6, the code for a structure is

Structure zFuheader
Dim Id1(80) As Byte
Dim Id2(80) As Byte
End Structure

However, in .NET, it doesn't let you declare the array size in the
structure.

I am trying to use an old external .dll that worked with the VB6 structure
syntax but doesn't appear to be working when I try and do it in .NET.

The problem in a little more detail:

I am using a number of "Declare Function" statments to access the functions
in the .dll. I am getting an error when I try to pass the structure to one
of the functions in the .dll. (Header Pointer is Null or somthing like that).

Module MainMod

Declare Function initFuHeader Lib "mtsadfconv.dll" Alias
"_initFuHeader_VB@4" _ (ByVal zHeader As zFuheader) As Integer

Public Structure zFuheader
Dim Id1() As Byte 'in VB6 declared to size 80
Dim Id2() As Byte 'in VB6 declared to size 80
End Structure

Public Sub Main()
Dim zHead As zFuheader
Dim result As Integer

result = initFuHeader(zHead) '<-- This returns a "result" that Header
Pointer is Null

End Sub

End Module

So I'm wondering if the error is because the structure doesn't declare a
size for the arrays??? If so, does anyone know a work around?

John

Ok... Your dealing with interop, so things are little different. You
have to add marshalling attributes to this structure, so that the
runtime marshaller knows how to pass it to the dll call. Here is what
my first stab would be:
Declare Function initFuHeader Lib "mtsadfconv.dll" Alias _
"_initFuHeader_VB@4" _ (ByVal zHeader As zFuheader) As Integer

I have to question this declare a little bit. First question I have
to ask - is this the original VB6 or declare? Because if it is, the As
Integer should be As Short. VB.NET changed the size of the data types.
A Integer in .NET is 32-bit, not 16-bit (though, this would probably
not cause you the error your receiving - though it might give
unexpected return results). Further, is this function actually
updating this structure? Because if it is, then you should probably be
passing it ByRef rather then ByVal. That would most likely cause the
error your receiving...

Public Structure zFuheader
Dim Id1() As Byte 'in VB6 declared to size 80
Dim Id2() As Byte 'in VB6 declared to size 80
End Structure

I would probably declare this as:

<StructLayout (LayoutKind.Sequential)_ ' not strictly necessary
Public Structure zFuheader
<MarshalAs (UnmanagedType.ByValArray, SizeConst:=80)_
Public Id1() As Byte 'in VB6 declared to size 80

<MarshalAs (UnmanagedType.ByValArray, SizeConst:=80)_
Public Id2() As Byte 'in VB6 declared to size 80
End Structure

Anyway, give it a go, and let us know what happens :)

--
Tom Shelton

Aug 24 '06 #6

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

Similar topics

1
by: Gaz | last post by:
Hi all, I'm using a 3rd party Assembly that contains a method which returns bitmap data, however the Return value type is IntPtr and I need to convert it so I can access the Bitmap data: I'm...
0
by: MDB | last post by:
Hello All, I have a function in a 3rd party dll that I am trying to use however, I am unsure how to convert to C# Can anyone help or give me some pointers? Here is what the documentation states:...
5
by: Sonu | last post by:
Hello everyone and thanks in advance. I have a multilingual application which has been built in MFC VC++ 6.0 (non-Unicode). It support English German Hungarian so far, which has been fine. But...
3
by: Brian Henry | last post by:
If i have a structure type and i place the structures data into a tag property (which is an object) it will go in obviously, but when i pull an object back into a structrured type it will error.....
9
by: Hugo Amselschlag | last post by:
Hi there, I've implemented a local system hook to suppress certain windows beeing displayed by the axWebbrowser control. Now I need some more information before I can decide, whether to suppress...
0
by: Aditya Agarwal | last post by:
Hi, I was wondering if there is a C++ library to deserialize PHP data structures. I am looking to deserialize mostly simple data structures (not user-defined classes/objects) so conversion to...
13
by: ppateel | last post by:
Hi, I am new to c++ and I am converting a c program to c++. I changed malloc call to new and I am getting an exception violation. Here is the relevant piece of code. Compiler vc++ 7.0 (.Net...
3
by: fakeprogress | last post by:
How would I go about converting this C code to C++? /* LIBRARY is an array of structures */ /* This function compares 'tcode' with */ /* existing codes in the array. */ /* It...
156
by: Lame Duck | last post by:
Hi Group! I have a vector<floatvariable that I need to pass to a function, but the function takes a float * arguement. That's OK, I can convert by doing &MyVector.front(), but when I get back a...
1
by: Charming12 | last post by:
Hi All, The question is regarding Unmanaged and Managed code conversion in C# for structures. I have two structures like: public struct Detail { public int age; public string address;
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: 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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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?
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...

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.