Click here to Skip to main content
15,884,838 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have run into a interesting bit of code in vb6 that I have been trying to figure out so that I can convert it to vb.net. To what i understand the "Any" keyword refers to the data type used by the API that is used in the code but I cannot figure out the last data type as it errors with the exception "Mismatched type".

The program will load correctly if I replace pDst any with Long and pSrc as Byte and lpString with String the program will load

VB
Declare Sub ArrayDescriptor Lib "kernel32" Alias "RtlMoveMemory"(pDst As Any, pSrc() As Any, ByVal ByteLen As Long)
Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (lpString As Any) As Long
'Finding all references for ArrayDescriptor leads me to:


Dim ARD As Integer
        ArrayDescriptor(ARD, FDATA, 4)
        If ARD = 0 Then MsgBox("File isn't loaded yet!", MsgBoxStyle.Critical, "Error") : Exit Sub

        DISASM.BaseAddress = VIRTUALBASEADR + VIRTUALADR - POINTERTORAW

        Dim Forward As Byte 'Next Instruction!
        Dim CNT As Integer
        CNT = POINTERTORAW
        Dim u As Integer
        Dim DATAS() As String
        ReDim DATAS(SIZEOFRAW)



        Dim TC2 As Integer
        Dim TC As Integer

        Label1.Text = "Disassemble..."
        System.Windows.Forms.Application.DoEvents()
        TC = GetTickCount
        'DISASSEMBLE!!!
        Do
            DATAS(u) = DISASM.DisAssemble(FDATA, CNT, Forward, 1, 0) & vbCrLf
            u = u + 1
            CNT = CNT + Forward
        Loop While SIZEOFRAW + POINTERTORAW > CNT

        TC2 = GetTickCount



        Label1.Text = "Disassembled for " & TC2 - TC & " msec"
        System.Windows.Forms.Application.DoEvents()

        ReDim Preserve DATAS(u - 1)


        'UPGRADE_WARNING: TextRTF was upgraded to Text and has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
        rt1.Text = Join(DATAS, "")
        Erase DATAS

this part of the code is what seems to be giving me problems when trying to figure out what data type to replace "Any" with. When I change pSrc to Byte and leave pDst to Any the program loads without a hitch but its that last data type that i need and is the problem to my question.

VB
Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)

'Is anyone able to tell me what data types are used in place of "Any" for the array descriptor sub and for sub copyMemory?<

Thank you in advance and I apologize for the lengthy question!
Posted
Updated 17-Apr-12 10:12am
v3
Comments
ledtech3 17-Apr-12 13:01pm    
According to a site called http://www.vb-helper.com/howto_net_copy_memory.html
they used:
Private Declare Sub CopyMemory Lib "kernel32" Alias _
"RtlMoveMemory" (ByVal Destination As Long, ByVal _
Source As Long, ByVal Length As Integer)

1 solution

Your best friend for this kind of information is pinvoke.net. Add it to your favourites!

http://www.pinvoke.net/default.aspx/kernel32.MoveMemory[^]

Alan.
[EDIT] I see that you've double posted and got the same answer both times.
 
Share this answer
 
v2
Comments
Dale 2012 17-Apr-12 13:50pm    
yes I am sorry for the double post but I figured that I would receive a response sooner as vb6 is not visited as frequently as vb.net, being old and all.
Dale 2012 17-Apr-12 15:57pm    
You are 100% correct!!! Thank you

the code that consists of the pointers is:

Public Function ReadPE(ByRef DATA() As Byte) As Byte
On Error GoTo ErrX
Dim CNT As Integer
Dim u As Integer
'UPGRADE_WARNING: Couldn't resolve default property of object DOSHEADER. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
CopyMemory(DOSHEADER, DATA(CNT), Len(DOSHEADER))
If DOSHEADER.e_magic <> "MZ" Then Exit Function
'UPGRADE_WARNING: Couldn't resolve default property of object NTHEADER. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
CopyMemory(NTHEADER, DATA(DOSHEADER.e_lfanew), Len(NTHEADER))
CNT = CNT + DOSHEADER.e_lfanew + Len(NTHEADER)
If NTHEADER.Signature <> "PE" & Chr(0) & Chr(0) Then Exit Function
ReDim SECTIONSHEADER(NTHEADER.FileHeader.NumberOfSections - 1)
For u = 0 To UBound(SECTIONSHEADER)
'UPGRADE_WARNING: Couldn't resolve default property of object SECTIONSHEADER(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
CopyMemory(SECTIONSHEADER(u), DATA(CNT), Len(SECTIONSHEADER(0)))
CNT = CNT + Len(SECTIONSHEADER(0))
Next u
ReadPE = 1
Exit Function
ErrX:
On Error GoTo 0
End Function


Can you or someone give an example of how to use the marshal class in my case?

DOSHEADER, NTHEADER, SECTIONSHEADER seem to be the issue now. I need to copy the memory with marshal class but how, please help once more

thank you in advance
cheers!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900