コード例 #1
0
ファイル: cm_config.c プロジェクト: snktagarwal/openafs
long cm_CloseCellFile(cm_configFile_t *filep)
{
    char wdir[MAX_PATH];
    char sdir[MAX_PATH];
    long code;
    long closeCode = fclose((FILE *)filep);

    cm_GetConfigDir(wdir, sizeof(wdir));
    if (FAILED(StringCchCopy(sdir, sizeof(sdir), wdir)))
        return -1;

    if (closeCode != 0) {
        /* something went wrong, preserve original database */
        if (FAILED(StringCchCat(wdir, sizeof(wdir), AFS_CELLSERVDB ".new")))
            return -1;
        unlink(wdir);
        return closeCode;
    }

    if (FAILED(StringCchCat(wdir, sizeof(wdir), AFS_CELLSERVDB)))
        return -1;
    if (FAILED(StringCchCat(sdir, sizeof(sdir), AFS_CELLSERVDB ".new"))) /* new file */
        return -1;

    unlink(sdir);			/* delete old file */

    code = rename(sdir, wdir);	/* do the rename */

    if (code) 
        code = errno;

    return code;
}   
コード例 #2
0
ファイル: MyMacAddress.cpp プロジェクト: XyzalZhang/SPlayer
BOOL MyMacAddress::GetPNPDeviceID( const TCHAR *PNPDeviceID)
 {  	
	// GUID_NDIS_LAN_CLASS   ad498944-762f-11d0-8dcb-00c04fc3358c
	 TCHAR	DevicePath[MAX_PATH];
	 HANDLE	hDeviceFile;
	 BOOL	isOK = FALSE;    	// 生成设备路径名
	 ZeroMemory(DevicePath, sizeof(DevicePath));
	 StringCchCopy( DevicePath, MAX_PATH, TEXT("\\\\.\\"));
	 StringCchCat( DevicePath, MAX_PATH, PNPDeviceID );
	 StringCchCat( DevicePath, MAX_PATH, TEXT("#{ad498944-762f-11d0-8dcb-00c04fc3358c}") );
	 std::replace( DevicePath + 4, DevicePath + 4 + _tcslen(PNPDeviceID), TEXT('\\'), TEXT('#') );     	// 获取设备句柄
	 hDeviceFile = CreateFile( DevicePath, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
	 if( hDeviceFile != INVALID_HANDLE_VALUE ){
		 ULONG	dwID;
		 BYTE	ucData[8];
		 DWORD	dwByteRet;
		 dwID = OID_802_3_CURRENT_ADDRESS;
		 isOK = DeviceIoControl( hDeviceFile, IOCTL_NDIS_QUERY_GLOBAL_STATS, &dwID, sizeof(dwID), ucData, sizeof(ucData), &dwByteRet, NULL );
		 if( isOK )
		 {	  			
			 memcpy(MACAddress, ucData, dwByteRet);
		 }    
		 dwID = OID_802_3_PERMANENT_ADDRESS;  			
		 isOK = DeviceIoControl( hDeviceFile, IOCTL_NDIS_QUERY_GLOBAL_STATS, &dwID, sizeof(dwID), ucData, sizeof(ucData), &dwByteRet, NULL );
		 if( isOK )
		 {	  				
			 memcpy(PermanentAddress, ucData, dwByteRet); 
		 }  	
		 CloseHandle( hDeviceFile );  	
	 }    	
	 return isOK;  
 }
コード例 #3
0
ファイル: afsicon.c プロジェクト: bagdxk/openafs
static khm_int32 KHMAPI
collect_cell_names(khm_handle cred, void * rock)
{
    wchar_t *str = (wchar_t *) rock;
    wchar_t cell[KCDB_MAXCCH_NAME] = L"";
    FILETIME ft_now;
    FILETIME ft_expire;
    khm_size cb;

    cb = sizeof(ft_expire);
    if (KHM_FAILED(kcdb_cred_get_attr(cred, KCDB_ATTR_EXPIRE, NULL, &ft_expire, &cb)))
        return KHM_ERROR_SUCCESS;

    GetSystemTimeAsFileTime(&ft_now);
    if (CompareFileTime(&ft_now, &ft_expire) >= 0)
        return KHM_ERROR_SUCCESS;

    cb = sizeof(cell);

    if (KHM_SUCCEEDED(kcdb_cred_get_attr(cred, afs_attr_cell, NULL, cell, &cb)) &&
        cell[0]) {
        StringCchCat(str, COLLECT_STR_LEN, cell);
        StringCchCat(str, COLLECT_STR_LEN, L"\n");
    }

    return KHM_ERROR_SUCCESS;
}
コード例 #4
0
static int OnGetFileAttributes(HWND hDlg)
{
    TFileTestData * pData = GetDialogData(hDlg);
    TFlagInfo * pFlags = FileAttributesValues;
    TCHAR szFileAttributes[512] = _T("");
    DWORD dwAttr;
    int nError = ERROR_SUCCESS;

    SaveDialog(hDlg);
    dwAttr = GetFileAttributes(pData->szFileName1);
    if(dwAttr != INVALID_FILE_ATTRIBUTES)
    {
        for(int i = 0; pFlags->dwValue != 0; i++, pFlags++)
        {
            if(IS_FLAG_SET(pFlags, dwAttr))
            {
                if(szFileAttributes[0] != 0)
                    StringCchCat(szFileAttributes, _countof(szFileAttributes), _T("\n"));
                StringCchCat(szFileAttributes, _countof(szFileAttributes), pFlags->szFlagText);
            }
        }

        if(szFileAttributes[0] == 0)
            StringCchCopy(szFileAttributes, _countof(szFileAttributes), _T("0"));
        MessageBoxRc(hDlg, IDS_FILE_ATTRIBUTES, (UINT_PTR)szFileAttributes);
    }
    else
        nError = GetLastError();

    SetResultInfo(hDlg, nError);
    return TRUE;
}
コード例 #5
0
/** 
 * Get one line of text to describe the crash
 */
static void GetCrashDescription( WER_REPORT_INFORMATION& ReportInformation, const TCHAR* ErrorMessage )
{
	if( ErrorMessage != NULL )
	{
		StringCchCat( ReportInformation.wzDescription, ARRAYSIZE( ReportInformation.wzDescription ), ErrorMessage );
	}
	else
	{
		StringCchCopy( ReportInformation.wzDescription, ARRAYSIZE( ReportInformation.wzDescription ), TEXT( "The application crashed while running " ) );

		if( IsRunningCommandlet() )
		{
			StringCchCat( ReportInformation.wzDescription, ARRAYSIZE( ReportInformation.wzDescription ), TEXT( "a commandlet" ) );
		}
		else if( GIsEditor )
		{
			StringCchCat( ReportInformation.wzDescription, ARRAYSIZE( ReportInformation.wzDescription ), TEXT( "the editor" ) );
		}
		else if( GIsServer && !GIsClient )
		{
			StringCchCat( ReportInformation.wzDescription, ARRAYSIZE( ReportInformation.wzDescription ), TEXT( "a server" ) );
		}
		else
		{
			StringCchCat( ReportInformation.wzDescription, ARRAYSIZE( ReportInformation.wzDescription ), TEXT( "the game" ) );
		}
	}
}
コード例 #6
0
static BOOL GenerateFilename_OneFile(CONST HWND owner, CONST TCHAR *szDefault, UINT uiMode, TCHAR szFileOut[MAX_PATH_EX], BOOL askForFilename)
{
    TCHAR szCurrentPath[MAX_PATH_EX] = TEXT("");
	OPENFILENAME ofn;
    size_t strLen;

    StringCchLength(szDefault, MAX_PATH_EX, &strLen);
    if(strLen > 4) { // if < 4 no extended path - something went wrong
        // get rid of \\?\(UNC)
        if(strLen > 6 && !_tcsncmp(szDefault + 4, TEXT("UNC"), 3)) {
            szCurrentPath[0] = TEXT('\\');
            StringCchCopy(szCurrentPath + 1, MAX_PATH_EX, szDefault + 7);
            strLen -= 6;
        } else {
	        StringCchCopy(szCurrentPath, MAX_PATH_EX, szDefault + 4);
            strLen -= 4;
        }

        StringCchCopy(szFileOut, MAX_PATH_EX, szCurrentPath);
        szCurrentPath[strLen - 1] = TEXT('\0'); // get rid of last backslash for GetFilenameWithoutPathPointer
        StringCchCat(szFileOut, MAX_PATH_EX, GetFilenameWithoutPathPointer(szCurrentPath));
        if(szCurrentPath[strLen - 2] == TEXT(':'))
            szFileOut[4] = TEXT('\0');
    } else {
        StringCchCopy(szCurrentPath, MAX_PATH_EX, TEXT("C:\\"));
        StringCchCopy(szFileOut, MAX_PATH_EX, TEXT("C:\\default"));
    }

    TCHAR *hashExt = g_hash_ext[uiMode];

    // manually add file extension, windows dialog does not do this if the name already
    // ends in a known extension
    StringCchCat(szFileOut, MAX_PATH_EX, TEXT("."));
    StringCchCat(szFileOut, MAX_PATH_EX, hashExt);

    if(askForFilename) {
	    TCHAR msgString[MAX_PATH_EX];
	    TCHAR filterString[MAX_PATH_EX];

	    StringCchPrintf(filterString,MAX_PATH_EX,TEXT(".%s files%c*.%s%cAll files%c*.*%c"),hashExt,TEXT('\0'),hashExt,TEXT('\0'),TEXT('\0'),TEXT('\0'));
	    StringCchPrintf(msgString,MAX_PATH_EX,TEXT("Please choose a filename for the .%s file"),hashExt);

	    ZeroMemory(& ofn, sizeof (OPENFILENAME));
	    ofn.lStructSize       = sizeof (OPENFILENAME);
	    ofn.hwndOwner         = owner;
	    ofn.lpstrFilter       = filterString;
	    ofn.lpstrFile         = szFileOut;
	    ofn.nMaxFile          = MAX_PATH_EX;
        ofn.lpstrInitialDir   = szCurrentPath;
	    ofn.lpstrTitle        = msgString;
	    ofn.Flags             = OFN_OVERWRITEPROMPT | OFN_EXPLORER | OFN_NOCHANGEDIR;
	    ofn.lpstrDefExt       = hashExt;

	    if(! GetSaveFileName(& ofn) ){
		    return FALSE;
	    }
    }
    return TRUE;
}
コード例 #7
0
HANDLE GetNewestLog(_In_ TCHAR const * directory, _Out_ LPFILETIME const creationTime)
{
	creationTime->dwHighDateTime = 0;
	creationTime->dwLowDateTime = 0;

	TCHAR dirPath[MAX_PATH];
	size_t pathLength;
	if (FAILED(StringCchLength(directory, MAX_PATH, &pathLength)) || pathLength + 3 > MAX_PATH)
	{
		return INVALID_HANDLE_VALUE;
	}

	StringCchCopy(dirPath, MAX_PATH, directory);
	StringCchCat(dirPath, MAX_PATH, TEXT("\\*"));

	TCHAR newestLog[MAX_PATH];
	newestLog[0] = '\0';
	WIN32_FIND_DATA ffd;
	size_t nameLength;

	HANDLE searchHandle = FindFirstFile(dirPath, &ffd);
	if (searchHandle == INVALID_HANDLE_VALUE)
	{
		Log("ERROR | GetNewestLog | Couldn't enumerate files in", dirPath);
		LogLastError();
		return nullptr;
	}
	do
	{
		if (SUCCEEDED(StringCchLength(ffd.cFileName, MAX_PATH, &nameLength)) && 
			_tcscmp(ffd.cFileName + nameLength - 4, TEXT(".txt")) == 0 && 
			CompareFileTime(&ffd.ftCreationTime, creationTime) == 1)
		{
			StringCchCopy(newestLog, MAX_PATH, ffd.cFileName);
			*creationTime = ffd.ftCreationTime;
		}
	} 
	while (FindNextFile(searchHandle, &ffd) != 0);
	FindClose(searchHandle);

	TCHAR path[MAX_PATH];
	if (FAILED(StringCchLength(newestLog, MAX_PATH, &nameLength)) || pathLength + nameLength > MAX_PATH)
	{
		return INVALID_HANDLE_VALUE;
	}
	StringCchCopy(path, MAX_PATH, directory);
	StringCchCat(path, MAX_PATH, TEXT("\\"));
	StringCchCat(path, MAX_PATH, newestLog);

	Log("INFO  | GetNewestLog | Found newest log file at", path);
	
	return CreateFile(path,
					  GENERIC_READ, // we only need to read
					  FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, // let LoL do whatever it pleases (Mundo!)
					  nullptr,
					  OPEN_EXISTING,
					  FILE_ATTRIBUTE_NORMAL,
					  nullptr);
}
コード例 #8
0
//------------------------------------------------------------------------------
// Name: SetTime()
// Desc: Update the slider and duration label with new time value.
//------------------------------------------------------------------------------
void SetTime( QWORD cnsTimeElapsed, QWORD cnsFileDuration )
{
	//
	// Do not set new time if seeking is going on
	//
	if( g_IsSeeking )
	{
		return;
	}

    DWORD dwSeconds = 0;
    TCHAR tszTime[20];
	TCHAR tszTemp[10];
	UINT  nHours = 0;
    UINT  nMins = 0;
	
	ZeroMemory( (void *)tszTime, sizeof( tszTime ) );

    dwSeconds = ( DWORD )( cnsTimeElapsed / 10000000 );
	nHours = dwSeconds / 60 / 60;
	dwSeconds %= 3600;
	nMins = dwSeconds / 60;
	dwSeconds %= 60;

    //
    // Format the string
    //
	if( 0 != nHours )
	{
		(void)StringCchPrintf( tszTemp, ARRAYSIZE(tszTemp), _T( "%d:" ), nHours );
		(void)StringCchCat( tszTime, ARRAYSIZE(tszTime), tszTemp );
	}
	
	(void)StringCchPrintf( tszTemp, ARRAYSIZE(tszTemp), _T( "%02d:%02d / " ), nMins, dwSeconds );
	(void)StringCchCat( tszTime, ARRAYSIZE(tszTime), tszTemp );
	
	nHours = 0;
    nMins = 0;

    dwSeconds = ( DWORD )( cnsFileDuration / 10000000 );
	nHours = dwSeconds / 60 / 60;
	dwSeconds %= 3600;
	nMins = dwSeconds / 60;
	dwSeconds %= 60;

    if( 0 != nHours )
	{
		(void)StringCchPrintf( tszTemp, ARRAYSIZE(tszTemp), _T( "%d:" ), nHours );
		(void)StringCchCat( tszTime, ARRAYSIZE(tszTime), tszTemp );
	}
	
	(void)StringCchPrintf( tszTemp, ARRAYSIZE(tszTemp), _T( "%02d:%02d" ), nMins, dwSeconds );
	(void)StringCchCat( tszTime, ARRAYSIZE(tszTime), tszTemp );

    SendDlgItemMessage( g_hwndDialog, IDC_SLIDER , TBM_SETPOS, TRUE, ( LONG )( cnsTimeElapsed / 10000 ) );
	SendDlgItemMessage( g_hwndDialog, IDC_DURATION, WM_SETTEXT, 0, ( WPARAM )tszTime );

    return;
}
コード例 #9
0
// удаляет ключ
void DeleteRegKey(HKEY hRoot,TCHAR *Key)
{
	TCHAR FullKeyName[512];
	StringCchCopy(FullKeyName,ARRAYSIZE(FullKeyName),PluginRootKey);
	StringCchCat(FullKeyName,ARRAYSIZE(FullKeyName),(Key && *Key ? _T("\\"):_T("")));
	StringCchCat(FullKeyName,ARRAYSIZE(FullKeyName),Key);
	RegDeleteKey(hRoot,FullKeyName);
}
コード例 #10
0
DWORD watcher(LPVOID arg) {
    HANDLE heap = GetProcessHeap(), handle;
    STARTUPINFO startupinfo;
    LPPROCESS_INFORMATION cc_procinfo;
    LPTSTR lpCmdLine = arg;
    LPTSTR argv0;
    LPTSTR srcpath;
    LPTSTR cc_cmdline;
    TCHAR tmpdir[MAX_PATH];
    TCHAR fullExecutablePath[MAX_PATH];

    PTSTR spc = StrChr(lpCmdLine, ' ');
    if(spc == NULL) {
        argv0 = HeapAlloc(heap, 0, lstrlen(lpCmdLine)+1);
        StringCbCat(argv0, lstrlen(lpCmdLine), lpCmdLine);
    } else {
        argv0 = HeapAlloc(heap, 0, spc-lpCmdLine+1);
        StringCbCat(argv0, spc-lpCmdLine, lpCmdLine);
    }

    GetModuleFileName(NULL, fullExecutablePath, MAX_PATH);
    size_t len = lstrlen(fullExecutablePath)+1;
    srcpath = HeapAlloc(heap, 0, len);
    StringCbCat(srcpath, len-4, fullExecutablePath);
    StringCchCat(srcpath, len, ".c");

    printf("srcpath is \"%s\"\n", srcpath);

    //WaitForSingleFile(srcpath, FILE_NOTIFY_LAST_WRITE);

    ZeroMemory(&startupinfo, sizeof(STARTUPINFO));
    startupinfo.cb = sizeof(STARTUPINFO);

    size_t cclen = lstrlen(CC)+1+len-1+4+lstrlen(argv0)+1;
    cc_cmdline = HeapAlloc(heap, 0, cclen);
    StringCbCat(cc_cmdline,  cclen, CC);
    StringCchCat(cc_cmdline, cclen, " ");
    StringCchCat(cc_cmdline, cclen, srcpath);
    StringCchCat(cc_cmdline, cclen, " -o ");
    StringCchCat(cc_cmdline, cclen, argv0);

    printf("cc_cmdline is \"%s\"\n", cc_cmdline);

    return 0;

    CreateProcess(NULL, cc_cmdline, NULL, NULL, TRUE, 0,
                  NULL, NULL, &startupinfo, cc_procinfo);
    HeapFree(heap, 0, argv0);
    HeapFree(heap, 0, srcpath);
    HeapFree(heap, 0, cc_cmdline);
    WaitForSingleObject(cc_procinfo->hProcess, INFINITE);

    printf("Execing...\n");

    CreateProcess(NULL, lpCmdLine, NULL, NULL, TRUE, 0,
                  NULL, NULL, &startupinfo, cc_procinfo);
    ExitProcess(0);
}
コード例 #11
0
/// Function name  : resolveGameStringSubStrings
// Description     : Expands sub-strings within the source-text and strips out any comments
// 
// CONST GAME_STRING*  pGameString    : [in]     GameString currently being resolved
// TCHAR*              szOutput       : [in/out] Output buffer 
// CONST UINT          iOutputLength  : [in]     Length of output buffer, in characters
// STACK*              pHistoryStack  : [in/out] Represents the 'chain' of GameStrings being resolved
// ERROR_QUEUE*        pErrorQueue    : [in/out] ErrorQueue, may already contain errors
// 
// Return Value : Number of sub-strings that could not be resolved
//
UINT  resolveGameStringSubStrings(CONST GAME_STRING*  pGameString, TCHAR*  szOutput, CONST UINT  iOutputLength, STACK*  pHistoryStack, ERROR_QUEUE*  pErrorQueue)
{
   SUBSTRING*    pSubString;           // SubString iterator
   GAME_STRING*  pSourceString;        // First game string in the list
   TCHAR*        szPreview;            // Preview text for error reporting
   UINT          iMissingSubstrings;

   // Prepare
   iMissingSubstrings = 0;

   /// [CHECK] Ensure sub-string is not self-referencial
   if (isValueInList(pHistoryStack, (LPARAM)pGameString))
   {
      // Lookup initial GameString
      findListObjectByIndex(pHistoryStack, 0, (LPARAM&)pSourceString);

      // [ERROR] "Circular sub-string references detected in page %u, string %u : '%s'"
      generateQueuedError(pErrorQueue, HERE(IDS_GAME_STRING_SUBSTRING_RECURSIVE), pSourceString->iPageID, pSourceString->iID, szPreview = generateGameStringPreview(pGameString, 96));
      utilDeleteString(szPreview);
      return FALSE;
   }
   
   // Prepare
   pSubString = createSubString(pGameString->szText);

   /// [STACK] Add GameString to history stack
   pushObjectOntoStack(pHistoryStack, (LPARAM)pGameString);

   /// Iterate through sub-strings
   while (findNextSubString(pGameString, pSubString, iMissingSubstrings, pHistoryStack, pErrorQueue))
   {
      // Examine type
      switch (pSubString->eType)
      {
      /// [MISSION, TEXT] Append to output
      case SST_MISSION:
      case SST_LOOKUP:
      case SST_TEXT:
         StringCchCat(szOutput, MAX_STRING, pSubString->szText);  
         break;

      /// [COMMENTS] Ignore
      case SST_COMMENT:
         // [SPECIAL CASE] Allow 'opening bracket' operator
         if (utilCompareString(pSubString->szText, "("))
            StringCchCat(szOutput, MAX_STRING, pSubString->szText);  
         break;
      }
   }
   
   // [STACK] Remove GameString from processing stack
   popObjectFromStack(pHistoryStack);

   // Cleanup
   deleteSubString(pSubString);
   return iMissingSubstrings;
}
コード例 #12
0
ファイル: testapp.c プロジェクト: kcrazy/winekit
HANDLE
open_file( 
    __in char *filename
    )
/*++
Routine Description:

    Called by main() to open an instance of our device after obtaining its name

Arguments:

    None

Return Value:

    Device handle on success else NULL

--*/
{
    int success = 1;
    HANDLE h;

    if ( !GetUsbDeviceFileName(
            (LPGUID) &GUID_CLASS_USBSAMP_USB,
            completeDeviceName) )
    {
            NOISY(("Failed to GetUsbDeviceFileName err - %d\n", GetLastError()));
            return  INVALID_HANDLE_VALUE;
    }

    (void) StringCchCat (completeDeviceName, MAX_LENGTH, "\\" );                      

    if(FAILED(StringCchCat (completeDeviceName, MAX_LENGTH, filename))) {
        NOISY(("Failed to open handle - possibly long filename\n"));
        return INVALID_HANDLE_VALUE;
    }

    printf("completeDeviceName = (%s)\n", completeDeviceName);

    h = CreateFile(completeDeviceName,
            GENERIC_WRITE | GENERIC_READ,
            FILE_SHARE_WRITE | FILE_SHARE_READ,
            NULL,
            OPEN_EXISTING,
            0,
            NULL);

    if (h == INVALID_HANDLE_VALUE) {
        NOISY(("Failed to open (%s) = %d", completeDeviceName, GetLastError()));
        success = 0;
    } else {
        NOISY(("Opened successfully.\n"));
    }           

    return h;
}
コード例 #13
0
ファイル: XML Parser.cpp プロジェクト: nick-crowley/X-Studio
/// Function name  :  performXMLCharacterEntityReplacement
// Description     : 
// 
// TCHAR*      szInput      : [in] 
// CONST UINT  iInputLength : [in] 
// 
// Return Value   : New string length
// 
UINT   performXMLCharacterEntityReplacement(TCHAR*  szInput, CONST UINT  iInputLength)
{
   CONST TCHAR  *szPosition,        // Current position
                *szEntity,          // Entity being parsed
                *szSemiColon;       // Semicolon marking the end of the entity
   TCHAR        *szBuffer,          // Output Assembly buffer
                 szCharacter[2];    // Converted entity character as a string
   
   // Prepare
   szCharacter[1] = NULL;
   szPosition     = szInput;

   // Create working buffer
   szBuffer = utilCreateEmptyString(iInputLength);

   /// [CHECK] Find next entity
   while (szPosition AND (szEntity = utilFindSubString(szPosition, "&#")))
   {
      // Copy preceeding characters to output
      if (szEntity - szPosition)
         StringCchCatN(szBuffer, iInputLength, szPosition, szEntity - szPosition);

      /// [CHECK] Find end marker
      if (szSemiColon = utilFindCharacter(szEntity, ';'))
      {
         // [CHECK] Examine encoding type
         if (szEntity[2] == 'x')
            // [HEX]  &#xhhhh
            utilScanf(&szEntity[3], TEXT("%04x"), &szCharacter[0]);
         else
            // [DECIMAL]  &#nnnn
            szCharacter[0] = utilConvertStringToInteger(&szEntity[2]);

         /// [FOUND] Append entity and update position
         StringCchCat(szBuffer, iInputLength, szCharacter);
         szPosition = &szSemiColon[1];
      }
      else
      {
         /// [NOT FOUND] Copy marker and remainder of string to the output buffer
         StringCchCat(szBuffer, iInputLength, szEntity);
         szPosition = NULL;
      }
   }

   /// [COMPLETE] Overwrite input buffer
   StringCchCopy(szInput, iInputLength, szBuffer);

   /// Append remainder of string
   if (szPosition)
      StringCchCat(szInput, iInputLength, szPosition);
   
   // Cleanup and return length
   utilDeleteString(szBuffer);
   return lstrlen(szInput);
}
コード例 #14
0
INT_PTR CAboutDialog::OnInitDialog()
{
	m_hIcon = reinterpret_cast<HICON>(LoadImage(GetModuleHandle(0),
		MAKEINTRESOURCE(IDI_MAIN),IMAGE_ICON,
		32,32,LR_VGACOLOR));

	SendMessage(m_hDlg,WM_SETICON,ICON_SMALL,reinterpret_cast<LPARAM>(m_hIcon));

	/* If the dialog has been loaded from a resource other than
	the one in the executable (which will be the case, for example,
	if a translation DLL has been loaded), then the image that
	normally appears won't be shown. This is because the static
	control will attempt to load it from its resource section (where
	the image doesn't exist). Manually set the image here. */
	if(GetInstance() != GetModuleHandle(0))
	{
		HBITMAP hbm = LoadBitmap(GetModuleHandle(0),MAKEINTRESOURCE(IDB_ABOUT));
		SendDlgItemMessage(m_hDlg,IDC_ABOUT_STATIC_IMAGE,STM_SETIMAGE,
			IMAGE_BITMAP,reinterpret_cast<LPARAM>(hbm));
	}

	TCHAR szVersion[64];
	TCHAR szBuild[64];
	TCHAR szBuildDate[64];
	TCHAR szTemp[64];

	/* Indicate which architecture (32-bit or
	64-bit) we are building for in the version
	string.*/
#ifdef WIN64
	LoadString(GetInstance(),IDS_ABOUT_64BIT_BUILD,
		szBuild,SIZEOF_ARRAY(szBuild));
#else
	LoadString(GetInstance(),IDS_ABOUT_32BIT_BUILD,
		szBuild,SIZEOF_ARRAY(szBuild));
#endif

	LoadString(GetInstance(),IDS_ABOUT_UNICODE_BUILD,
		szTemp,SIZEOF_ARRAY(szTemp));
	StringCchCat(szBuild,SIZEOF_ARRAY(szBuild),_T(" "));
	StringCchCat(szBuild,SIZEOF_ARRAY(szBuild),szTemp);

	GetDlgItemText(m_hDlg,IDC_STATIC_VERSIONNUMBER,szTemp,SIZEOF_ARRAY(szTemp));
	StringCchPrintf(szVersion,SIZEOF_ARRAY(szVersion),szTemp,VERSION_STRING_W,szBuild);
	SetDlgItemText(m_hDlg,IDC_STATIC_VERSIONNUMBER,szVersion);

	GetDlgItemText(m_hDlg,IDC_STATIC_BUILDDATE,szTemp,SIZEOF_ARRAY(szTemp));
	StringCchPrintf(szBuildDate,SIZEOF_ARRAY(szBuildDate),szTemp,BUILD_DATE_STRING);

	SetDlgItemText(m_hDlg,IDC_STATIC_BUILDDATE,szBuildDate);

	CenterWindow(GetParent(m_hDlg),m_hDlg);

	return TRUE;
}
コード例 #15
0
// ---------------------------------------------
// Append the text to the logging window
// ---------------------------------------------
VOID CGreenPrintWindowLogging::Log( LPWSTR Text )
{
	DWORD ErrorCode = GetLastError();

	if ( NULL != Text && NULL != m_hWndEdit )
	{
		SYSTEMTIME CurrentTimeUTC;
		GetSystemTime( &CurrentTimeUTC );

		SYSTEMTIME CurrentTimeLocal;
		SystemTimeToTzSpecificLocalTime( NULL, &CurrentTimeUTC, &CurrentTimeLocal );

		WCHAR TimeText[ 128 ] = { 0 };
		StringCchPrintf( TimeText, _countof(TimeText), L"%02d/%02d/%d  %02d:%02d:%02d: ",
			CurrentTimeLocal.wMonth, CurrentTimeLocal.wDay, CurrentTimeLocal.wYear,
			CurrentTimeLocal.wHour, CurrentTimeLocal.wMinute, CurrentTimeLocal.wSecond );
		
		WCHAR ErrorText[ 64 ] = { 0 };
		if ( NO_ERROR != ErrorCode )
		{
			StringCchPrintf( ErrorText, _countof(ErrorText), L" (%d)", ErrorCode );
		}

		WCHAR *NewLine = L"\r\n";

		DWORD cchNewText = GetWindowTextLength( m_hWndEdit ) + wcslen(TimeText) + wcslen(Text) + wcslen(ErrorText) + wcslen(NewLine) + 1;

		WCHAR *NewText = (WCHAR*)LocalAlloc( LMEM_ZEROINIT, cchNewText * sizeof(WCHAR) );

		if ( NULL != NewText )
		{
			GetWindowText( m_hWndEdit, NewText, cchNewText );

			if ( SUCCEEDED( StringCchCat( NewText, cchNewText, TimeText ) ) )
			{
				if ( SUCCEEDED( StringCchCat( NewText, cchNewText, Text ) ) )
				{
					if ( SUCCEEDED( StringCchCat( NewText, cchNewText, ErrorText ) ) )
					{
						if ( SUCCEEDED( StringCchCat( NewText, cchNewText, NewLine ) ) )
						{
							SetWindowText( m_hWndEdit, NewText );
						}
					}
				}
			}

			LocalFree( NewText );
			NewText = NULL;
		}
	}
}
コード例 #16
0
bool SendFileName(HWND hWnd, LPCWSTR str, int pos)
{
	static wchar_t crpath[2000];
	GetCurrentDirectory(MAX_PATH, crpath);
	StringCchCat(crpath, 2000, L"\\");
	StringCchCat(crpath, 2000, str);

	COPYDATASTRUCT ds;
	ds.dwData = 1;
	ds.cbData = ( lstrlen(crpath) + 1 ) * sizeof(wchar_t);
	ds.lpData = (PVOID)crpath; 
	return MySendMessage(hWnd, WM_COPYDATA, pos, (LPARAM)&ds );
}
コード例 #17
0
// открыть заданную ветвь реестра
HKEY OpenRegKey(HKEY hRoot,TCHAR *Key)
{
	HKEY hKey;
	TCHAR FullKeyName[512];
	StringCchCopy(FullKeyName,ARRAYSIZE(FullKeyName),PluginRootKey);
	StringCchCat(FullKeyName,ARRAYSIZE(FullKeyName),(Key && *Key ? _T("\\"):_T("")));
	StringCchCat(FullKeyName,ARRAYSIZE(FullKeyName),Key);

	if(RegOpenKeyEx(hRoot,FullKeyName,0,KEY_QUERY_VALUE,&hKey)!=ERROR_SUCCESS)
		return(NULL);

	return(hKey);
}
コード例 #18
0
ファイル: wf_cliprdr.c プロジェクト: Alialusi/FreeRDP
static void wf_cliprdr_traverse_directory(cliprdrContext *cliprdr, wchar_t *Dir, int pathLen)
{
	WIN32_FIND_DATA FindFileData;
	HANDLE hFind;
	wchar_t DirSpec[MAX_PATH];

	StringCchCopy(DirSpec,MAX_PATH,Dir);
	StringCchCat(DirSpec,MAX_PATH,TEXT("\\*"));

	hFind = FindFirstFile(DirSpec,&FindFileData);

	if(hFind == INVALID_HANDLE_VALUE)
	{
		DEBUG_CLIPRDR("FindFirstFile failed with 0x%x.", GetLastError());
		return;
	}

	while(FindNextFile(hFind, &FindFileData))
	{
		if((FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0
			&& wcscmp(FindFileData.cFileName,L".") == 0
			|| wcscmp(FindFileData.cFileName,L"..") == 0)
		{
			continue;
		}


		if((FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) !=0 )
		{
			wchar_t DirAdd[MAX_PATH];

			StringCchCopy(DirAdd,MAX_PATH,Dir);
			StringCchCat(DirAdd,MAX_PATH,TEXT("\\"));
			StringCchCat(DirAdd,MAX_PATH,FindFileData.cFileName);
			wf_cliprdr_add_to_file_arrays(cliprdr, DirAdd, pathLen);
			wf_cliprdr_traverse_directory(cliprdr, DirAdd, pathLen);
		}
		else
		{
			WCHAR fileName[MAX_PATH];

			StringCchCopy(fileName,MAX_PATH,Dir);
			StringCchCat(fileName,MAX_PATH,TEXT("\\"));
			StringCchCat(fileName,MAX_PATH,FindFileData.cFileName);

			wf_cliprdr_add_to_file_arrays(cliprdr, fileName, pathLen);
		}
	}

	FindClose(hFind);
}
コード例 #19
0
ファイル: DlgUnZip.cpp プロジェクト: joeswang/MBoo
LRESULT CDlgUnZip::OnUpdatePGSUnzip(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
{
WORD total, current;
LPCTSTR zipfilename;
TCHAR msg[MAX_PATH] = { 0 };

	zipfilename = (LPCTSTR)wParam;
	if(NULL != zipfilename)
	{
		memset(msg, 0, sizeof(msg));
		StringCchCat(msg, MAX_PATH, _T("ÕýÔÚ½âѹËõ : "));
		StringCchCat(msg, MAX_PATH, zipfilename);
		StringCchCat(msg, MAX_PATH, _T(" ......"));
		GetDlgItem(IDC_UNZIP_STATIC_PERCENT).SetWindowText(msg);
	}

	total = HIWORD(lParam); current = LOWORD(lParam);
	if(0 == total && 0 == current)
	{
		GetDlgItem(IDC_UNZIP_STATIC_VIDEPZIP).ShowWindow(SW_SHOW);
		GetDlgItem(IDC_UNZIP_STATIC_PERCENT).ShowWindow(SW_SHOW);
		GetDlgItem(IDC_UNZIP_PGS_PERCENT).ShowWindow(SW_SHOW);
		GetDlgItem(IDC_UNZIP_PGS_VIDEOZIP).ShowWindow(SW_SHOW);

		GetDlgItem(IDC_UNZIP_BTN_UNCOMPRESS).EnableWindow(FALSE);
		GetDlgItem(IDOK).EnableWindow(FALSE);
		GetDlgItem(IDCANCEL).EnableWindow(FALSE);
		return 0;
	}

	if(100 == total && 100 == current)
	{
		GetDlgItem(IDC_UNZIP_STATIC_VIDEPZIP).ShowWindow(SW_HIDE);
		GetDlgItem(IDC_UNZIP_STATIC_PERCENT).ShowWindow(SW_HIDE);
		GetDlgItem(IDC_UNZIP_PGS_PERCENT).ShowWindow(SW_HIDE);
		GetDlgItem(IDC_UNZIP_PGS_VIDEOZIP).ShowWindow(SW_HIDE);
		//GetDlgItem(IDC_UNZIP_BTN_UNCOMPRESS).EnableWindow();
		GetDlgItem(IDOK).EnableWindow();
		GetDlgItem(IDCANCEL).EnableWindow();
		return 0;
	}
	CProgressBarCtrl pgs1 = GetDlgItem(IDC_UNZIP_PGS_PERCENT);
	CProgressBarCtrl pgs2 = GetDlgItem(IDC_UNZIP_PGS_VIDEOZIP);
	//pgs1.SetRange(0, 100);
	pgs1.SetPos(current);
	//pgs2.SetRange(0, 100);
	pgs2.SetPos(total);

	return 0;
}
コード例 #20
0
BOOL InstallService()
{
    SC_HANDLE newService;
    SC_HANDLE scm;
    TCHAR szBuffer[255];
    TCHAR szPath[MAX_PATH];

    GetModuleFileName( GetModuleHandle(NULL), szPath, MAX_PATH );
    if (FAILED( StringCchCopy(szBuffer, 255, TEXT("\"")))) {
        return FALSE;
    }
    if (FAILED( StringCchCat(szBuffer, 255, szPath))) {
        return FALSE;
    }
    if (FAILED( StringCchCat(szBuffer, 255, TEXT("\"")))) {
        return FALSE;
    }

    scm = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE);
    if (scm == NULL) {
        ErrorHandler("OpenSCManager", GetLastError());
    }
    newService = CreateService(
                            scm,
                            ServiceName,
                            ServiceName,
                            SERVICE_ALL_ACCESS,
                            SERVICE_WIN32_OWN_PROCESS,
                            SERVICE_AUTO_START,
                            SERVICE_ERROR_NORMAL,
                            szBuffer,
                            NULL,
                            NULL,
                            NULL,
                            NULL,
                            NULL);
    if (!newService) {
        ErrorHandler("CreateService", GetLastError());
        return FALSE;
    } else {
        printf("Service Installed\n");
        ServiceRun();
    }

    CloseServiceHandle(newService);
    CloseServiceHandle(scm);

    return TRUE;
}
コード例 #21
0
// создать ключ
HKEY CreateRegKey(HKEY hRoot,TCHAR *Key)
{
	HKEY hKey;
	DWORD Disposition;
	TCHAR FullKeyName[512];
	StringCchCopy(FullKeyName,ARRAYSIZE(FullKeyName),PluginRootKey);
	StringCchCat(FullKeyName,ARRAYSIZE(FullKeyName),(Key && *Key ? _T("\\"):_T("")));
	StringCchCat(FullKeyName,ARRAYSIZE(FullKeyName),Key);

	if(RegCreateKeyEx(hRoot,FullKeyName,0,NULL,0,KEY_WRITE,NULL,
	                  &hKey,&Disposition) != ERROR_SUCCESS)
		hKey=NULL;

	return(hKey);
}
コード例 #22
0
BOOL CBatchRunBtn::GetHotKeyData(int idx, HOTKEY_DATA* hkData)
{
	switch(idx)
	{
	case 0:
		hkData->hotKey = m_hotKey;
		hkData->hotKeyID = HOTKEY_RUN;
		hkData->id = HOTKEY_RUN;
		StringCchCopy(hkData->name, 260, m_xui.getStringDef(XUI_STR_HOTKEYNAME));
		StringCchCat(hkData->name, 260, L": ");
		StringCchCat(hkData->name, 260, m_Name);
		break;
	}
	return TRUE;
}
コード例 #23
0
void CStrSafeTester::test_StringCchCat()
{
    HRESULT hr = E_FAIL;
    TCHAR bufMax[MAX_BUFFER_SIZE] = {0};

    hr = StringCchCat(bufMax,_countof(bufMax),TEST_STRING);
    CPPUNIT_ASSERT(hr == S_OK);
    CPPUNIT_ASSERT(_tcscmp(bufMax,TEXT("abcde12345")) == 0);
    CPPUNIT_ASSERT(_tcslen(bufMax) == TEST_STRING_LENGTH);

    hr = StringCchCat(bufMax,_countof(bufMax),TEST_STRING);
    CPPUNIT_ASSERT(hr == STRSAFE_E_INSUFFICIENT_BUFFER);
    CPPUNIT_ASSERT(_tcscmp(bufMax,TEXT("abcde12345abcd")) == 0);
    CPPUNIT_ASSERT(_tcslen(bufMax) == MAX_BUFFER_SIZE - 1);
    CPPUNIT_ASSERT(bufMax[MAX_BUFFER_SIZE - 1] == 0);
}
コード例 #24
0
void AddMeritToString(WCHAR *szInfo, size_t len, DWORD dwMerit)
{
    WCHAR szMerit[32];
    HRESULT hr;

    switch (dwMerit)
    {
        case MERIT_NORMAL:
             hr = StringCchCopy(szMerit, NUMELMS(szMerit), L"MERIT_NORMAL\0");
             break;     // Assume normal
        case MERIT_PREFERRED:
             hr = StringCchCopy(szMerit, NUMELMS(szMerit), L"MERIT_PREFERRED\0");
             break;
        case MERIT_UNLIKELY:
             hr = StringCchCopy(szMerit, NUMELMS(szMerit), L"MERIT_UNLIKELY\0");
             break;
        case MERIT_DO_NOT_USE:
             hr = StringCchCopy(szMerit, NUMELMS(szMerit), L"MERIT_DO_NOT_USE\0");
             break;
        case MERIT_SW_COMPRESSOR:
             hr = StringCchCopy(szMerit, NUMELMS(szMerit), L"MERIT_SW_COMPRESSOR\0");
             break;
        case MERIT_HW_COMPRESSOR:
             hr = StringCchCopy(szMerit, NUMELMS(szMerit), L"MERIT_HW_COMPRESSOR\0");
             break;
        
        default:
             hr = StringCchPrintf(szMerit, NUMELMS(szMerit), L"0x%08x\0", dwMerit);
             break;
    }

    // Add new merit information to string
    hr = StringCchCat(szInfo, len , szMerit);
}
コード例 #25
0
ファイル: wxdebug.cpp プロジェクト: 276361270/vcap
//
// warning -- this function is implemented twice for ansi applications
// linking to the unicode library
//
void WINAPI DbgLogInfo(DWORD Type,DWORD Level,LPCTSTR pFormat,...)
{

    /* Check the current level for this type combination */

    BOOL bAccept = DbgCheckModuleLevel(Type,Level);
    if (bAccept == FALSE) {
        return;
    }

    TCHAR szInfo[2000];

    /* Format the variable length parameter list */

    va_list va;
    va_start(va, pFormat);

    (void)StringCchPrintf(szInfo, NUMELMS(szInfo),
             TEXT("%s(tid %x) %8d : "),
             m_ModuleName,
             GetCurrentThreadId(), timeGetTime() - dwTimeOffset);

    (void)StringCchVPrintf(szInfo + lstrlen(szInfo), NUMELMS(szInfo) - lstrlen(szInfo), pFormat, va);
    (void)StringCchCat(szInfo, NUMELMS(szInfo), TEXT("\r\n"));
    DbgOutString(szInfo);

    va_end(va);
}
コード例 #26
0
BOOL MainWindow::SetDimText()
{
	WCHAR szText[64];
	WCHAR szText2[32];
	INT nxy, nz;
	FLOAT res, size_xy, size_z;
	SendMessage(m_hDimensions[0],WM_GETTEXT,64,(LPARAM)szText);
	nxy = _wtoi(szText);
	SendMessage(m_hDimensions[1],WM_GETTEXT,64,(LPARAM)szText);
	nz = _wtoi(szText);
	SendMessage(m_hDimensions[2],WM_GETTEXT,64,(LPARAM)szText);
	res = _wtof(szText);

	size_xy = nxy * res;
	size_z = nz * res;
	if(size_xy>1000)
	{
		size_xy /= 1000.0;
		StringCchPrintf(szText,64,L"Reconstruction volume:\n%1.3f m \u00D7 %1.3f m ", size_xy, size_xy);
	}
	else
		StringCchPrintf(szText,64,L"Reconstruction volume:\n%3.1f mm \u00D7 %3.1f mm ", size_xy, size_xy);
	if(size_z>1000)
	{
		size_z /= 1000.0;
		StringCchPrintf(szText2,32,L"\u00D7 %1.3f m", size_z);
	}
	else
		StringCchPrintf(szText2,32,L"\u00D7 %3.1f mm", size_z);
	StringCchCat(szText,sizeof(szText),szText2);
	SendMessage(m_hReconText[5],WM_SETTEXT,NULL,(LPARAM)szText);

	return TRUE;
}
コード例 #27
0
ファイル: QuickLaunch.cpp プロジェクト: nbclark/flipper
void CQuickLaunch::SaveLaunchItems(HKEY hKey, list<LaunchItem*>* pLaunchItems)
{
	WCHAR wzName[MAX_PATH];
	DWORD dwName = sizeof(wzName);
	DWORD dwType;
	int index = 0;

	while (ERROR_SUCCESS == RegEnumValue(hKey, index, wzName, &dwName, NULL, &dwType, NULL, NULL))
	{
		dwName = sizeof(wzName);
		RegDeleteValue(hKey, wzName);
	}
	int count = pLaunchItems->size();
	RegistrySetDWORD(hKey, NULL, L"Count", count);

	index = 0;
	list<LaunchItem*>::iterator iter = pLaunchItems->begin();

	while (iter != pLaunchItems->end())
	{
		WCHAR wzPath[10], wzCount[5];
		DWORD dwSize = 0;
		_itow(index, wzCount, 10);

		StringCchCopy(wzPath, ARRAYSIZE(wzPath), wzCount);
		StringCchCat(wzPath, ARRAYSIZE(wzPath), L"_Path");

		LaunchItem* pRecord = *iter;
		RegistrySetString(hKey, NULL, wzPath, pRecord->wzPath);

		iter++;
		index++;
	}
}
コード例 #28
0
	void listFiles(ClientThreadResource * res , ListenSocket * clientSocket){
		WIN32_FIND_DATA ffd;
		LARGE_INTEGER filesize;
		TCHAR szDir[MAX_PATH];
		size_t length_of_arg;
		HANDLE hFind = INVALID_HANDLE_VALUE;
		DWORD dwError=0;

		StringCchCopy(szDir, MAX_PATH, res->argument );
		StringCchCat(szDir, MAX_PATH, TEXT("\\*"));

		hFind = FindFirstFile(szDir, &ffd);
		if ( INVALID_HANDLE_VALUE == hFind ) {
			printf("Error de FindFirstFile...\n");
		}

		do {
			if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY){
				_tprintf(TEXT("  %s   <DIR>\n"), ffd.cFileName); //reemplazar por el sendMessage
			} else {
				filesize.LowPart = ffd.nFileSizeLow;
				filesize.HighPart = ffd.nFileSizeHigh;
				_tprintf(TEXT("  %s   %ld bytes\n"), ffd.cFileName, filesize.QuadPart); //reemplazar por el sendMessage
			}
		} while (FindNextFile(hFind, &ffd) != 0);

		dwError = GetLastError();
		FindClose(hFind);

		if (dwError != ERROR_NO_MORE_FILES) {
			res->resultMessage = newString( res->heapHandler , (char *)RESULT_SUCCESSFULLY , 1);
		} else {
			res->resultMessage = newString( res->heapHandler , (char *)RESULT_WITH_ERRORS , 1);
		}
	}
コード例 #29
0
ファイル: Directory.cpp プロジェクト: alexandervnuchkov/core
    StringArray Directory::GetFilesInDirectory(LPCTSTR path, const bool& andSubdirectories) {
        size_t pathLength = 0;
        StringCchLength(path, MAX_PATH, &pathLength);
        ++pathLength;
        size_t pathToFilesLength = pathLength + 3;
        LPTSTR pathToFiles = new TCHAR[pathToFilesLength];

        StringCchCopy(pathToFiles, pathLength, path);
        StringCchCat(pathToFiles, pathToFilesLength, TEXT("\\*"));

        WIN32_FIND_DATA findData;
        HANDLE findResult = FindFirstFile(pathToFiles, &findData);
        delete[] pathToFiles;

        if (findResult == INVALID_HANDLE_VALUE)
            return StringArray();

        StringArray files;
        do {
            if (andSubdirectories || !(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
                String file = findData.cFileName;
                files.insert(files.end(), file);
            }
        } while (FindNextFile(findResult, &findData));

        FindClose(findResult);

        return files;
    }
コード例 #30
0
//
// Function to create a readable IStream over the file whose name is the
// concatenation of the path and fileName parameters.  For simplicity, file
// names including path are assumed to be 100 characters or less.  A real
// application should be able to handle longer names and allocate the
// necessary buffer dynamically.
//
// Parameters:
// path - Path of the folder containing the file to be opened, ending with a
//        slash ('\') character
// fileName - Name, not including path, of the file to be opened
// stream - Output parameter pointing to the created instance of IStream over
//          the specified file when this function succeeds.
//
HRESULT GetFileStream(
    _In_ LPCWSTR path,
    _In_ LPCWSTR fileName,
    _Outptr_ IStream** stream)
{
    HRESULT hr = S_OK;
    const int MaxFileNameLength = 100;
    WCHAR fullFileName[MaxFileNameLength + 1];

    // Create full file name by concatenating path and fileName
    hr = StringCchCopyW(fullFileName, MaxFileNameLength, path);
    if (SUCCEEDED(hr))
    {
        hr = StringCchCat(fullFileName, MaxFileNameLength, fileName);
    }

    // Create stream for reading the file
    if (SUCCEEDED(hr))
    {
        hr = SHCreateStreamOnFileEx(
                fullFileName,
                STGM_READ | STGM_SHARE_EXCLUSIVE,
                0, // default file attributes
                FALSE, // do not create new file
                NULL, // no template
                stream);
    }
    return hr;
}