Link to home
Start Free TrialLog in
Avatar of twu027
twu027

asked on

vb6 to vb.net

I got the upgrade warning when I convert from vb6 to vb.net. it is like this:

Structure GUID may require marshalling attributes to be passed as an argument in this Declare statement

my code is as the following:

can someone help plz? The problem came from the API calls.

how should I change the vb.net code?


Private Structure GUID
        Dim Data1 As Integer
        Dim Data2 As Short
        Dim Data3 As Short
        <VBFixedArray(7)> Dim Data4() As Byte
 
        'UPGRADE_TODO: "Initialize" must be called to initialize instances of this structure. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="B4BFF9E0-8631-45CF-910E-62AB3970F27B"'
        Public Sub Initialize()
            ReDim Data4(7)
        End Sub
    End Structure
 
    'UPGRADE_WARNING: Structure GUID may require marshalling attributes to be passed as an argument in this Declare statement. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="C429C3A5-5D47-4CD9-8F51-74A1616405DC"'
    Private Declare Function CoCreateGuid Lib "OLE32.DLL" (ByRef pGuid As GUID) As Integer
 
    Public Function GetGUID() As String
        '(c) 2000 Gus Molina
 
        'UPGRADE_WARNING: Arrays in structure udtGUID may need to be initialized before they can be used. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="814DF224-76BD-4BB4-BFFB-EA359CB9FC48"'
        Dim udtGUID As GUID
 
        If (CoCreateGuid(udtGUID) = 0) Then
 
            GetGUID = New String("0", 8 - Len(Hex(udtGUID.Data1))) & Hex(udtGUID.Data1) & New String("0", 4 - Len(Hex(udtGUID.Data2))) & Hex(udtGUID.Data2) & New String("0", 4 - Len(Hex(udtGUID.Data3))) & Hex(udtGUID.Data3) & IIf((udtGUID.Data4(0) < &H10S), "0", "") & Hex(udtGUID.Data4(0)) & IIf((udtGUID.Data4(1) < &H10S), "0", "") & Hex(udtGUID.Data4(1)) & IIf((udtGUID.Data4(2) < &H10S), "0", "") & Hex(udtGUID.Data4(2)) & IIf((udtGUID.Data4(3) < &H10S), "0", "") & Hex(udtGUID.Data4(3)) & IIf((udtGUID.Data4(4) < &H10S), "0", "") & Hex(udtGUID.Data4(4)) & IIf((udtGUID.Data4(5) < &H10S), "0", "") & Hex(udtGUID.Data4(5)) & IIf((udtGUID.Data4(6) < &H10S), "0", "") & Hex(udtGUID.Data4(6)) & IIf((udtGUID.Data4(7) < &H10S), "0", "") & Hex(udtGUID.Data4(7))
        End If
 
    End Function

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of ZachSmith
ZachSmith
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of twu027
twu027

ASKER

I am having problems with it in the run time. the exception is like memory corrupt problem
Avatar of twu027

ASKER

the error message is like this:
{"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

and I believe it is caused by the code above