HRESULT GetFileName(wchar_t *FileName, UINT FileNameSize, WCHAR* instanceName, SensorType senserID)
{
	wchar_t DevIdOut[20];
	HRESULT hr;
	GetDevIdforFile(instanceName, DevIdOut);

    // Get the time
    wchar_t timeString[MAX_PATH];
	wchar_t dateString[MAX_PATH];
    GetTimeFormatEx(NULL, TIME_FORCE24HOURFORMAT, NULL, L"hh'-'mm'-'ss", timeString, _countof(timeString));
	GetDateFormatEx(NULL, 0, NULL, L"yyyy'-'MMM'-'dd", dateString, _countof(dateString), NULL);

	// File name will be DeviceConnectID-KinectAudio-HH-MM-SS.wav
	switch (senserID)
	{
	case AudioSensor:
		hr=StringCchPrintfW(FileName, FileNameSize, L"%s\\KinectAudio\\Audio-%s-%s-%s.wav", knownPath, DevIdOut, dateString, timeString);
		break;
	case RGBSensor:
		hr=StringCchPrintfW(FileName, FileNameSize, L"%s\\KinectRGB\\RGB-%s-%s-%s.avi", knownPath, DevIdOut, dateString, timeString);
		break;
	case DepthSensor:
		hr=StringCchPrintfW(FileName, FileNameSize, L"%s\\KinectDepth\\Depth-%s-%s-%s.avi", knownPath, DevIdOut, dateString, timeString);
		break;
	case SpeechRecog:
		hr=StringCchPrintfW(FileName, FileNameSize, L"%s\\KinectSpeechRecog\\SpeechRecog-%s-%s-%s.txt", knownPath, DevIdOut, dateString, timeString);
		break;
	default:
		break;
	}
    return hr;
}
Exemplo n.º 2
0
HRESULT ScaWebAppExtensionsWrite(IMSAdminBase* piMetabase, LPCWSTR wzRootOfWeb,
                                 SCA_WEB_APPLICATION_EXTENSION* pswappextList
                                )
{
    HRESULT hr = S_OK;

    LPWSTR wzAppExt = NULL;
    DWORD cchAppExt;
    WCHAR wzAppExtension[1024];
    WCHAR wzAppExtensions[65536];
    SCA_WEB_APPLICATION_EXTENSION* pswappext = NULL;

    if (!pswappextList)
        ExitFunction();

    ::ZeroMemory(wzAppExtensions, sizeof(wzAppExtensions));
    wzAppExt = wzAppExtensions;
    cchAppExt = countof(wzAppExtensions);
    pswappext = pswappextList;

    while (pswappext)
    {
        if (0 == lstrcmpW(wzAppExtension, L"*"))
            StringCchPrintfW(wzAppExtension, countof(wzAppExtension), L"*,%s,%d", pswappext->wzExecutable, pswappext->iAttributes);
        else if (*pswappext->wzExtension)
            StringCchPrintfW(wzAppExtension, countof(wzAppExtension), L".%s,%s,%d", pswappext->wzExtension, pswappext->wzExecutable, pswappext->iAttributes);
        else   // blank means "*" (all)
            StringCchPrintfW(wzAppExtension, countof(wzAppExtension), L"*,%s,%d", pswappext->wzExecutable, pswappext->iAttributes);

        // if verbs were specified and not the keyword "all"
        if (pswappext->wzVerbs[0] && CSTR_EQUAL != CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, pswappext->wzVerbs, -1, L"all", -1))
        {
            StringCchCatW(wzAppExtension, countof(wzAppExtension), L",");
            StringCchCatW(wzAppExtension, countof(wzAppExtension), pswappext->wzVerbs);
        }

        StringCchCopyW(wzAppExt, cchAppExt, wzAppExtension);
        wzAppExt += lstrlenW(wzAppExtension) + 1;
        cchAppExt -= lstrlenW(wzAppExtension) + 1;
        pswappext = pswappext->pswappextNext;
    }

    if (*wzAppExtensions)
    {
        hr = ScaWriteMetabaseValue(piMetabase, wzRootOfWeb, NULL, MD_SCRIPT_MAPS, METADATA_INHERIT, IIS_MD_UT_FILE, MULTISZ_METADATA, wzAppExtensions);
        ExitOnFailure1(hr, "Failed to write AppExtension: '%S'", wzAppExtension);
    }

