Пример #1
0
UINT WINAPI SHAppBarMessage(DWORD dwMessage, PAPPBARDATA pabd)
{
    HWND hwndTray;
    COPYDATASTRUCT cds;
    TRAYAPPBARDATA tabd;
    BOOL fret;
    LPRECT lprc = NULL;

    hwndTray = FindWindow(c_szTrayClass, NULL);
    if (!hwndTray || (pabd->cbSize > SIZEOF(tabd.abd)))
    {
        return(FALSE);
    }

    tabd.abd = *pabd;
    tabd.dwMessage = dwMessage;
    tabd.hSharedRect = NULL;
    tabd.dwProcId = GetCurrentProcessId();

    cds.dwData = TCDM_APPBAR;
    cds.cbData = SIZEOF(tabd);
    cds.lpData = &tabd;

    switch (dwMessage) {
    case ABM_QUERYPOS:
    case ABM_SETPOS:
    case ABM_GETTASKBARPOS:
        tabd.hSharedRect = SHAllocShared(NULL, SIZEOF(RECT), tabd.dwProcId);
        if (tabd.hSharedRect == NULL)
            return FALSE;
        break;
    }

    fret = (SendMessage(hwndTray, WM_COPYDATA, (WPARAM)pabd->hWnd, (LPARAM)&cds));

    if (tabd.hSharedRect) {
        lprc = (LPRECT)SHLockShared(tabd.hSharedRect,tabd.dwProcId);
        if (lprc == NULL)
        {
            fret = FALSE;
        }
        else
        {
            pabd->rc = *lprc;
            SHUnlockShared(lprc);
        }
        SHFreeShared(tabd.hSharedRect,tabd.dwProcId);
    }
    return fret;
}
Пример #2
0
HANDLE MakeSharedPacket(IEThreadParamBlock * threadParams, LPCWSTR strPath, int dwProcessId)
{
    HNFBlock* hnfData;
    UINT sharedBlockSize = sizeof(*hnfData);
    UINT directoryPidlLength = 0;
    UINT pidlSize7C = 0;
    UINT pidlSize80 = 0;
    UINT pathLength = 0;
    LPITEMIDLIST pidl80 = threadParams->offset80;

    // Count the total length of the message packet

    // directory PIDL
    if (threadParams->directoryPIDL)
    {
        directoryPidlLength = ILGetSize(threadParams->directoryPIDL);
        sharedBlockSize += directoryPidlLength;
        DbgPrint("directoryPidlLength=%d\n", directoryPidlLength);
    }

    // another PIDL
    if (threadParams->offset7C)
    {
        pidlSize7C = ILGetSize(threadParams->offset7C);
        sharedBlockSize += pidlSize7C;
        DbgPrint("pidlSize7C=%d\n", pidlSize7C);
    }

    // This flag indicates the presence of another pidl?
    if (!(threadParams->offset84 & 0x8000))
    {
        if (pidl80)
        {
            pidlSize80 = ILGetSize(pidl80);
            sharedBlockSize += pidlSize80;
            DbgPrint("pidlSize80=%d\n", pidlSize7C);
        }
    }
    else
    {
        DbgPrint("pidl80 sent by value = %p\n", pidl80);
        pidlSize80 = 4;
        sharedBlockSize += pidlSize80;
    }

    // The path string
    if (strPath)
    {
        pathLength = 2 * lstrlenW(strPath) + 2;
        sharedBlockSize += pathLength;
        DbgPrint("pathLength=%d\n", pidlSize7C);
    }

    DbgPrint("sharedBlockSize=%d\n", sharedBlockSize);

    // Allocate and fill the shared section
    HANDLE hShared = SHAllocShared(0, sharedBlockSize, dwProcessId);
    if (!hShared)
    {
        DbgPrint("Shared section alloc error.\n");
        return 0;
    }

    PBYTE target = (PBYTE) SHLockShared(hShared, dwProcessId);
    if (!target)
    {
        DbgPrint("Shared section lock error. %d\n", GetLastError());
        SHFreeShared(hShared, dwProcessId);
        return 0;
    }

    // Basic information
    hnfData = (HNFBlock*) target;
    hnfData->cbSize = sharedBlockSize;
    hnfData->offset4 = (DWORD) (threadParams->dwFlags);
    hnfData->offset8 = (DWORD) (threadParams->offset8);
    hnfData->offsetC = (DWORD) (threadParams->offset74);
    hnfData->offset10 = (DWORD) (threadParams->offsetD8);
    hnfData->offset14 = (DWORD) (threadParams->offset84);
    hnfData->offset18 = (DWORD) (threadParams->offset88);
    hnfData->offset1C = (DWORD) (threadParams->offset8C);
    hnfData->offset20 = (DWORD) (threadParams->offset90);
    hnfData->offset24 = (DWORD) (threadParams->offset94);
    hnfData->offset28 = (DWORD) (threadParams->offset98);
    hnfData->offset2C = (DWORD) (threadParams->offset9C);
    hnfData->offset30 = (DWORD) (threadParams->offsetA0);
    hnfData->directoryPidlLength = 0;
    hnfData->pidlSize7C = 0;
    hnfData->pidlSize80 = 0;
    hnfData->pathLength = 0;
    target += sizeof(*hnfData);

    // Copy the directory pidl contents
    if (threadParams->directoryPIDL)
    {
        memcpy(target, threadParams->directoryPIDL, directoryPidlLength);
        target += directoryPidlLength;
        hnfData->directoryPidlLength = directoryPidlLength;
    }

    // Copy the other pidl contents
    if (threadParams->offset7C)
    {
        memcpy(target, threadParams->offset7C, pidlSize7C);
        target += pidlSize7C;
        hnfData->pidlSize7C = pidlSize7C;
    }

    // copy the third pidl
    if (threadParams->offset84 & 0x8000)
    {
        *(LPITEMIDLIST*) target = pidl80;
        target += pidlSize80;
        hnfData->pidlSize80 = pidlSize80;
    }
    else if (pidl80)
    {
        memcpy(target, pidl80, pidlSize80);
        target += pidlSize80;
        hnfData->pidlSize80 = pidlSize80;
    }

    // and finally the path string
    if (strPath)
    {
        memcpy(target, strPath, pathLength);
        hnfData->pathLength = pathLength;
    }

    SHUnlockShared(hnfData);

    return hShared;
}