Results 1 to 28 of 28

Thread: Help: Pointers Problems

Threaded View

  1. #13

    Thread Starter
    Lively Member
    Join Date
    May 2004
    Location
    Home
    Posts
    85

    Re: Help: Pointers Problems

    Events:
    Code:
    Private Sub Command1_Click()
        'Text2.Text = FormatFilePath(Text1.Text)
        Text2.Text = FormatFilePath2(Text1.Text)
    End Sub
    
    Private Function OpenFilePath(ByVal sPath As String) As String
    
        'Variables:
        Dim hFile As Long
        
        'Method 1:
            Dim OFS As OFSTRUCT
            hFile = OpenFile(sPath, OFS, OF_READWRITE)
        
        'Method 2:
            'Dim lReturn As Long
            'Dim tObjAttr As OBJECT_ATTRIBUTES
            'Dim tUString As UNICODE_STRING
        
            'Initialize attributes:
            'tUString.Length = Len(sPath) * 2
            'tUString.Buffer = StrPtr(sPath)
            
            'tObjAttr.Length = Len(tObjAttr)
            'tObjAttr.ObjectName = VarPtr(tUString)
            'tObjAttr.Attributes = OBJ_CASE_INSENSITIVE Or OBJ_INHERIT
            
            'Open File:
            'lReturn = ZwOpenFile(hFile, FILE_ALL_ACCESS, 0, tIO, FILE_SHARE_READ Or FILE_SHARE_WRITE, FILE_NON_DIRECTORY_FILE)
            'lReturn = NtOpenFile(hFile, GENERIC_READ Or SYNCHRONIZE, tObjAttr, tIO, FILE_SHARE_READ, FILE_NON_DIRECTORY_FILE Or FILE_SYNCHRONOUS_IO_NONALERT)
                'MsgBox GetSysMsg(lReturn0)
    
        'Return Value:
        OpenFilePath = hFile
    
    End Function
    
    
    Public Function FormatFilePath2(ByVal sPath As String) As String
    
        Dim tIO As IO_STATUS_BLOCK
        Dim tFileName As FILE_NAME_INFORMATION
        
        Dim hFile As Long
        Dim lReturn As Long
        
        '-----------
        
        'Open File:
        hFile = OpenFilePath(sPath)
            MsgBox "hFile  = " & hFile
            
        'Set buffer & size:
        tFileName.FileName.Length = Len(sPath) * 2
        tFileName.FileName.Buffer = StrPtr(sPath)
        Call RtlInitUnicodeString(tFileName.FileName, StrPtr(sPath))
        
            MsgBox "Unicode Buff = " & tFileName.FileName.Buffer
            MsgBox "Unicode Length = " & tFileName.FileName.Length
            MsgBox "Unicode MaxLength = " & tFileName.FileName.MaximumLength
        
        'Store structure size:
        Dim lSize As Long
        lSize = Len(tFileName)
            MsgBox "lSize = " & lSize
        
        'Set pointer:
        Dim ptr As Long
        ptr = VarPtr(tFileName)
            MsgBox "Pointer = " & ptr
            MsgBox "Pointer Size = " & Len(ptr)
        
        'Fill data structure:
        lReturn = NtQueryInformationFile(hFile, tIO, ptr, lSize, FileNameInformation)
            MsgBox GetSysMsg(lReturn)
        
        'Move pointer to variable:
        Dim tFNI As FNI
        
            'Init Unicode string maybe? (Still does not work)
            tFNI.FileName.Length = Len(sPath) * 2
            tFNI.FileName.Buffer = StrPtr(sPath)
            Call RtlInitUnicodeString(tFNI.FileName, StrPtr(sPath))
        
        'Call CopyMemory(tFNI, ByVal ptr, Len(ptr))
        'Call CopyMemory(ByVal VarPtr(tFNI), ByVal ptr, lSize)
        'Call CopyMemory(VarPtr(tFNI), ByVal ptr, Len(ptr))
        'Call CopyMemoryRead(ByVal VarPtr(tFNI), ByVal VarPtr(ptr), Len(ptr))
        
        Call CopyMemory(ByVal VarPtr(tFNI), ByVal ptr, LenB(tFNI))
        
        
            MsgBox "tFNI Size = " & Len(tFNI)
            
            MsgBox "Unicode Buff = " & tFNI.FileName.Buffer
            MsgBox "Unicode Length = " & tFNI.FileName.Length
            MsgBox "Unicode MaxLength = " & tFNI.FileName.MaximumLength
        
        Dim sValue As String
        sValue = Space(tFNI.FileName.Length \ 2)
            MsgBox "sValue Buff = " & sValue
        'Call CopyMemoryRead(sValue, ByVal tFNI.FileName.Buffer, (Len(tFNI.FileName.Buffer)))
        'Call CopyMemory(ByVal VarPtr(sValue), tFNI.FileName.Buffer, 4)
        Call CopyMemory(ByVal StrPtr(sValue), tFNI.FileName.Buffer, tFNI.FileName.Length)
            MsgBox "sValue = " & sValue
    
    End Function

    The problem is right here:
    Code:
        'Move pointer to variable:
        Dim tFNI As FNI
        
            'Init Unicode string maybe? (Still does not work)
            tFNI.FileName.Length = Len(sPath) * 2
            tFNI.FileName.Buffer = StrPtr(sPath)
            Call RtlInitUnicodeString(tFNI.FileName, StrPtr(sPath))
        
        'Call CopyMemory(tFNI, ByVal ptr, Len(ptr))
        'Call CopyMemory(ByVal VarPtr(tFNI), ByVal ptr, lSize)
        'Call CopyMemory(VarPtr(tFNI), ByVal ptr, Len(ptr))
        'Call CopyMemoryRead(ByVal VarPtr(tFNI), ByVal VarPtr(ptr), Len(ptr))
        
        Call CopyMemory(ByVal VarPtr(tFNI), ByVal ptr, LenB(tFNI))
    Notice how I tried the method you described in there.

    See if you have any idea why it does this. To create it just add it to a form and put 1 command button and 2 textboxes on it.

    Eneter a valid file path in textbox 1 and see what happens. It will go up to the point, the API will be successful, and then boom crashes.

    Please Help.


    OR

    Here I uploaded my code, just add a text file called A.txt to C:\ and click the command button and watch it crash right after the Error_Success Return from the API:
    http://www.mediafire.com/?7rzkn1ldywe

    So please help if you can.
    Last edited by altf4; Apr 29th, 2007 at 05:21 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width