LExit:
    return hr;
}
Exemplo n.º 3
0
//
// Purpose: 
//   Logs messages to the event log
//
// Parameters:
//   szFunction - name of function that failed
// 
// Return value:
//   None
//
// Remarks:
//   The service must have an entry in the Application event log.
//
VOID SvcReportEvent(LPTSTR szFunction) 
{ 
    HANDLE hEventSource;
    LPCWSTR lpszStrings[2];
    WCHAR Buffer[80];

    hEventSource = RegisterEventSourceW(NULL, SVCNAME);

    if( NULL != hEventSource )
    {
        StringCchPrintfW(Buffer, 80, L"%s failed with %d", szFunction, GetLastError());

        lpszStrings[0] = SVCNAME;
        lpszStrings[1] = Buffer;

        ReportEventW(hEventSource,        // event log handle
                    EVENTLOG_ERROR_TYPE, // event type
                    0,                   // event category
                    EVENTLOG_ERROR_TYPE, // event identifier
                    NULL,                // no security identifier
                    2,                   // size of lpszStrings array
                    0,                   // no binary data
                    lpszStrings,         // array of strings
                    NULL);               // no binary data

        DeregisterEventSource(hEventSource);
    }
}
Exemplo n.º 4
0
_Use_decl_annotations_
DX9_exception::DX9_exception(HRESULT hr, const char* file_name, int line) noexcept : HRESULT_exception(hr, file_name, line)
{
    try
    {
        WCHAR wide_error_string[1024];
        PCWSTR dx_message = DXGetErrorStringW(m_hr);
        if(CompareString(LOCALE_INVARIANT, NORM_IGNORECASE, dx_message, -1, TEXT("Unknown"), -1) == CSTR_EQUAL)
        {
            assert(!"DX error string could not be found.  Was check_hr intended?");
            dx_message = L"Unknown error.";
        }

        StringCchPrintfW(wide_error_string, ARRAYSIZE(wide_error_string), L"Error: %08x: %s", m_hr, dx_message);

        const auto error_string = PortableRuntime::utf8_from_utf16(wide_error_string);
        PortableRuntime::dprintf("!%s(%d): %s\n", file_name, line, error_string.c_str());

        // Just save off the message now, but do the full formatting in what(), to allow exception unwind to free up some resources.
        m_what = std::make_shared<std::string>(std::move(error_string));
    }
    catch(const std::bad_alloc& ex)
    {
        (void)ex;       // Unreferenced parameter.

        PortableRuntime::dprintf("!Failed creation of exception object.\n");
    }
}
Exemplo n.º 5
0
static
void UpdateReadmePage(HWND hDlg)
{
    HWND TextBox = GetDlgItem(hDlg, IDC_README_TEXT);
    if( SendDlgItemMessage(hDlg, IDC_COMMANDLINE, BM_GETCHECK, 0, 0) == BST_CHECKED)
    {
        size_t Length = wcslen(g_CommandlineUsage) + 1;
        for (size_t n = 0; n < g_FlagCount; ++n)
        {
            Length += wcslen(g_Flags[n].szAbbr);
            Length += wcslen(g_Flags[n].szDesc);
            Length += (7 + 3 + 2);  /* whitespace + ' - ' + newline */
        }

        WCHAR* Commandline = (WCHAR*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, Length * sizeof(WCHAR));
        StringCchCopy(Commandline, Length, g_CommandlineUsage);
        WCHAR Buffer[260];
        for (size_t n = 0; n < g_FlagCount; ++n)
        {
            StringCchPrintfW(Buffer, 260, L"       %s - %s\r\n", g_Flags[n].szAbbr, g_Flags[n].szDesc);
            StringCchCat(Commandline, Length, Buffer);
        }
        SetWindowText(TextBox, Commandline);
        HeapFree(GetProcessHeap(), 0, Commandline);
    }
    else if( SendDlgItemMessage(hDlg, IDC_LICENSE, BM_GETCHECK, 0, 0) == BST_CHECKED)
    {
        SetWindowText(TextBox, g_License);
    }
    else
    {
        SetWindowText(TextBox, L"Well hello there, you hacker :)");
    }
}
Exemplo n.º 6
0
void CAPIHook::FixupNewlyLoadedModule(HMODULE hmod, DWORD dwFlags) {

   // If a new module is loaded, hook the hooked functions
   if ((hmod != NULL) &&   // Do not hook our own module
       (hmod != ModuleFromAddress(FixupNewlyLoadedModule)) && 
       ((dwFlags & LOAD_LIBRARY_AS_DATAFILE) == 0) &&
       ((dwFlags & LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE) == 0) &&
       ((dwFlags & LOAD_LIBRARY_AS_IMAGE_RESOURCE) == 0)
       ) {

      for (CAPIHook* p = sm_pHead; p != NULL; p = p->m_pNext) {
         if (p->m_pfnOrig != NULL) {
            ReplaceIATEntryInAllMods(p->m_pszCalleeModName, 
               p->m_pfnOrig, p->m_pfnHook);  
         } else {
#ifdef _DEBUG
            // We should never end up here 
            wchar_t szPathname[MAX_PATH];
            GetModuleFileNameW(NULL, szPathname, _countof(szPathname));
            wchar_t sz[1024];
            StringCchPrintfW(sz, _countof(sz), 
               TEXT("[%4u - %s] impossible to find %S\r\n"), 
               GetCurrentProcessId(), szPathname, p->m_pszCalleeModName);
            OutputDebugString(sz);
#endif
         }
      }
   }
}
Exemplo n.º 7
0
// 
//   FUNCTION: CServiceBase::WriteErrorLogEntry(PWSTR, DWORD) 
// 
//   PURPOSE: Log an error message to the Application event log. 
// 
//   PARAMETERS: 
//   * pszFunction - the function that gives the error 
//   * dwError - the error code 
// 
void CServiceBase::WriteErrorLogEntry(const PWSTR pszFunction, DWORD dwError) 
{ 
    wchar_t szMessage[260]; 
    StringCchPrintfW(szMessage, ARRAYSIZE(szMessage),  
        L"%s failed w/err 0x%08lx", pszFunction, dwError); 
    WriteEventLogEntry(szMessage, EVENTLOG_ERROR_TYPE); 
} 
Exemplo n.º 8
0
HRESULT addGraphToRot(IUnknown *pUnkGraph, DWORD *pdwRegister) 
{
	IMoniker * pMoniker;
	IRunningObjectTable *pROT;
	WCHAR wsz[128];
	HRESULT hr;

	if (!pUnkGraph || !pdwRegister)
		return E_POINTER;

	if (FAILED(GetRunningObjectTable(0, &pROT)))
		return E_FAIL;

	hr = StringCchPrintfW(wsz, NUMELMS(wsz), L"FilterGraph %08x pid %08x\0", (DWORD_PTR)pUnkGraph, 
		GetCurrentProcessId());

	hr = CreateItemMoniker(L"!", wsz, &pMoniker);
	if (SUCCEEDED(hr)) 
	{
		// Use the ROTFLAGS_REGISTRATIONKEEPSALIVE to ensure a strong reference
		// to the object.  Using this flag will cause the object to remain
		// registered until it is explicitly revoked with the Revoke() method.
		//
		// Not using this flag means that if GraphEdit remotely connects
		// to this graph and then GraphEdit exits, this object registration 
		// will be deleted, causing future attempts by GraphEdit to fail until
		// this application is restarted or until the graph is registered again.
		hr = pROT->Register(ROTFLAGS_REGISTRATIONKEEPSALIVE, pUnkGraph, 
			pMoniker, pdwRegister);
		pMoniker->Release();
	}

	pROT->Release();
	return hr;
}
Exemplo n.º 9
0
HRESULT
AddGraphToRunningObjectTable(IUnknown *aUnkGraph, DWORD *aOutRotRegister)
{
  HRESULT hr;

  nsRefPtr<IMoniker> moniker;
  nsRefPtr<IRunningObjectTable> runningObjectTable;

  hr = GetRunningObjectTable(0, getter_AddRefs(runningObjectTable));
  NS_ENSURE_TRUE(SUCCEEDED(hr), hr);

  const size_t STRING_LENGTH = 256;
  WCHAR wsz[STRING_LENGTH];

  StringCchPrintfW(wsz,
                   STRING_LENGTH,
                   L"FilterGraph %08x pid %08x",
                   (DWORD_PTR)aUnkGraph,
                   GetCurrentProcessId());

  hr = CreateItemMoniker(L"!", wsz, getter_AddRefs(moniker));
  NS_ENSURE_TRUE(SUCCEEDED(hr), hr);

  hr = runningObjectTable->Register(ROTFLAGS_REGISTRATIONKEEPSALIVE,
                                    aUnkGraph,
                                    moniker,
                                    aOutRotRegister);
  NS_ENSURE_TRUE(SUCCEEDED(hr), hr);

  return S_OK;
}
Exemplo n.º 10
0
STDAPI DllUnregisterServer()
{
    LPOLESTR psz;
    WCHAR szCLSID[MAX_PATH];
    HRESULT hr = StringFromCLSID(CLSID_OVDeskBand, &psz);
    if (SUCCEEDED(hr))
    {
        hr = StringCchCopyW(szCLSID, ARRAYSIZE(szCLSID), psz);
        CoTaskMemFree(psz);
    }

    if (SUCCEEDED(hr))
    {
        WCHAR szSubkey[MAX_PATH];
        hr = StringCchPrintfW(szSubkey, ARRAYSIZE(szSubkey), L"CLSID\\%s", szCLSID);
        if (SUCCEEDED(hr))
        {
            if (ERROR_SUCCESS != RegDeleteTreeW(HKEY_CLASSES_ROOT, szSubkey))
            {
                hr = E_FAIL;
            }
        }
    }

    return SUCCEEDED(hr) ? S_OK : SELFREG_E_CLASS;
}
Exemplo n.º 11
0
BOOL ReadImageGlobalFlagsFromRegistry( _In_z_ PCWSTR ImageName, _Out_ ULONG* Flag )
{
    HKEY hKey;
    WCHAR FullKey[260];
    if(!ImageName || !ImageName[0])
    {
        *Flag = 0;
        return TRUE;
    }
    StringCchPrintfW(FullKey, 260, IMAGE_FILE_OPTIONS, ImageName);
    if(EnableDebug())
    {
        LONG lRet = RegOpenKeyExW( HKEY_LOCAL_MACHINE, FullKey, 0, KEY_READ, &hKey );
        if( ERROR_SUCCESS == lRet )
        {
            AutoCloseReg raii(hKey);
            DWORD Type = 0, cbData = sizeof(*Flag);
            if( ERROR_SUCCESS == RegQueryValueExW( hKey, GLOBALFLAG_VALUENAME, NULL, &Type, (LPBYTE)Flag, &cbData ) && Type == REG_DWORD )
            {
                return TRUE;
            }
        }
        else if(ERROR_FILE_NOT_FOUND == lRet)
        {
            *Flag = 0;
            return TRUE;
        }
    }
    return FALSE;
}
Exemplo n.º 12
0
HRESULT WINAPI CRecycleBin::GetDetailsOf(PCUITEMID_CHILD pidl, UINT iColumn, LPSHELLDETAILS pDetails)
{
    PIDLRecycleStruct * pFileDetails;
    WCHAR buffer[MAX_PATH];
    WCHAR szTypeName[100];
    LPWSTR pszBackslash;
    UINT Length;

    TRACE("(%p, %p, %d, %p)\n", this, pidl, iColumn, pDetails);
    if (iColumn >= COLUMNS_COUNT)
        return E_FAIL;
    pDetails->fmt = RecycleBinColumns[iColumn].fmt;
    pDetails->cxChar = RecycleBinColumns[iColumn].cxChars;
    if (pidl == NULL)
        return SHSetStrRet(&pDetails->str, RecycleBinColumns[iColumn].column_name_id);

    if (iColumn == COLUMN_NAME)
        return GetDisplayNameOf(pidl, SHGDN_NORMAL, &pDetails->str);

    pFileDetails = _ILGetRecycleStruct(pidl);
    switch (iColumn)
    {
        case COLUMN_DATEDEL:
            FormatDateTime(buffer, MAX_PATH, &pFileDetails->DeletionTime);
            break;
        case COLUMN_DELFROM:
            pszBackslash = wcsrchr(pFileDetails->szName, L'\\');
            Length = (pszBackslash - pFileDetails->szName);
            memcpy((LPVOID)buffer, pFileDetails->szName, Length * sizeof(WCHAR));
            buffer[Length] = L'\0';
            break;
        case COLUMN_SIZE:
            StrFormatKBSizeW(pFileDetails->FileSize.QuadPart, buffer, MAX_PATH);
            break;
        case COLUMN_MTIME:
            FormatDateTime(buffer, MAX_PATH, &pFileDetails->LastModification);
            break;
        case COLUMN_TYPE:
            // FIXME: We should in fact use a UNICODE version of _ILGetFileType
            szTypeName[0] = L'\0';
            wcscpy(buffer, PathFindExtensionW(pFileDetails->szName));
            if (!( HCR_MapTypeToValueW(buffer, buffer, _countof(buffer), TRUE) &&
                    HCR_MapTypeToValueW(buffer, szTypeName, _countof(szTypeName), FALSE )))
            {
                /* load localized file string */
                szTypeName[0] = '\0';
                if(LoadStringW(shell32_hInstance, IDS_ANY_FILE, szTypeName, _countof(szTypeName)))
                {
                    szTypeName[63] = '\0';
                    StringCchPrintfW(buffer, _countof(buffer), szTypeName, PathFindExtensionW(pFileDetails->szName));
                }
            }
            return SHSetStrRet(&pDetails->str, szTypeName);
        default:
            return E_FAIL;
    }

    return SHSetStrRet(&pDetails->str, buffer);
}
Exemplo n.º 13
0
void ShowError(HWND hwnd, PCWSTR szMessage, HRESULT hr)
{
    wchar_t msg[256];

    if (SUCCEEDED(StringCchPrintfW(msg, ARRAYSIZE(msg),  L"%s (hr = 0x%X)", szMessage, hr)))
    {
        MessageBox(hwnd, msg, NULL, MB_OK | MB_ICONERROR);
    }
}
Exemplo n.º 14
0
HRESULT CBandSiteMenu::_CreateMenuPart()
{
    WCHAR wszBandName[MAX_PATH];
    WCHAR wszBandGUID[MAX_PATH];
    WCHAR wRegKey[MAX_PATH];
    UINT cBands;
    DWORD dwDataSize;
    CATID category = CATID_DeskBand;
    HMENU hmenuToolbars;
    DWORD dwRead;
    CComPtr<IEnumGUID> pEnumGUID;
    HRESULT hr;

    if (m_hmenu)
        DestroyMenu(m_hmenu);

    /* Load the template we will fill in */
    m_hmenu = LoadMenuW(GetModuleHandleW(L"browseui.dll"), MAKEINTRESOURCEW(IDM_TASKBAR_TOOLBARS));
    if (!m_hmenu)
        return HRESULT_FROM_WIN32(GetLastError());

    /* Get the handle of the submenu where the available items will be shown */
    hmenuToolbars = GetSubMenu(m_hmenu, 0);

    /* Create the category enumerator */
    hr = SHEnumClassesOfCategories(1, &category, 0, NULL, &pEnumGUID);
    if (FAILED_UNEXPECTEDLY(hr))
        return hr;

    m_ComCatGuids.RemoveAll();

    /* Enumerate the classes in the  CATID_DeskBand category */
    cBands = 0;
    do
    {
        GUID iter;
        pEnumGUID->Next(1, &iter, &dwRead);
        if (!dwRead)
            continue;

        if (!StringFromGUID2(iter, wszBandGUID, MAX_PATH))
            continue;

        /* Get the band name */
        StringCchPrintfW(wRegKey, MAX_PATH, L"CLSID\\%s", wszBandGUID);
        dwDataSize = MAX_PATH;
        SHGetValue(HKEY_CLASSES_ROOT, wRegKey, NULL, NULL, wszBandName, &dwDataSize);

        /* Insert it */
        InsertMenu(hmenuToolbars, cBands, MF_BYPOSITION, m_ComCatGuids.GetSize() + FIRST_COMCAT_MENU_ID, wszBandName);
        m_ComCatGuids.Add(iter);
        cBands++;
    }
    while (dwRead > 0);

    return S_OK;
}
Exemplo n.º 15
0
void DumpServiceClassInfo(LPWSASERVICECLASSINFO lpSci)
{
    WCHAR szGuid[MAX_PATH] = {'\0'};
    GUID TempGuid = {0};
    DWORD i = 0;
    HRESULT hRet;

    if (NULL == lpSci)
        return;

    CopyMemory(&TempGuid,lpSci->lpServiceClassId,sizeof(GUID));

    if (FAILED(hRet = StringCchPrintfW(szGuid,
                                       sizeof(szGuid)/sizeof(szGuid[0]),
                                       L"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
                                       TempGuid.Data1,                    
                                       TempGuid.Data2,
                                       TempGuid.Data3,
                                       TempGuid.Data4[0],
                                       TempGuid.Data4[1],
                                       TempGuid.Data4[2],
                                       TempGuid.Data4[3],
                                       TempGuid.Data4[4],
                                       TempGuid.Data4[5],
                                       TempGuid.Data4[6],
                                       TempGuid.Data4[7]
                                      )))
    {
        printf("StringCchPrintfW failed: 0x%x\n",hRet);
        return;

    }



    printf("\nWSASERVICECLASSINFO %p:\n",lpSci);
    wprintf(L"lpServiceClassId:\t%s\n",szGuid);
    printf("lpszServiceClassName:\t%s\n",lpSci->lpszServiceClassName);
    printf("dwCount:\t\t%d\n",lpSci->dwCount);

    for (i = 0; i < lpSci->dwCount; i++)
    {
        printf("lpClassInfos (WSANSCLASSINFOW %p):\n",&lpSci->lpClassInfos[i]);
        printf("\t\tdwNameSpace:\t%d\n",lpSci->lpClassInfos[i].dwNameSpace);
        printf("\t\tdwValueSize:\t%d\n",lpSci->lpClassInfos[i].dwValueSize);
        printf("\t\tdwValueType:\t%d\n",lpSci->lpClassInfos[i].dwValueType);
        printf("\t\tlpszName:\t%s\n",lpSci->lpClassInfos[i].lpszName);
        printf("\t\tlpValue:\t%p\n",lpSci->lpClassInfos[i].lpValue);

    }
    printf("\n");

    return;

}
Exemplo n.º 16
0
void DebugMsg(const WCHAR* pszFormat, ...)
{
    WCHAR buf[1024];
    StringCchPrintfW(buf, sizeof(buf)/sizeof(WCHAR), L"(%lu): ", GetCurrentThreadId());
		va_list arglist;
		va_start(arglist, pszFormat);
		StringCchVPrintfW(&buf[wcslen(buf)], sizeof(buf)/sizeof(WCHAR), pszFormat, arglist);
		va_end(arglist);
    StringCchCatW(buf, sizeof(buf)/sizeof(WCHAR), L"\n");
    OutputDebugStringW(buf);
}
Exemplo n.º 17
0
/// <summary>
/// 
/// </summary>
/// <param name="wchar_t">handle to the application instance</param>
/// <param name="UINT">always 0</param>
/// <param name="int">command line arguments</param>
/// <returns>HRESULT</returns>
HRESULT GetScreenshotFileName(wchar_t *screenshotName, UINT screenshotNameSize, int frameType) {
    wchar_t *knownPath = NULL;
    HRESULT hr = SHGetKnownFolderPath(FOLDERID_Pictures, 0, NULL, &knownPath);

    if (SUCCEEDED(hr)) {
		if (m_bRecord) {
			wchar_t counterString[6];
			swprintf_s(counterString, L"%05d", m_bRecCounter);

			if (frameType == COLOR) {
				StringCchPrintfW(screenshotName, screenshotNameSize, L"%s\\%sC.PNG", knownPath, counterString);
			} else {
				StringCchPrintfW(screenshotName, screenshotNameSize, L"%s\\%sD.PNG", knownPath, counterString);
			}
		}
    }

    CoTaskMemFree(knownPath);
    return hr;
}
Exemplo n.º 18
0
	bool CLoggingImp::InitLogging()
	{
		if (!SHGetSpecialFolderPathW(0, m_wszLogDir, CSIDL_APPDATA, TRUE))
		{
			return false;
		}
		PathAppendW(m_wszLogDir, L"Logging");
		if (!CreateDirectoryW(m_wszLogDir, 0) && 
			GetLastError() != ERROR_ALREADY_EXISTS)
		{
			return false;
		}

		CleanOldLog();

		wchar_t wszBaseName[MAX_PATH] = {0};
		if (!GetModuleFileNameW(0, wszBaseName, MAX_PATH))
		{
			return false;
		}
		PathRemoveExtensionW(wszBaseName);
		PathStripPathW(wszBaseName);
		wchar_t wszLogFile[MAX_PATH] = {0};
		HRESULT hr = StringCchPrintfW(wszLogFile, MAX_PATH, L"%s\\%s_PID%d_%d.log", 
			m_wszLogDir, wszBaseName, GetCurrentProcessId(), GetTickCount());
		if (FAILED(hr))
		{
			return false;
		}
		//create file
		std::locale loc("");
		m_logwfstream.imbue(loc);
		m_logwfstream.open(wszLogFile, std::ios_base::out);	//TODO: what mode?
		if (!m_logwfstream)
		{
			return false;
		}
		//initialize critical section
		bool bOk = true;
		try
		{
			InitializeCriticalSection(&m_csWriteFile);
		}
		catch (...)
		{
			bOk = false;
			m_logwfstream.close();
		}
		
		m_logwfstream << L"\t\tIF ANY ERROR OCCURRED, "
			L"PLS CONTACT ME: [email protected].\n\n\n";
		
		return bOk;
	}
