Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / October 2007

Tip: Looking for answers? Try searching our database.

Migrating VB6 to VB.NET - converting type to structure

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John - 23 Oct 2007 17:41 GMT
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
Tom Shelton - 23 Oct 2007 18:00 GMT
> 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
[quoted text clipped - 3 lines]
> 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:
>
[quoted text clipped - 21 lines]
>     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

--
Tom Shelton
John - 23 Oct 2007 18:34 GMT
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.

> > 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
[quoted text clipped - 77 lines]
> --
> Tom Shelton
Tom Shelton - 23 Oct 2007 20:19 GMT
> 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
[quoted text clipped - 4 lines]
>
> 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?

--
Tom Shelton
zacks@construction-imaging.com - 23 Oct 2007 18:33 GMT
> 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
[quoted text clipped - 33 lines]
> 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.
John - 23 Oct 2007 18:47 GMT
Zacks thanks for the suggestion I will give that a try.

> > 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
[quoted text clipped - 36 lines]
> I would personally do this by defining a class with the same structure
> as the Type, and then instaniating an object of the class.
John - 23 Oct 2007 19:48 GMT
That didn't work either.

> Zacks thanks for the suggestion I will give that a try.
>
[quoted text clipped - 38 lines]
> > I would personally do this by defining a class with the same structure
> > as the Type, and then instaniating an object of the class.
zacks@construction-imaging.com - 23 Oct 2007 19:48 GMT
> Zacks thanks for the suggestion I will give that a try.
>
[quoted text clipped - 39 lines]
> > I would personally do this by defining a class with the same structure
> > as the Type, and then instaniating an object of the class.

If you do a search on "Structure vs Class" in this newsgroup, you'll
find that there has been numerous threads on the subject.
John - 23 Oct 2007 20:11 GMT
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.

> > Zacks thanks for the suggestion I will give that a try.
> >
[quoted text clipped - 42 lines]
> If you do a search on "Structure vs Class" in this newsgroup, you'll
> find that there has been numerous threads on the subject.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.