Click here to Skip to main content
14,984,043 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to port some vb6 code to vb.net and one object in a line of code is not assigned a value before it's used Here's the code

Public Function GetFileFullPath(ByVal hFile As Long) As String
    Dim objName         As UNICODE_STRING
    Dim hHeap           As Long
    Dim dwSize          As Long
    Dim dwDriversSize   As Long
    Dim pName           As Long
    Dim ntStatus        As Long
    Dim i               As Long
    Dim strDrives       As String
    Dim strArray()      As String
    Dim strDrive        As String
    Dim strTmp          As String
    Dim strTemp         As String
    
    hHeap = GetProcessHeap
    pName = HeapAlloc(hHeap, HEAP_ZERO_MEMORY, &H1000)
    ntStatus = NtQueryObject(hFile, ObjectNameInformation, pName, &H1000, dwSize)
    If (NT_SUCCESS(ntStatus)) Then
        i = 1
        Do While (ntStatus = STATUS_INFO_LEN_MISMATCH)
            pName = HeapReAlloc(hHeap, HEAP_ZERO_MEMORY, pName, &H1000 * i)
            ntStatus = NtQueryObject(hFile, ObjectNameInformation, pName, &H1000, ByVal 0)
            i = i + 1
        Loop
    End If
    HeapFree hHeap, 0, pName
    strTemp = String$(512, Chr$(0))
    lstrcpyW strTemp, pName + Len(objName)


On the very last line, objName has not been initialized and I get then warning 'objName is used before it has been assigned a value.

Do you think the author meant Len(pName) ?

thanks

What I have tried:

I have a function that uses objName. Most of it is included in the post.
Posted
Updated 18-Jul-16 8:19am
v3
Comments
Richard Deeming 18-Jul-16 14:18pm
   
From what I can see, NtQueryObject[^] is not a public API. It could be changed or removed from Windows without notice.

Based on the name of the function, I'm guessing you want to get the path of a file based on a file handle. You should probably be using GetFinalPathNameByHandle[^] to do that. (Obtaining a File Name From a File Handle[^])

If that's the converted code, then the converter has done a very poor job. There are several obvious problems with the code - for example, using On Error ... instead of Try .. Catch, using Long instead of IntPtr to represent a handle, etc.
Member 12333593 18-Jul-16 14:50pm
   
Thank you. You've helped a lot. And I actually removed the "On Error" shortly after I posted it, plus removed it from my code. I'll replace it with try/catch. Thanks also about the long instead of IntPtr.

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