Exemplo n.º 19
0
int LauncherStartup(const wchar_t *args, int channel) {
  wchar_t pwszPath[UNC_MAX_PATH];
  GetModuleFileNameW(nullptr, pwszPath, UNC_MAX_PATH);
  PathRemoveFileSpecW(pwszPath);
  PathRemoveFileSpecW(pwszPath);
  PathRemoveFileSpecW(pwszPath);
  std::wstring psfile = pwszPath;
  switch (channel) {
  case kOpenEnvironment:
    psfile += L"\\bin\\ClangBuilderEnvironment.ps1";
    break;
  case kBaseBuilder:
    psfile += L"\\bin\\ClangBuilderManager.ps1";
    break;
  case kNinjaBootstrap:
    psfile += L"\\bin\\ClangBuilderBootstrap.ps1";
    break;
  default:
    psfile = L"Not support channel value: " + std::to_wstring(channel);
    OutErrorMessage(psfile.c_str(), L"Not support clangbuilder channel !");
    return -2;
  }
  if (!PathFileExistsW(psfile.c_str())) {
    OutErrorMessage(psfile.c_str(), L"PathFileExists return false");
    return -1;
  }

  if (SHGetFolderPathW(NULL, CSIDL_SYSTEM, NULL, 0, pwszPath) != S_OK) {
    return -1;
  }
  auto length = wcslen(pwszPath);
  StringCchCatW(pwszPath, UNC_MAX_PATH - length,
                L"\\WindowsPowerShell\\v1.0\\powershell.exe ");
  length = wcslen(pwszPath);
  auto offsetPtr = pwszPath + length;
  StringCchPrintfW(offsetPtr, UNC_MAX_PATH - length,
                   L" -NoLogo -NoExit   -File \"%s\" %s", psfile.c_str(), args);
  PROCESS_INFORMATION pi;
  STARTUPINFO si;
  ZeroMemory(&si, sizeof(si));
  ZeroMemory(&pi, sizeof(pi));
  si.cb = sizeof(si);
  si.dwFlags = STARTF_USESHOWWINDOW;
  si.wShowWindow = SW_SHOW;
  if (CreateProcessW(nullptr, pwszPath, NULL, NULL, FALSE,
                     CREATE_NEW_CONSOLE | NORMAL_PRIORITY_CLASS, NULL, NULL,
                     &si, &pi)) {
    CloseHandle(pi.hThread);
    CloseHandle(pi.hProcess);
    return 0;
  }
  return GetLastError();
}
int WACIrctell::ccb_notify(int msg, int param1, int param2)
{
	if (msg==TITLECHANGE && dotell)
	{
		const wchar_t *title = (const wchar_t *)param1;
		const wchar_t *cur=core->core_getCurrent(0);

		wchar_t msg[256];
		StringCchPrintfW(msg, 256, L"/describe #winamp is now listening to \"%s\"", title);
		DdeCom::sendCommand(L"mIRC", msg, 1000);
	}
	return 0;
}
Exemplo n.º 21
0
static
void StoreImageFlags(HWND hDlg)
{
    WCHAR Buffer[128] = {0};
    SendDlgItemMessageW(hDlg, IDC_EDIT_IMAGENAME, WM_GETTEXT, 128, (LPARAM)Buffer);
    g_ImageSettings = FlagsFromDialog(hDlg) & g_ValidImageFlags;
    if(!WriteImageGlobalFlagsToRegistry(Buffer, g_ImageSettings))
    {
        WCHAR ErrorBuffer[256];
        StringCchPrintfW(ErrorBuffer, 256, L"Unable to write image flags for %s", Buffer);
        MessageBoxW(hDlg, ErrorBuffer, L"gflags Error", MB_OK | MB_ICONERROR);
    }
}
static void OnSkinChanged(HTMLControl *pCtrl)
{
	wchar_t css[128];
	if (!pCtrl) return;
	if (!ml_color) return; // make sure we have the function to get colors first!
	return;  // lets not do this for now...
	if (S_OK ==StringCchPrintfW(css, 128, L"BODY { background-color: #%06X; color:#%06X }",
	                            GetHTMLColor(ml_color(WADLG_ITEMBG)),
	                            GetHTMLColor(ml_color(WADLG_ITEMFG))))
	{
		pCtrl->SetHostCSS(css);
	}
}
Exemplo n.º 23
0
void GBAConfigDirectory(char* out, size_t outLength) {
	struct VFile* portable;
#ifdef _WIN32
	wchar_t wpath[MAX_PATH];
	wchar_t wprojectName[MAX_PATH];
	MultiByteToWideChar(CP_UTF8, 0, projectName, -1, wprojectName, MAX_PATH);
	HMODULE hModule = GetModuleHandleW(NULL);
	GetModuleFileNameW(hModule, wpath, MAX_PATH);
	PathRemoveFileSpecW(wpath);
	WideCharToMultiByte(CP_UTF8, 0, wpath, -1, out, outLength, 0, 0);
	StringCchCatA(out, outLength, "\\portable.ini");
	portable = VFileOpen(out, O_RDONLY);
	if (portable) {
		portable->close(portable);
	} else {
		wchar_t* home;
		SHGetKnownFolderPath(&FOLDERID_RoamingAppData, 0, NULL, &home);
		StringCchPrintfW(wpath, MAX_PATH, L"%ws\\%ws", home, wprojectName);
		CoTaskMemFree(home);
		CreateDirectoryW(wpath, NULL);
	}
	WideCharToMultiByte(CP_UTF8, 0, wpath, -1, out, outLength, 0, 0);
#elif defined(PSP2)
	UNUSED(portable);
	snprintf(out, outLength, "cache0:/%s", projectName);
	sceIoMkdir(out, 0777);
#elif defined(GEKKO)
	UNUSED(portable);
	snprintf(out, outLength, "/%s", projectName);
	mkdir(out, 0777);
#elif defined(_3DS)
	UNUSED(portable);
	snprintf(out, outLength, "/%s", projectName);
	FSUSER_CreateDirectory(sdmcArchive, fsMakePath(PATH_ASCII, out), 0);
#else
	getcwd(out, outLength);
	strncat(out, PATH_SEP "portable.ini", outLength - strlen(out));
	portable = VFileOpen(out, O_RDONLY);
	if (portable) {
		getcwd(out, outLength);
		portable->close(portable);
		return;
	}

	char* home = getenv("HOME");
	snprintf(out, outLength, "%s/.config", home);
	mkdir(out, 0755);
	snprintf(out, outLength, "%s/.config/%s", home, binaryName);
	mkdir(out, 0755);
#endif
}
Exemplo n.º 24
0
/// <summary>
/// Get the name of the file where screenshot will be stored.
/// </summary>
/// <param name="screenshotName">
/// [out] String buffer that will receive screenshot file name.
/// </param>
/// <param name="screenshotNameSize">
/// [in] Number of characters in screenshotName string buffer.
/// </param>
/// <returns>
/// S_OK on success, otherwise failure code.
/// </returns>
HRESULT GetScreenshotFileName(wchar_t *screenshotName, UINT screenshotNameSize,int shotType)
{
   wchar_t *knownPath = NULL;
    HRESULT hr = SHGetKnownFolderPath(FOLDERID_Pictures, 0, NULL, &knownPath);
	
      knownPath=L"..\\output";
    if (SUCCEEDED(hr))
    {
        // Get the time
        wchar_t timeString[MAX_PATH];
        GetTimeFormatEx(NULL,TIME_FORCE24HOURFORMAT, NULL, L"hh'-'mm'-'ss", timeString, _countof(timeString));

		// File name will be KinectColorShot-HH-MM-SS(shotType==0)
		//                or KinectDepthShot-HH-MM-SS(shotType==1)
        if(shotType==0)
        StringCchPrintfW(screenshotName, screenshotNameSize, L"%s\\KinectColorShot-%s.bmp", knownPath, timeString);
		else if(shotType==1)
        StringCchPrintfW(screenshotName, screenshotNameSize, L"%s\\KinectDepthShot-%s.bmp", knownPath, timeString);
    }

   // CoTaskMemFree(knownPath);
    return hr;
}
Exemplo n.º 25
0
BOOL WINAPI InjectLibA(DWORD dwProcessId, PCSTR pszLibFile)
{

    // Allocate a (stack) buffer for the Unicode version of the pathname
    SIZE_T cchSize = lstrlenA(pszLibFile) + 1;
    PWSTR pszLibFileW = (PWSTR)
                        _alloca(cchSize * sizeof(wchar_t));

    // Convert the ANSI pathname to its Unicode equivalent
    StringCchPrintfW(pszLibFileW, cchSize, L"%S", pszLibFile);

    // Call the Unicode version of the function to actually do the work.
    return(InjectLibW(dwProcessId, pszLibFileW));
}
Exemplo n.º 26
0
bool _vdwDeleteFile(struct VDir* vd, const char* path) {
	struct VDirW32* vdw = (struct VDirW32*) vd;
	if (!path) {
		return 0;
	}
	wchar_t dir[MAX_PATH + 1];
	wchar_t pathw[MAX_PATH + 1];
	wchar_t combined[MAX_PATH + 1];
	MultiByteToWideChar(CP_UTF8, 0, vdw->path, -1, dir, MAX_PATH);
	MultiByteToWideChar(CP_UTF8, 0, path, -1, pathw, MAX_PATH);
	StringCchPrintfW(combined, MAX_PATH, L"%ws\\%ws", dir, pathw);

	return DeleteFileW(combined);
}
Exemplo n.º 27
0
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
// DescriptionFromHR
// Retrives a description of a HRESULT error code.
//
HRESULT DescriptionFromHR(HRESULT hr, LPWSTR buf, size_t cchBuf) {
    if (FACILITY_WINDOWS == HRESULT_FACILITY(hr))
    {
         hr = HRESULT_CODE(hr);
    }

    if (FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, hr,
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, DWORD(cchBuf), nullptr) == 0)
    {
        return StringCchPrintfW(buf, cchBuf, L"Unknown error, 0x%.8X", hr);
    }

    return S_OK;
}
Exemplo n.º 28
0
//------------------------------------------------------------------------------
// DllUnregisterServer
//------------------------------------------------------------------------------
STDAPI DllUnregisterServer()
{
	HKEY    hKey = NULL;
	HRESULT hr = S_OK;
	LONG    lResult = ERROR_SUCCESS;
	WCHAR   szKey[MAX_PATH] = { 0 };
	WCHAR   szCLSID[OLEGUID_LEN_CCH] = { 0 };

	//
	// Register the COM object in the registry
	//
	if (0 == StringFromGUID2(CLSID_SsysPrinterSvcProxy, szCLSID, ARRAYSIZE(szCLSID)))
	{
		hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
	}

	if (S_OK == hr)
	{
		hr = StringCchPrintfW(szKey, ARRAYSIZE(szKey), L"%s\\InProcServer32", szCLSID);
	}

	if (S_OK == hr)
	{
		lResult = RegOpenKeyExW(
			HKEY_CLASSES_ROOT,
			L"CLSID",
			0,
			KEY_SET_VALUE,
			&hKey
			);
		hr = HRESULT_FROM_WIN32(lResult);
	}

	if (S_OK == hr)
	{
		lResult = RegDeleteKeyW(hKey, szKey);
		hr = HRESULT_FROM_WIN32(lResult);
	}

	if (S_OK == hr)
	{
		lResult = RegDeleteKeyW(hKey, szCLSID);
		hr = HRESULT_FROM_WIN32(lResult);
	}

	RegCloseKey(hKey);
	hKey = NULL;

	return hr;
}// DllUnregisterServer
Exemplo n.º 29
0
//
// Registry keys are removed here.
//
STDAPI DllUnregisterServer()
{
    WCHAR szSubKey[MAX_PATH];
	WCHAR szBoxShellFolderID[MAX_PATH];
    
    //Delete the context menu entries.
    HRESULT hr = StringFromGUID2(CLSID_BoxShellFolder, 
                                  szBoxShellFolderID, 
                                  ARRAYSIZE(szBoxShellFolderID));
    if (SUCCEEDED(hr))
    {
        hr = StringCchPrintfW(szSubKey, ARRAYSIZE(szSubKey), L"Software\\Classes\\CLSID\\%s", szBoxShellFolderID);
        if (SUCCEEDED(hr))
        {
            hr = SHDeleteKeyW(HKEY_CURRENT_USER, szSubKey);
        }
    }

	hr = StringCchPrintfW(szSubKey, ARRAYSIZE(szSubKey), MYCOMPUTER_NAMESPACE_GUID, szBoxShellFolderID);
	if (SUCCEEDED(hr))
	{
		//MessageBoxW(NULL, szSubKey, NULL, 0);
		hr = SHDeleteKeyW(HKEY_CURRENT_USER, szSubKey);
	}

	hr = StringCchPrintfW(szSubKey, ARRAYSIZE(szSubKey), SHELL_EXT_APPROVED, szBoxShellFolderID);
	if (SUCCEEDED(hr))
	{
		//MessageBoxW(NULL, szSubKey, NULL, 0);
		hr = SHDeleteKeyW(HKEY_LOCAL_MACHINE, szSubKey);
	}

	RefreshFolderViews(CSIDL_DRIVES);   

	return SUCCEEDED(hr) ? S_OK : SELFREG_E_CLASS;
}
Exemplo n.º 30
0
void MainWindow::OnDisplay()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	m_rc->PushModelView();
		gun->Draw();

		camera.ApplyTransform(m_rc);
		skybox->Draw();

		static int viewLoc = mainShader->GetUniformLocation("View");
		Matrix44f view = m_rc->GetModelView();
		mainShader->Use();
		glUniformMatrix4fv(viewLoc, 1, FALSE, view.data);

		int drawCalls = sponza->Draw();
		WCHAR buf[20] = L"";
		StringCchPrintfW(buf, 20, L"Meshes: %d", drawCalls);
		text->SetText(buf);
		
		glEnable(GL_BLEND);
		glDisable(GL_CULL_FACE);
	
		if (fShowMuzzleFlash) {
			m_rc->PushModelView();
				m_rc->SetModelView(Matrix44f::Identity());
				muzzle_flash->Draw();
			m_rc->PopModelView();
		}

		m_rc->PushModelView();
		m_rc->PushProjection();
			float viewport[4] = { };
			glGetFloatv(GL_VIEWPORT, viewport);
			m_rc->SetProjection(Ortho2D(0, viewport[2], viewport[3], 0));
			m_rc->SetModelView(Matrix44f::Identity());

			crosshair->location = Vector3f(viewport[2]*0.5f, viewport[3]*0.5f, 0);
			crosshair->Draw();
		m_rc->PopModelView();
		m_rc->PopProjection();

		glEnable(GL_CULL_FACE);
		glDisable(GL_BLEND);

		text->Draw(10, 10);
	m_rc->PopModelView();
}