Migrating VB6 to VB.NET - converting type to structure

G

Guest

I have a VB6 project that I have been converting to .NET. I have most of it
working, but I am having trouble with one of the Functions and a stucture
that is being passed to it.

Here's the VB6 function:
Declare Function KGI_NextElement Lib "wkgi32.dll" (ByVal hSession As Long,
ByVal wFlags As Integer, pElmHdr As KGI_ELEMENT) As Integer

Here's the VB6 Type:

Type KGI_ELEMENT
elm_flags As Long 'Flags
elm_PageNumber As Long 'Page Number
elm_xPos As Long 'X position
elm_yPos As Long 'Y Position
elm_Width As Long 'Width
elm_Depth As Long 'Depth
elm_xRes As Long 'X Resolution
elm_yRes As Long 'Y Resolution
elm_Rotation As Long 'Rotation
elm_Offset As Long 'Offset
elm_Length As Long 'Length
elm_TypeMask As Integer 'Mask for Element Type
'-----------------------------------------------------------
'New fields in 32-bit
elm_Title As String * TITLE_SIZE 'Document Title
elm_Person As String * PERSON_SIZE 'Person
elm_Date As String * DATE_SIZE 'Creation Date
elm_Time As String * TIME_SIZE 'Creation Time
elm_Type As String * DATATYPE_SIZE 'Type
elm_Icon As String * ICON_SIZE 'Icon Name
elm_Description As String * DESCRIPT_SIZE 'Element description
End Type ' End of KGI_ELEMENT structure

Any help or suggestions on the proper way to convert this would be greatly
appreciated. I have tried several interations and can't seem to get it to
work.

Thanks,

John
 
T

Tom Shelton

I have a VB6 project that I have been converting to .NET. I have most of it
working, but I am having trouble with one of the Functions and a stucture
that is being passed to it.

Here's the VB6 function:
Declare Function KGI_NextElement Lib "wkgi32.dll" (ByVal hSession As Long,
ByVal wFlags As Integer, pElmHdr As KGI_ELEMENT) As Integer

' Assuming that the string elements are ansi strings?
Declare Ansi Function KGI_NextElement Lib "wkgi32.dll" _
(ByVal hSession As IntPtr, _
ByVal wFlags As Short, _
ByRef pElmHdr As KGI_ELEMENT) As Short
Here's the VB6 Type:

Type KGI_ELEMENT
elm_flags As Long 'Flags
elm_PageNumber As Long 'Page Number
elm_xPos As Long 'X position
elm_yPos As Long 'Y Position
elm_Width As Long 'Width
elm_Depth As Long 'Depth
elm_xRes As Long 'X Resolution
elm_yRes As Long 'Y Resolution
elm_Rotation As Long 'Rotation
elm_Offset As Long 'Offset
elm_Length As Long 'Length
elm_TypeMask As Integer 'Mask for Element Type
'-----------------------------------------------------------
'New fields in 32-bit
elm_Title As String * TITLE_SIZE 'Document Title
elm_Person As String * PERSON_SIZE 'Person
elm_Date As String * DATE_SIZE 'Creation Date
elm_Time As String * TIME_SIZE 'Creation Time
elm_Type As String * DATATYPE_SIZE 'Type
elm_Icon As String * ICON_SIZE 'Icon Name
elm_Description As String * DESCRIPT_SIZE 'Element description
End Type ' End of KGI_ELEMENT structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
Structure KGI_ELEMENT
elm_flags As Integer 'Flags
elm_PageNumber As Integer 'Page Number
elm_xPos As Integer 'X position
elm_yPos As Integer 'Y Position
elm_Width As Integer 'Width
elm_Depth As Integer 'Depth
elm_xRes As Integer 'X Resolution
elm_yRes As Integer 'Y Resolution
elm_Rotation As Integer 'Rotation
elm_Offset As Integer 'Offset
elm_Length As Integer 'Length
elm_TypeMask As Short 'Mask for Element Type
'-----------------------------------------------------------
'New fields in 32-bit
<MarshalAs(UnmanageType.ByValTStr, SizeConst:=TITLE_SIZE)> _
elm_Title As String 'Document Title

