예제 #1
0
IFACEMETHODIMP ContextMenu::GetCommandString(UINT_PTR idCommand,
                                             UINT uFlags,
                                             LPUINT lpReserved,
                                             LPSTR pszName,
                                             UINT uMaxNameLen)
{
    HRESULT  hr = E_INVALIDARG;

    if (idCommand != IDM_SHAREWITHBOX)
    {
        return hr;
    }

    switch(uFlags)
    {
        case GCS_HELPTEXTA:
            hr = StringCchCopyNA(pszName, 
                                 uMaxNameLen, 
                                 HELP_A, 
                                 uMaxNameLen);
            break; 

        case GCS_HELPTEXTW: 
            hr = StringCchCopyNW((LPWSTR)pszName, 
                                 uMaxNameLen, 
                                 HELP_W, 
                                 uMaxNameLen);
            break; 

        case GCS_VERBA:
            hr = StringCchCopyNA(pszName, 
                                  uMaxNameLen, 
                                  VERB_A, 
                                  uMaxNameLen);
            break; 

        case GCS_VERBW:
            hr = StringCchCopyNW((LPWSTR)pszName, 
                                 uMaxNameLen, 
                                 VERB_W, 
                                 uMaxNameLen);
            break; 

        default:
            hr = S_OK;
            break; 
    }
    return hr;
}
예제 #2
0
파일: DrmShlExt.cpp 프로젝트: Ochieng/drm
//
//   FUNCTION: CDrmShlExt::GetCommandString(UINT, UINT, LPUINT, 
//             LPSTR, UINT)
//
//   PURPOSE: If a user highlights one of the items added by a context menu 
//            handler, the handler's IContextMenu::GetCommandString method is 
//            called to request a Help text string that will be displayed on 
//            the Windows Explorer status bar. This method can also be called 
//            to request the verb string that is assigned to a command. 
//            Either ANSI or Unicode verb strings can be requested.
//
IFACEMETHODIMP CDrmShlExt::GetCommandString(
    UINT_PTR idCommand, UINT uFlags, LPUINT lpReserved, LPSTR pszName, 
    UINT uMaxNameLen)
{
    HRESULT hr = E_INVALIDARG;

    // For the command "&Decrypt" (IDM_DECRYPT)
    if (idCommand == IDM_DECRYPT)
    {
        switch (uFlags)
        {
        case GCS_HELPTEXTA:
            hr = StringCchCopyNA(pszName, 
                lstrlenA(pszName) / sizeof(pszName[0]), 
                "Rights Network File Decrypter", 
                uMaxNameLen);
            break;

        case GCS_HELPTEXTW:
            hr = StringCchCopyNW((LPWSTR)pszName, 
                lstrlenW((LPWSTR)pszName) / sizeof(pszName[0]), 
                L"Rights Network File Decrypter", 
                uMaxNameLen);
            break;

        case GCS_VERBA:
            hr = StringCchCopyNA(pszName, 
                lstrlenA(pszName) / sizeof(pszName[0]), 
                VERB_DECRYPTA, uMaxNameLen);
            break;

        case GCS_VERBW:
            hr = StringCchCopyNW((LPWSTR)pszName, 
                lstrlenW((LPWSTR)pszName) / sizeof(pszName[0]), 
                VERB_DECRYPTW, uMaxNameLen);
            break;

        default:
            hr = S_OK;
        }
    }

    // If the command (idCommand) is not supported by this context menu 
    // extension handler, return E_INVALIDARG.

    return hr;
}
예제 #3
0
/*!
	ホットキーによる投下の調整
	@return		HRESULT	終了状態コード
*/
HRESULT DocThreadDropCopy( VOID )
{
	CHAR	acBuf[260];
	TCHAR	atTitle[64], atInfo[256];
	INT	cbSize, maxPage;//, dFocusBuf;
	LPVOID	pcString = NULL;

//	dFocusBuf = gixFocusPage;	//	現在頁を一旦待避させて
//	gixFocusPage = gixDropPage;	//	投下用頁にして

//	cbSize = DocPageTextAllGetAlloc( D_SJIS, &pcString );
	cbSize = DocPageTextGetAlloc( gitFileIt, gixDropPage, D_SJIS, &pcString, FALSE );

//	gixFocusPage = dFocusBuf;	//	終わったら戻す

	TRACE( TEXT("%d 頁をコピー"), gixDropPage );

	DocClipboardDataSet( pcString, cbSize, D_SJIS );

	ZeroMemory( acBuf, sizeof(acBuf) );
	StringCchCopyNA( acBuf, 260, (LPCSTR)pcString, 250 );
	ZeroMemory( atInfo, sizeof(atInfo) );
	MultiByteToWideChar( CP_ACP, 0, acBuf, (INT)strlen(acBuf), atInfo, 256 );

	StringCchPrintf( atTitle, 64, TEXT("%d 頁をコピーしたよ"), gixDropPage + 1 );

	NotifyBalloonExist( atInfo, atTitle, NIIF_INFO );

	FREE( pcString );

	gixDropPage++;	//	次の頁へ

	maxPage = DocNowFilePageCount(  );
	if( maxPage <= gixDropPage )	gixDropPage = 0;
	//	最終頁までイッたら先頭に戻る


	return S_OK;
}
예제 #4
0
char * GetFileNameFromHandle(HANDLE hFile, TCHAR *pszFilename)
{
    BOOL bSuccess = FALSE;
    HANDLE hFileMap;
    void* pMem;
    // Get the file size.
    DWORD dwFileSizeHi = 0;
    DWORD dwFileSizeLo = GetFileSize(hFile, &dwFileSizeHi);

    if( dwFileSizeLo == 0 && dwFileSizeHi == 0 ) {
        printf(TEXT("Cannot map a file with a length of zero.\n"));
        return FALSE;
    }

    // Create a file mapping object.
    hFileMap = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 1, NULL);

    if (!hFileMap)
        return FALSE;

    // Create a file mapping to get the file name.
    pMem = MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, 1);

    if (!pMem) {
        CloseHandle(hFileMap);
        return FALSE;
    }
    if (GetMappedFileName (GetCurrentProcess(), pMem, pszFilename, MAX_PATH)) {
        // Translate path with device name to drive letters.
        TCHAR szTemp[BUFSIZE];
        szTemp[0] = '\0';

        if (GetLogicalDriveStrings(BUFSIZE-1, szTemp)) {
            TCHAR szName[MAX_PATH];
            TCHAR szDrive[3] = TEXT(" :");
            BOOL bFound = FALSE;
            TCHAR* p = szTemp;

            do {
                // Copy the drive letter to the template string
                *szDrive = *p;

                // Look up each device name
                if (QueryDosDevice(szDrive, szName, MAX_PATH)) {
                    size_t uNameLen = strlen(szName);

                    if (uNameLen < MAX_PATH) {
                        bFound = _strnicmp(pszFilename, szName, uNameLen) == 0
                                 && *(pszFilename + uNameLen) == '\\';

                        if (bFound) {
                            // Reconstruct pszFilename using szTempFile
                            // Replace device path with DOS path
                            TCHAR szTempFile[MAX_PATH];
                            StringCchPrintfA(szTempFile, MAX_PATH, TEXT("%s%s"), szDrive, pszFilename+uNameLen);
                            StringCchCopyNA(pszFilename, MAX_PATH+1, szTempFile, strlen(szTempFile));
                        }
                    }
                }
                while (*p++);	// Go to the next NULL character.
            } while (!bFound && *p); // end of string
        }
    }
    bSuccess = TRUE;
    UnmapViewOfFile(pMem);
    CloseHandle(hFileMap);

    if (bSuccess == TRUE)
        return pszFilename;

    return NULL;
}
예제 #5
0
파일: util.c 프로젝트: 340211173/Driver
DWORD
WINAPI
RemoveVirtualDriver (
                     HWND           hWnd,
                     PVIRT_DEVICE   pVirtualDevice,
                     ULONG          BusNumber)
{
    HANDLE                      hDevice = INVALID_HANDLE_VALUE;
    ULONG                       ulStrLen = 0;
    size_t                      retVal = 0;
    UCHAR                       BusName[16] = "\\\\.\\1394BUS";
    PIEEE1394_API_REQUEST       p1394ApiReq = NULL;
    PIEEE1394_VDEV_PNP_REQUEST  pDevPnpReq = NULL;
    DWORD                       dwBytesRet = 0;
    DWORD                       dwRet = ERROR_SUCCESS;
    ULONG                       p1394ApiReqLen = 0;

    if (!pVirtualDevice->DeviceID)
    {
        dwRet = ERROR_INVALID_PARAMETER;

        goto Exit_RemoveVirtualDriver;
    }

    _itoa_s (
        BusNumber, 
        (CHAR *) &BusName[11], 
        ((sizeof (BusName) / sizeof (BusName[0])) - (strlen((CHAR *)BusName))),
        10);


    hDevice = OpenDevice (hWnd, (PSTR) &BusName);
    if (hDevice != INVALID_HANDLE_VALUE) 
    {

        //taking care of NULL termination character
        retVal = strlen(pVirtualDevice->DeviceID) + 1;

        if (S_OK != (SizeTToULong (retVal, &ulStrLen)))
        {
            dwRet = GetLastError();
            TRACE (TL_ERROR, (hWnd, "SizeTToULong failed: %d\n", dwRet));

            goto Exit_RemoveVirtualDriver;
        }



        if ( pVirtualDevice->fulFlags & IEEE1394_REQUEST_FLAG_UNICODE ) 
        {
            p1394ApiReq = \
                (PIEEE1394_API_REQUEST) LocalAlloc (
                LPTR, 
                sizeof(IEEE1394_API_REQUEST)+(ulStrLen * sizeof(WCHAR)));

            if (NULL == p1394ApiReq)
            {
                dwRet = GetLastError();
                TRACE (TL_FATAL, (hWnd, "LocalAlloc failed: %d\n", dwRet));

                goto Exit_RemoveVirtualDriver;
            }

            p1394ApiReqLen = \
                sizeof(IEEE1394_API_REQUEST)+(ulStrLen * sizeof(WCHAR));
        } 
        else 
        {
            p1394ApiReq = (PIEEE1394_API_REQUEST) LocalAlloc (
                LPTR, 
                sizeof(IEEE1394_API_REQUEST)+ulStrLen);
            
            if (NULL == p1394ApiReq)
            {
                dwRet = GetLastError();
                TRACE (TL_FATAL, (hWnd, "LocalAlloc failed: %d\n", dwRet));

                goto Exit_RemoveVirtualDriver;
            }

            p1394ApiReqLen = sizeof(IEEE1394_API_REQUEST)+ ulStrLen;
        }

        p1394ApiReq->RequestNumber = IEEE1394_API_REMOVE_VIRTUAL_DEVICE;
        p1394ApiReq->Flags = 0;

        pDevPnpReq = &p1394ApiReq->u.RemoveVirtualDevice;

        pDevPnpReq->fulFlags = pVirtualDevice->fulFlags;
        pDevPnpReq->Reserved = 0;
        pDevPnpReq->InstanceId = pVirtualDevice->InstanceID;
        
        if (pVirtualDevice->fulFlags & IEEE1394_REQUEST_FLAG_UNICODE) 
        {
            if (S_OK != StringCchCopyNW (
                (LPWSTR)&pDevPnpReq->DeviceId,
                ulStrLen,
                (LPWSTR)pVirtualDevice->DeviceID, 
                ulStrLen))
            {
                TRACE (TL_FATAL, (hWnd, "StringCchCopyNW failed\n"));
                dwRet = ERROR_INSUFFICIENT_BUFFER;

                goto Exit_RemoveVirtualDriver;
            }
        
            if (!DeviceIoControl (
                hDevice,
                IOCTL_IEEE1394_API_REQUEST,
                p1394ApiReq,
                p1394ApiReqLen,
                NULL,
                0,
                &dwBytesRet,
                NULL))
            {
                dwRet = GetLastError();

                goto Exit_RemoveVirtualDriver;
            }
        } 
        else 
        {
            if (S_OK != StringCchCopyNA (
                (STRSAFE_LPSTR) &pDevPnpReq->DeviceId,
                ulStrLen,
                (STRSAFE_LPSTR) pVirtualDevice->DeviceID, 
                ulStrLen))
            {
                TRACE (TL_FATAL, (hWnd, "StringCchCopyNA failed\n"));
                dwRet = ERROR_INSUFFICIENT_BUFFER;

                goto Exit_RemoveVirtualDriver;
            }

            if (!DeviceIoControl (
                hDevice,
                IOCTL_IEEE1394_API_REQUEST,
                p1394ApiReq,
                p1394ApiReqLen,
                NULL,
                0,
                &dwBytesRet,
                NULL))
            {
                dwRet = GetLastError();
            }
        }
    }
    else 
    {
        dwRet = ERROR_INVALID_HANDLE;
    }

Exit_RemoveVirtualDriver:

    if (INVALID_HANDLE_VALUE != hDevice)
    {
        CloseHandle (hDevice);
    }

    if (p1394ApiReq)
    {
        LocalFree (p1394ApiReq);
    }

    return dwRet;
}
예제 #6
0
파일: util.c 프로젝트: 340211173/Driver
DWORD
WINAPI
AddVirtualDriver (
                  HWND                hWnd,
                  PVIRT_DEVICE    pVirtualDevice,
                  ULONG               BusNumber)
{
    HANDLE                      hDevice;
    ULONG                       ulStrLen;
    size_t                      retVal = 0;
    UCHAR                       BusName[16] = "\\\\.\\1394BUS";
    PIEEE1394_API_REQUEST       p1394ApiReq;
    PIEEE1394_VDEV_PNP_REQUEST  pDevPnpReq;
    DWORD                       dwBytesRet;
    DWORD                       dwRet;
    ULONG                       p1394ApiReqLen = 0;

    TRACE(TL_TRACE, (hWnd, "AddVirtual Driver\r\n"));

    _itoa_s (
        BusNumber, 
        (CHAR *) &BusName[11], 
        ((sizeof (BusName) / sizeof (BusName[0])) - (strlen((CHAR *)BusName))),
        10);


    TRACE (TL_TRACE, (hWnd, "Bus: %s\r\n", BusName));

    hDevice = OpenDevice (hWnd, (PSTR) &BusName);
    if (hDevice != INVALID_HANDLE_VALUE)
    {

        //taking care of NULL terminating character
        retVal = strlen(pVirtualDevice->DeviceID) + 1;

        if (S_OK != (SizeTToULong (retVal, &ulStrLen)))
        {
            dwRet = GetLastError();
            TRACE (TL_ERROR, (hWnd, "SizeTToULong failed: %d\n", dwRet));
            return dwRet;
        }


        if ( pVirtualDevice->fulFlags & IEEE1394_REQUEST_FLAG_UNICODE ) 
        {
            p1394ApiReq = (PIEEE1394_API_REQUEST) LocalAlloc (
                LPTR, 
                sizeof(IEEE1394_API_REQUEST)+(ulStrLen * sizeof(WCHAR)));

            if (NULL == p1394ApiReq)
            {
                DWORD gle = GetLastError();

                TRACE (TL_FATAL, (hWnd, "LocalAlloc failed: %d\n", gle));
                return gle;
            }

            p1394ApiReqLen = \
                sizeof(IEEE1394_API_REQUEST)+(ulStrLen * sizeof(WCHAR));
        } 
        else 
        {
            p1394ApiReq = (PIEEE1394_API_REQUEST) LocalAlloc(LPTR, 
                sizeof(IEEE1394_API_REQUEST)+ulStrLen);

            if (NULL == p1394ApiReq)
            {
                DWORD gle = GetLastError();

                TRACE (TL_FATAL, (hWnd, "LocalAlloc failed: %d\n", gle));
                return gle;
            }

            p1394ApiReqLen = sizeof(IEEE1394_API_REQUEST)+ ulStrLen;
        }

        p1394ApiReq->RequestNumber = IEEE1394_API_ADD_VIRTUAL_DEVICE;
        p1394ApiReq->Flags = pVirtualDevice->fulFlags;

        pDevPnpReq = &p1394ApiReq->u.AddVirtualDevice;

        pDevPnpReq->fulFlags = pVirtualDevice->fulFlags;
        pDevPnpReq->Reserved = 0;
        pDevPnpReq->InstanceId = pVirtualDevice->InstanceID;

        if ( pVirtualDevice->fulFlags & IEEE1394_REQUEST_FLAG_UNICODE ) 
        {
            if (S_OK != StringCchCopyNW (
                (LPWSTR)&pDevPnpReq->DeviceId,
                ulStrLen,
                (LPWSTR)pVirtualDevice->DeviceID, 
                ulStrLen))
                            
            {
                TRACE (TL_FATAL, (hWnd, "StringCchCopyNW failed\n"));
                return ERROR_INSUFFICIENT_BUFFER;
            }


            dwRet = DeviceIoControl (
                hDevice,
                IOCTL_IEEE1394_API_REQUEST,
                p1394ApiReq,
                p1394ApiReqLen,
                NULL,
                0,
                &dwBytesRet,
                NULL);
        } 
        else 
        {
            if (S_OK != StringCchCopyNA (
                (STRSAFE_LPSTR) &pDevPnpReq->DeviceId,
                ulStrLen,
                (STRSAFE_LPSTR) pVirtualDevice->DeviceID, 
                ulStrLen))
            {
                TRACE (TL_FATAL, (hWnd, "StringCchCopyNA failed\n"));
                return ERROR_INSUFFICIENT_BUFFER;
            }

            dwRet = DeviceIoControl (
                hDevice,
                IOCTL_IEEE1394_API_REQUEST,
                p1394ApiReq,
                p1394ApiReqLen,
                NULL,
                0,
                &dwBytesRet,
                NULL);
        }

        if (!dwRet)
        {
            
            dwRet = GetLastError();
            TRACE(
                TL_WARNING, 
                (hWnd, 
                "Failed IOCTL_IEEE1394_API_REQEST 0x%x\r\n", 
                dwRet));
        }
        else 
        {
            TRACE(TL_WARNING, (hWnd, "Succeeded IOCTL_IEEE1394_API_REQEST\r\n"));
            dwRet = ERROR_SUCCESS;
        }

        // free resources

        CloseHandle (hDevice);
        LocalFree(p1394ApiReq);
    }
    else 
    {
        dwRet = ERROR_INVALID_HANDLE;
    }

    return dwRet;
}
예제 #7
0
HRESULT StringCchCopyA(
        LPSTR pszDest,
        size_t cchDest,
        LPCSTR pszSrc){
    return StringCchCopyNA(pszDest, cchDest, pszSrc, cchDest);
}
예제 #8
0
static int config_load(
    struct idmap_config *config,
    const char *filename)
{
    char buffer[1024], *pos;
    FILE *file;
    struct config_pair pair;
    const struct config_option *option;
    int line = 0;
    int status = NO_ERROR;

    /* open the file */
    file = fopen(filename, "r");
    if (file == NULL) {
        eprintf("config_load() failed to open file '%s'\n", filename);
        goto out;
    }

    /* read each line */
    while (fgets(buffer, sizeof(buffer), file)) {
        line++;

        /* skip whitespace */
        pos = buffer;
        while (isspace(*pos)) pos++;

        /* skip comments and empty lines */
        if (*pos == '#' || *pos == 0)
            continue;

        /* parse line into a key=value pair */
        status = config_parse_pair(buffer, &pair);
        if (status) {
            eprintf("error on line %d: %s\n", line, buffer);
            break;
        }

        /* find the config_option by key */
        status = config_find_option(&pair, &option);
        if (status) {
            eprintf("unrecognized option '%s' on line %d: %s\n",
                pair.key, line, buffer);
            status = ERROR_INVALID_PARAMETER;
            break;
        }

        if (option->type == TYPE_INT) {
            if (!parse_uint(pair.value, (UINT*)((char*)config + option->offset))) {
                status = ERROR_INVALID_PARAMETER;
                eprintf("expected a number on line %d: %s=\"%s\"\n",
                    line, pair.key, pair.value);
                break;
            }
        } else {
            if (FAILED(StringCchCopyNA((char*)config + option->offset,
                    option->max_len, pair.value, pair.value_len))) {
                status = ERROR_BUFFER_OVERFLOW;
                eprintf("overflow on line %d: %s=\"%s\"\n",
                    line, pair.key, pair.value);
                break;
            }
        }
    }

    fclose(file);
out:
    return status;
}
예제 #9
0
void FillMenuItemInfo(HWND hWnd, HIMC hIMC, LPMENUITEMINFO lpmii, LPMYIMEMENUITEMINFO lpIme, BOOL fRight)
{
    FillMemory((PVOID)lpmii, sizeof(MENUITEMINFO), 0);
    lpmii->cbSize = sizeof(MENUITEMINFO);
    lpmii->fMask = 0;

    // Set fType;
    if (lpIme->fType)
    {
        lpmii->fMask |= MIIM_TYPE;
        lpmii->fType = 0;

        if (lpIme->fType & IMFT_RADIOCHECK)
        {
            lpmii->fType |= MFT_RADIOCHECK;
        }

        if (lpIme->fType & IMFT_SEPARATOR)
        {
            lpmii->fType |= MFT_SEPARATOR;
        }

    }

    lpmii->fMask |= MIIM_ID;
    lpmii->wID = lpIme->wID + IDM_STARTIMEMENU;

    if (lpIme->fType & IMFT_SUBMENU)
    {
        lpmii->fMask |= MIIM_SUBMENU;
        lpmii->hSubMenu = CreateImeMenu(hWnd, hIMC, lpIme, fRight);
    }

    lpmii->fMask |= MIIM_STATE;
    lpmii->fState = lpIme->fState;

    if (lpIme->hbmpChecked &&  lpIme->hbmpUnchecked)
    {
       lpmii->fMask |= MIIM_CHECKMARKS;
       lpmii->hbmpChecked = lpIme->hbmpChecked;
       lpmii->hbmpUnchecked = lpIme->hbmpUnchecked;
    }
    

    lpmii->fMask |= MIIM_DATA;
    lpmii->dwItemData = lpIme->dwItemData;

    if (lpIme->hbmpItem)
    {
       lpmii->fMask |= MIIM_BITMAP;
       lpmii->hbmpItem = lpIme->hbmpItem;
    }


#ifdef USEWAPI
    {
        BOOL bUDC;
        int i;
        char   szTemp[IMEMENUITEM_STRING_SIZE] = {0};

        i = WideCharToMultiByte(CP_ACP,
                                0,
                                lpIme->szString,
                                (int)wcslen(lpIme->szString),
                                szTemp,
                                IMEMENUITEM_STRING_SIZE,
                                (LPSTR)NULL,
                                &bUDC);
        szTemp[i] = '\0';

        if (lstrlen(szTemp))
        {
            lpmii->fMask |= MIIM_STRING;
            StringCchCopyNA((LPSTR)lpIme->szString, ARRAYSIZE(lpIme->szString), szTemp, IMEMENUITEM_STRING_SIZE-1);
            lpmii->dwTypeData = (LPSTR)lpIme->szString;
            lpmii->cch = lstrlen((LPSTR)lpIme->szString);
        }
    }
#else
    if (lstrlen(lpIme->szString))
    {
        lpmii->fMask |= MIIM_STRING;
        lpmii->dwTypeData = lpIme->szString;
        lpmii->cch = lstrlen(lpIme->szString);
    }
#endif

}