<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=PERSON_SIZE)>_
elm_Person As String 'Person

<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DATE_SIZE)>_
elm_Date As String 'Creation Date

<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=TIME_SIZE)>_
elm_Time As String 'Creation Time

<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DATATYPE_SIZE)>_
elm_Type As String 'Type

<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=ICON_SIZE)>_
elm_Icon As String 'Icon Name

<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=DESCRIPT_SIZE )>_
elm_Description As String 'Element description

End Structure ' End of KGI_ELEMENT structure
 
Z

zacks

I have a VB6 project that I have been converting to .NET. I have most of it
working, but I am having trouble with one of the Functions and a stucture
that is being passed to it.

Here's the VB6 function:
Declare Function KGI_NextElement Lib "wkgi32.dll" (ByVal hSession As Long,
ByVal wFlags As Integer, pElmHdr As KGI_ELEMENT) As Integer

Here's the VB6 Type:

Type KGI_ELEMENT
elm_flags As Long 'Flags
elm_PageNumber As Long 'Page Number
elm_xPos As Long 'X position
elm_yPos As Long 'Y Position
elm_Width As Long 'Width
elm_Depth As Long 'Depth
elm_xRes As Long 'X Resolution
elm_yRes As Long 'Y Resolution
elm_Rotation As Long 'Rotation
elm_Offset As Long 'Offset
elm_Length As Long 'Length
elm_TypeMask As Integer 'Mask for Element Type
'-----------------------------------------------------------
'New fields in 32-bit
elm_Title As String * TITLE_SIZE 'Document Title
elm_Person As String * PERSON_SIZE 'Person
elm_Date As String * DATE_SIZE 'Creation Date
elm_Time As String * TIME_SIZE 'Creation Time
elm_Type As String * DATATYPE_SIZE 'Type
elm_Icon As String * ICON_SIZE 'Icon Name
elm_Description As String * DESCRIPT_SIZE 'Element description
End Type ' End of KGI_ELEMENT structure

Any help or suggestions on the proper way to convert this would be greatly
appreciated. I have tried several interations and can't seem to get it to
work.

I would personally do this by defining a class with the same structure
as the Type, and then instaniating an object of the class.
 
G

Guest

Thanks Tom for replying so quickly. Unfortunately that didn't work. When I
call the KGI_NextElement it supposed to put data into the pElmHeader, which
it does but the data is off. For example I know elm_Type should return the
value "TIFF", which it does correct with VB6. In .NET it returns "FF", also
most of the other value in structure are empty when they would normal have
values.

Thanks again for the help.
 
Z

zacks

Zacks thanks for the suggestion I will give that a try.

If you do a search on "Structure vs Class" in this newsgroup, you'll
find that there has been numerous threads on the subject.
 
G

Guest

Not sure why yet but I received a FatalExecutionEngineError

FatalExecutionEngineError was detected
Message: The runtime has encountered a fatal error. The address of the error
was at 0x79e774e3, on thread 0xcb4. The error code is 0xc0000005. This error
may be a bug in the CLR or in the unsafe or non-verifiable portions of user
code. Common sources of this bug include user marshaling errors for
COM-interop or PInvoke, which may corrupt the stack.
 
T

Tom Shelton

Thanks Tom for replying so quickly. Unfortunately that didn't work. When I
call the KGI_NextElement it supposed to put data into the pElmHeader, which
it does but the data is off. For example I know elm_Type should return the
value "TIFF", which it does correct with VB6. In .NET it returns "FF", also
most of the other value in structure are empty when they would normal have
values.

Thanks again for the help.

Hmmm... Sounds like an alignment issue. I converted this off of the
VB6 declaration. You wouldn't happen to have a C declaration for this
structure would you?
 
A

alex castillo

Hi, i see that you were working on cnoverting some keyfile program from VB6 to .NET.
I'm doing some work now on creating an application in .NET that connects to the keyfile and i really don't know how to do it, can you help me?
I found the libraries but i cannot import them to my project neither, can you help me?
 

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