/********************************************************************** * COMCAT_ICatInformation_IsClassOfCategories */ static HRESULT WINAPI COMCAT_ICatInformation_IsClassOfCategories( LPCATINFORMATION iface, REFCLSID rclsid, ULONG cImplemented, CATID *rgcatidImpl, ULONG cRequired, CATID *rgcatidReq) { WCHAR keyname[45] = { 'C', 'L', 'S', 'I', 'D', '\\', 0 }; HRESULT res; struct class_categories *categories; HKEY key; if (TRACE_ON(ole)) { ULONG count; TRACE("CLSID: %s Implemented %u\n",debugstr_guid(rclsid),cImplemented); for (count = 0; count < cImplemented; ++count) TRACE(" %s\n",debugstr_guid(&rgcatidImpl[count])); TRACE("Required %u\n",cRequired); for (count = 0; count < cRequired; ++count) TRACE(" %s\n",debugstr_guid(&rgcatidReq[count])); } if ((cImplemented && rgcatidImpl == NULL) || (cRequired && rgcatidReq == NULL)) return E_POINTER; res = StringFromGUID2(rclsid, keyname + 6, CHARS_IN_GUID); if (FAILED(res)) return res; categories = COMCAT_PrepareClassCategories(cImplemented, rgcatidImpl, cRequired, rgcatidReq); if (categories == NULL) return E_OUTOFMEMORY; res = open_classes_key(HKEY_CLASSES_ROOT, keyname, KEY_READ, &key); if (res == ERROR_SUCCESS) { res = COMCAT_IsClassOfCategories(key, categories); RegCloseKey(key); } else res = S_FALSE; HeapFree(GetProcessHeap(), 0, categories); return res; }
void EnumDMO(bool bEnc) { char buf[256]; WCHAR wbuf[256]; WCHAR *pwsz; IEnumDMO *pEnumDMO; CLSID clsid; DWORD dwCount; DMOEnum(bEnc ? DMOCATEGORY_VIDEO_ENCODER : DMOCATEGORY_VIDEO_DECODER, DMO_ENUMF_INCLUDE_KEYED, 0, NULL, 0, NULL, &pEnumDMO); while (pEnumDMO->Next(1, &clsid, &pwsz, &dwCount) == S_OK) { StringFromGUID2(clsid, wbuf, _countof(wbuf)); wsprintf(buf, "DMO\t%d\t%S\t%S\n", bEnc, pwsz, wbuf); printf("%s", buf); CoTaskMemFree(pwsz); } pEnumDMO->Release(); }
// // 函数名称: RegisterInprocServer // // 作用: 在注册表中注册进程内组件 // // 参数: // * pszModule -包含该组件模块的路径 // * clsid -组件的类ID // * pszFriendlyName -友元名称 // * pszThreadModel -线程模型 // // // 注意: 该方法在注册表中创建了HKCR\CLSID\{<CLSID>}注册项. // // HKCR // { // NoRemove CLSID // { // ForceRemove {<CLSID>} = s '<Friendly Name>' // { // InprocServer32 = s '%MODULE%' // { // val ThreadingModel = s '<Thread Model>' // } // } // } // } // HRESULT RegisterInprocServer(PCWSTR pszModule, const CLSID& clsid, PCWSTR pszFriendlyName, PCWSTR pszThreadModel) { if (pszModule == NULL || pszThreadModel == NULL) { return E_INVALIDARG; } HRESULT hr; wchar_t szCLSID[MAX_PATH]; StringFromGUID2(clsid, szCLSID, ARRAYSIZE(szCLSID)); wchar_t szSubkey[MAX_PATH]; // 创建 HKCR\CLSID\{<CLSID>}注册项. hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey), L"CLSID\\%s", szCLSID); if (SUCCEEDED(hr)) { hr = SetHKCRRegistryKeyAndValue(szSubkey, NULL, pszFriendlyName); //创建 HKCR\CLSID\{<CLSID>}\InprocServer32注册项. if (SUCCEEDED(hr)) { hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey), L"CLSID\\%s\\InprocServer32", szCLSID); if (SUCCEEDED(hr)) { //以InprocServer32注册项的值作为为COM模块的路径的默认值 hr = SetHKCRRegistryKeyAndValue(szSubkey, NULL, pszModule); if (SUCCEEDED(hr)) { //为组件设置线程模型. hr = SetHKCRRegistryKeyAndValue(szSubkey, L"ThreadingModel", pszThreadModel); } } } } return hr; }
JobbedProcessManager::JobbedProcessManager() : szUsername(nullptr), szPassword(nullptr), szDirectory(nullptr), szCmdLine(nullptr), szExecutable(nullptr), szEnvBlock(nullptr), tle_(false), mle_(false), terminate_shocker(false) { ZeroMemory(&extLimits, sizeof extLimits); extLimits.BasicLimitInformation.ActiveProcessLimit = 1; extLimits.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_ACTIVE_PROCESS; ZeroMemory(&uiLimits, sizeof uiLimits); uiLimits.UIRestrictionsClass = JOB_OBJECT_UILIMIT_DESKTOP | JOB_OBJECT_UILIMIT_DISPLAYSETTINGS | JOB_OBJECT_UILIMIT_EXITWINDOWS | JOB_OBJECT_UILIMIT_GLOBALATOMS | JOB_OBJECT_UILIMIT_HANDLES | JOB_OBJECT_UILIMIT_READCLIPBOARD | JOB_OBJECT_UILIMIT_SYSTEMPARAMETERS | JOB_OBJECT_UILIMIT_WRITECLIPBOARD; CoCreateGuid(&guid); StringFromGUID2(guid, szGuid, ARRAYSIZE(szGuid)); }
/********************************************************************** * COMCAT_ICatRegister_RegisterCategories */ static HRESULT WINAPI COMCAT_ICatRegister_RegisterCategories( LPCATREGISTER iface, ULONG cCategories, CATEGORYINFO *rgci) { HKEY comcat_key; HRESULT res; TRACE("\n"); if (cCategories && rgci == NULL) return E_POINTER; /* Create (or open) the component categories key. */ res = RegCreateKeyExW(HKEY_CLASSES_ROOT, comcat_keyname, 0, NULL, 0, KEY_READ | KEY_WRITE, NULL, &comcat_key, NULL); if (res != ERROR_SUCCESS) return E_FAIL; for (; cCategories; --cCategories, ++rgci) { static const WCHAR fmt[] = { '%', 'l', 'X', 0 }; WCHAR keyname[39]; WCHAR valname[9]; HKEY cat_key; /* Create (or open) the key for this category. */ if (!StringFromGUID2(&rgci->catid, keyname, 39)) continue; res = RegCreateKeyExW(comcat_key, keyname, 0, NULL, 0, KEY_READ | KEY_WRITE, NULL, &cat_key, NULL); if (res != ERROR_SUCCESS) continue; /* Set the value for this locale's description. */ wsprintfW(valname, fmt, rgci->lcid); RegSetValueExW(cat_key, valname, 0, REG_SZ, (CONST BYTE*)(rgci->szDescription), (lstrlenW(rgci->szDescription) + 1) * sizeof(WCHAR)); RegCloseKey(cat_key); } RegCloseKey(comcat_key); return S_OK; }
static HRESULT WINAPI MediaStreamFilterImpl_AddMediaStream(IMediaStreamFilter* iface, IAMMediaStream *pAMMediaStream) { IMediaStreamFilterImpl *This = impl_from_IMediaStreamFilter(iface); IMediaStream** streams; IPin** pins; MediaStreamFilter_InputPin* pin; HRESULT hr; PIN_INFO info; MSPID purpose_id; TRACE("(%p)->(%p)\n", iface, pAMMediaStream); streams = CoTaskMemRealloc(This->streams, (This->nb_streams + 1) * sizeof(IMediaStream*)); if (!streams) return E_OUTOFMEMORY; This->streams = streams; pins = CoTaskMemRealloc(This->pins, (This->nb_streams + 1) * sizeof(IPin*)); if (!pins) return E_OUTOFMEMORY; This->pins = pins; info.pFilter = (IBaseFilter*)&This->filter; info.dir = PINDIR_INPUT; hr = IAMMediaStream_GetInformation(pAMMediaStream, &purpose_id, NULL); if (FAILED(hr)) return hr; /* Pin name is "I{guid MSPID_PrimaryVideo or MSPID_PrimaryAudio}" */ info.achName[0] = 'I'; StringFromGUID2(&purpose_id, info.achName + 1, 40); hr = BaseInputPin_Construct(&MediaStreamFilter_InputPin_Vtbl, sizeof(BaseInputPin), &info, &input_BaseFuncTable, &input_BaseInputFuncTable, &This->filter.csFilter, NULL, &This->pins[This->nb_streams]); if (FAILED(hr)) return hr; pin = (MediaStreamFilter_InputPin*)This->pins[This->nb_streams]; pin->pin.pin.pinInfo.pFilter = (LPVOID)This; This->streams[This->nb_streams] = (IMediaStream*)pAMMediaStream; This->nb_streams++; IMediaStream_AddRef((IMediaStream*)pAMMediaStream); return S_OK; }
// // FUNCTION: UnregisterShellExtContextMenuHandler // // PURPOSE: Unregister the context menu handler. // // PARAMETERS: // * pszFileType - The file type that the context menu handler is // associated with. For example, '*' means all file types; '.txt' means // all .txt files. The parameter must not be NULL. // * clsid - Class ID of the component // // NOTE: The function removes the {<CLSID>} key under // HKCR\<File Type>\shellex\ContextMenuHandlers in the registry. // HRESULT UnregisterShellExtContextMenuHandler( PCWSTR pszFileType, const CLSID& clsid) { if (pszFileType == NULL) { return E_INVALIDARG; } HRESULT hr; wchar_t szCLSID[MAX_PATH]; StringFromGUID2(clsid, szCLSID, ARRAYSIZE(szCLSID)); wchar_t szSubkey[MAX_PATH]; // If pszFileType starts with '.', try to read the default value of the // HKCR\<File Type> key which contains the ProgID to which the file type // is linked. if (*pszFileType == L'.') { wchar_t szDefaultVal[260]; hr = GetHKCRRegistryKeyAndValue(pszFileType, NULL, szDefaultVal, sizeof(szDefaultVal)); // If the key exists and its default value is not empty, use the // ProgID as the file type. if (SUCCEEDED(hr) && szDefaultVal[0] != L'\0') { pszFileType = szDefaultVal; } } // Remove the HKCR\<File Type>\shellex\ContextMenuHandlers\{<CLSID>} key. hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey), L"%s\\shellex\\ContextMenuHandlers\\%s", pszFileType, szCLSID); if (SUCCEEDED(hr)) { hr = HRESULT_FROM_WIN32(RegDeleteTree(HKEY_CLASSES_ROOT, szSubkey)); } return hr; }
HRESULT OCContextMenuRegHandler::RegisterInprocServer(PCWSTR pszModule, const CLSID& clsid, PCWSTR pszFriendlyName, PCWSTR pszThreadModel) { if (pszModule == NULL || pszThreadModel == NULL) { return E_INVALIDARG; } HRESULT hr; wchar_t szCLSID[MAX_PATH]; StringFromGUID2(clsid, szCLSID, ARRAYSIZE(szCLSID)); wchar_t szSubkey[MAX_PATH]; // Create the HKCR\CLSID\{<CLSID>} key. hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey), L"CLSID\\%s", szCLSID); if (SUCCEEDED(hr)) { hr = SetHKCRRegistryKeyAndValue(szSubkey, NULL, pszFriendlyName); // Create the HKCR\CLSID\{<CLSID>}\InprocServer32 key. if (SUCCEEDED(hr)) { hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey), L"CLSID\\%s\\InprocServer32", szCLSID); if (SUCCEEDED(hr)) { // Set the default value of the InprocServer32 key to the // path of the COM module. hr = SetHKCRRegistryKeyAndValue(szSubkey, NULL, pszModule); if (SUCCEEDED(hr)) { // Set the threading model of the component. hr = SetHKCRRegistryKeyAndValue(szSubkey, L"ThreadingModel", pszThreadModel); } } } } return hr; }
/* static private */ HRESULT REGUTIL::_RegisterClassBase( REFCLSID rclsid, const char *szDesc, const char *szProgID, const char *szIndepProgID, char *szOutCLSID ) { char szID[64]; // the class ID to register. OLECHAR szWID[64]; // helper for the class ID to register. StringFromGUID2( rclsid, szWID, NumItems( szWID ) ); WideCharToMultiByte( CP_ACP, 0, szWID, -1, szID, sizeof( szID ), NULL, NULL ); strcpy( szOutCLSID, "CLSID\\" ); strcat( szOutCLSID, szID ); // create ProgID keys. SetKeyAndValue( szProgID, NULL, szDesc ); SetKeyAndValue( szProgID, "CLSID", szID ); // create VersionIndependentProgID keys. SetKeyAndValue( szIndepProgID, NULL, szDesc ); SetKeyAndValue( szIndepProgID, "CurVer", szProgID ); SetKeyAndValue( szIndepProgID, "CLSID", szID ); // create entries under CLSID. SetKeyAndValue( szOutCLSID, NULL, szDesc ); SetKeyAndValue( szOutCLSID, "ProgID", szProgID ); SetKeyAndValue( szOutCLSID, "VersionIndependentProgID", szIndepProgID ); SetKeyAndValue( szOutCLSID, "NotInsertable", NULL ); return S_OK; } // REGUTIL::_RegisterClassBase
/////////////////////////////////////////////////////////// // // Class factory body // HRESULT __stdcall IOemCF::QueryInterface(const IID& iid, void** ppv) { if ((iid == IID_IUnknown) || (iid == IID_IClassFactory)) { *ppv = static_cast<IOemCF*>(this) ; } else { #if DBG && defined(USERMODE_DRIVER) TCHAR szOutput[80] = {0}; StringFromGUID2(iid, szOutput, COUNTOF(szOutput)); // can not fail! WARNING(DLLTEXT("IOemCF::QueryInterface %s not supported.\r\n"), szOutput); #endif *ppv = NULL ; return E_NOINTERFACE ; } reinterpret_cast<IUnknown*>(*ppv)->AddRef() ; return S_OK ; }
/*********************************************************************** * unregister_interfaces */ static HRESULT unregister_interfaces(struct regsvr_interface const *list) { LONG res = ERROR_SUCCESS; HKEY interface_key; res = RegOpenKeyExW(HKEY_CLASSES_ROOT, interface_keyname, 0, KEY_READ | KEY_WRITE, &interface_key); if (res == ERROR_FILE_NOT_FOUND) return S_OK; if (res != ERROR_SUCCESS) goto error_return; for (; res == ERROR_SUCCESS && list->iid; ++list) { WCHAR buf[39]; StringFromGUID2(list->iid, buf, 39); res = recursive_delete_keyW(interface_key, buf); } RegCloseKey(interface_key); error_return: return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK; }
static HRESULT MMDevPropStore_OpenPropKey(const GUID *guid, DWORD flow, HKEY *propkey) { WCHAR buffer[39]; LONG ret; HKEY key; StringFromGUID2(guid, buffer, 39); if ((ret = RegOpenKeyExW(flow == eRender ? key_render : key_capture, buffer, 0, KEY_READ|KEY_WRITE|KEY_WOW64_64KEY, &key)) != ERROR_SUCCESS) { WARN("Opening key %s failed with %u\n", debugstr_w(buffer), ret); return E_FAIL; } ret = RegOpenKeyExW(key, reg_properties, 0, KEY_READ|KEY_WRITE|KEY_WOW64_64KEY, propkey); RegCloseKey(key); if (ret != ERROR_SUCCESS) { WARN("Opening key %s failed with %u\n", debugstr_w(reg_properties), ret); return E_FAIL; } return S_OK; }
Guid::Guid( void ) { #ifdef _MSC_VER OLECHAR guidStringPtr[40]; GUID guid; CoCreateGuid( &guid ); # ifndef NDEBUG int charSize = # endif StringFromGUID2( guid, guidStringPtr, 40 ); assert( charSize > 0 ); std::wstring wideString = guidStringPtr; utf8::utf16to8( wideString.begin(), wideString.end(), std::back_inserter( m_string ) ); #endif }
BOOL IsSingleThreadedApartment() { HRESULT hr; CLSID ClsID; hr = CLSIDFromProgID(OLESTR("VPinMAME.Controller"), &ClsID); if ( FAILED(hr) ) return FALSE; OLECHAR sClsID[256]; StringFromGUID2(ClsID, (LPOLESTR) sClsID, 256); char szClsID[256]; WideCharToMultiByte(CP_ACP, 0, (LPOLESTR) sClsID, -1, szClsID, sizeof szClsID, NULL, NULL); char szRegKey[256]; lstrcpy(szRegKey, "CLSID\\"); lstrcat(szRegKey, szClsID); lstrcat(szRegKey, "\\InprocServer32"); HKEY hKey; if ( RegOpenKey(HKEY_CLASSES_ROOT, szRegKey, &hKey)!=ERROR_SUCCESS ) return FALSE; char szThreadingModel[MAX_PATH]; ULONG uSize = sizeof szThreadingModel; DWORD dwType = REG_SZ; if ( RegQueryValueEx(hKey, "ThreadingModel", NULL, &dwType, (LPBYTE) &szThreadingModel, &uSize)!=ERROR_SUCCESS ) { RegCloseKey(hKey); // if we don't have that entry, return TRUE (old style, but single threaded) return TRUE; } RegCloseKey(hKey); // if we don't have that entry, return TRUE (old style, but single threaded) if ( !szThreadingModel[0] ) return TRUE; return _stricmp(szThreadingModel, "Apartment")?FALSE:TRUE; }
/* static private */ HRESULT REGUTIL::_UnregisterClassBase( REFCLSID rclsid, const char *szProgID, const char *szIndepProgID, char *szOutCLSID ) { char szID[64]; // the class ID to register. OLECHAR szWID[64]; // helper for the class ID to register. StringFromGUID2( rclsid, szWID, NumItems( szWID ) ); WideCharToMultiByte( CP_ACP, 0, szWID, -1, szID, sizeof( szID ), NULL, NULL ); strcpy( szOutCLSID, "CLSID\\" ); strcat( szOutCLSID, szID ); // delete the version independant prog ID settings. DeleteKey( szIndepProgID, "CurVer" ); DeleteKey( szIndepProgID, "CLSID" ); RegDeleteKeyA( HKEY_CLASSES_ROOT, szIndepProgID ); // delete the prog ID settings. DeleteKey( szProgID, "CLSID" ); RegDeleteKeyA( HKEY_CLASSES_ROOT, szProgID ); // delete the class ID settings. DeleteKey( szOutCLSID, "ProgID" ); DeleteKey( szOutCLSID, "VersionIndependentProgID" ); DeleteKey( szOutCLSID, "NotInsertable" ); RegDeleteKeyA( HKEY_CLASSES_ROOT, szOutCLSID ); return S_OK; } // REGUTIL::_UnregisterClassBase
/***************************************************************************** * UnregisterInprocServer() ***************************************************************************** */ HRESULT UnregisterInprocServer ( IN REFGUID ClassId ) { WCHAR ClsIdStr[MAX_PATH]; StringFromGUID2(ClassId, ClsIdStr, MAX_PATH); WCHAR KeyName[MAX_PATH]; wcscpy(KeyName, L"CLSID\\"); wcscat(KeyName, ClsIdStr); wcscat(KeyName, L"\\InprocServer32"); RegDeleteKeyW(HKEY_CLASSES_ROOT, KeyName); wcscpy(KeyName, L"CLSID\\"); wcscat(KeyName, ClsIdStr); RegDeleteKeyW(HKEY_CLASSES_ROOT, KeyName); return S_OK; }
/*********************************************************************** * GetActiveObject (OLEAUT32.35) * * Gets an object from the global item table. * * PARAMS * rcid [I] CLSID of the object. * preserved [I] Reserved. Set to NULL. * ppunk [O] Address to store object into. * * RETURNS * Success: S_OK. * Failure: HRESULT code. */ HRESULT WINAPI GetActiveObject(REFCLSID rcid,LPVOID preserved,LPUNKNOWN *ppunk) { WCHAR guidbuf[80]; HRESULT ret; LPRUNNINGOBJECTTABLE runobtable; LPMONIKER moniker; StringFromGUID2(rcid,guidbuf,39); ret = CreateItemMoniker(pdelimiter,guidbuf,&moniker); if (FAILED(ret)) return ret; ret = GetRunningObjectTable(0,&runobtable); if (FAILED(ret)) { IMoniker_Release(moniker); return ret; } ret = IRunningObjectTable_GetObject(runobtable,moniker,ppunk); IRunningObjectTable_Release(runobtable); IMoniker_Release(moniker); return ret; }
/****************************************************************************** * Invoke -- Takes a dispid and uses it to call a method or property defined * in the script code in the context of this OrxScript. ******************************************************************************/ STDMETHODIMP OrxScript::Invoke(DISPID pDispID, REFIID riid, LCID plcid, WORD pFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* pArgErr) { FPRINTF(logfile,"OrxScript::Invoke\n"); OLECHAR lIID[100]; StringFromGUID2(riid, lIID, sizeof(lIID)); FPRINTF2(logfile,"riid %S \n",lIID); FPRINTF2(logfile,"pArgErr %p\n",pArgErr); // check parameters // According to the Doc, this should always be IID_NULL. if (riid != IID_NULL) { return E_INVALIDARG; } return CommonInvoke(pDispID, plcid, pFlags, pDispParams, pVarResult, pExcepInfo); }
static HKEY open_special_category_key(const CLSID *clsid, BOOL create) { WCHAR key_name[sizeof(wszActiveMovieKey)/sizeof(WCHAR) + CHARS_IN_GUID-1]; HKEY ret; LONG res; strcpyW(key_name, wszActiveMovieKey); if (!StringFromGUID2(clsid, key_name + sizeof(wszActiveMovieKey)/sizeof(WCHAR)-1, CHARS_IN_GUID)) return NULL; if(create) res = RegCreateKeyW(HKEY_CURRENT_USER, key_name, &ret); else res = RegOpenKeyExW(HKEY_CURRENT_USER, key_name, 0, KEY_READ, &ret); if (res != ERROR_SUCCESS) { WARN("Could not open %s\n", debugstr_w(key_name)); return NULL; } return ret; }
HRESULT RemoteDebuggerProxy::Start() { if ( mSessionGuid != GUID_NULL ) return S_OK; HRESULT hr = S_OK; GUID sessionGuid = { 0 }; wchar_t sessionGuidStr[GUID_LENGTH + 1] = L""; int ret = 0; hr = CoCreateGuid( &sessionGuid ); if ( FAILED( hr ) ) return hr; ret = StringFromGUID2( sessionGuid, sessionGuidStr, _countof( sessionGuidStr ) ); _ASSERT( ret > 0 ); if ( ret == 0 ) return E_FAIL; mSessionGuid = sessionGuid; hr = StartAgent( sessionGuidStr ); if ( FAILED( hr ) ) return hr; hr = StartServer( sessionGuidStr ); if ( FAILED( hr ) ) return hr; SetRemoteEventCallback( this ); hr = StartClient( sessionGuidStr, sessionGuid, mhContext ); SetRemoteEventCallback( NULL ); if ( FAILED( hr ) ) { StopServer(); return hr; } return S_OK; }
// // 函数名称: RegisterShellExtInfotipHandler // // 作用: 注册shell 信息提示处理方法. // // 参数: // * pszFileType - 要处理文件的类型,如“*”代表所有的文件类型, // “.txt”代表.txt文件类型。参数不能为空 // * clsid - 组件的类ID。 // // 注意: 该方法在注册表中创建了以下注册信息。 // // HKCR // { // NoRemove <File Type> // { // NoRemove shellex // { // {00021500-0000-0000-C000-000000000046} = s '{<CLSID>}' // } // } // } // HRESULT RegisterShellExtInfotipHandler(PCWSTR pszFileType, const CLSID& clsid) { if (pszFileType == NULL) { return E_INVALIDARG; } HRESULT hr; wchar_t szCLSID[MAX_PATH]; StringFromGUID2(clsid, szCLSID, ARRAYSIZE(szCLSID)); wchar_t szSubkey[MAX_PATH]; // 如果 pszFileType以‘.’开始,就试着去找包含ProgID的HKCR\<FIle Type>的默认值 if (*pszFileType == L'.') { wchar_t szDefaultVal[260]; hr = GetHKCRRegistryKeyAndValue(pszFileType, NULL, szDefaultVal, sizeof(szDefaultVal)); // 如果key存在并且默认值不空,就用ProgID作为文件的类型 if (SUCCEEDED(hr) && szDefaultVal[0] != L'\0') { pszFileType = szDefaultVal; } } //创建注册项 // HKCR\<File Type>\shellex\{00021500-0000-0000-C000-000000000046} hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey), L"%s\\shellex\\{00021500-0000-0000-C000-000000000046}", pszFileType); if (SUCCEEDED(hr)) { //设置注册项的默认值. hr = SetHKCRRegistryKeyAndValue(szSubkey, NULL, szCLSID); } return hr; }
HRESULT RegisterShellExtContextMenuHandler( PCWSTR pszFileType, const CLSID& clsid, PCWSTR pszFriendlyName) { if (pszFileType == NULL) { return E_INVALIDARG; } HRESULT hr; wchar_t szCLSID[MAX_PATH]; StringFromGUID2(clsid, szCLSID, ARRAYSIZE(szCLSID)); wchar_t szSubkey[MAX_PATH]; //如果文件的类型是以'.'开头的,然后在注册表的HKCR\<File Type>下获取该文件类型的对应的Program ID来关联该文件 if (*pszFileType == L'.') { wchar_t szDefaultVal[260]; hr = GetHKCRRegistryKeyAndValue(pszFileType, NULL, szDefaultVal, sizeof(szDefaultVal)); // 如果该键存在且不为空, 使用ProgID 为该文件类型 if (SUCCEEDED(hr) && szDefaultVal[0] != L'\0') { pszFileType = szDefaultVal; } } // 创建键 HKCR\<File Type>\shellex\ContextMenuHandlers\{<CLSID>} hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey), L"%s\\shellex\\ContextMenuHandlers\\%s", pszFileType, szCLSID); if (SUCCEEDED(hr)) { // 为该键设置默认值. hr = SetHKCRRegistryKeyAndValue(szSubkey, NULL, pszFriendlyName); } return hr; }
///////////////////////////////////////////////////////////////// // HRESULT CSession::GetSchemaRowset // ///////////////////////////////////////////////////////////////// HRESULT CSession::GetSchemaRowset(CAggregate* pCAggregate, REFGUID guidSchema, ULONG cRestrictions, VARIANT* rgRestrictions, REFIID riid, ULONG cPropSets, DBPROPSET* rgPropSets, IUnknown** ppIUnknown) { HRESULT hr = S_OK; if(!m_pIDBSchemaRowset) return E_FAIL; //Schema Rowset WCHAR wszBuffer[MAX_NAME_LEN+1]; WCHAR* pwszSchemaName = GetSchemaName(guidSchema); //Try to find the String Resprentation of the guidSchema if(pwszSchemaName == NULL) { StringFromGUID2(guidSchema, wszBuffer, MAX_NAME_LEN); pwszSchemaName = wszBuffer; } //GetSchema Rowset XTEST_(hr = m_pIDBSchemaRowset->GetRowset( pCAggregate, // punkOuter guidSchema, // schema IID cRestrictions, // # of restrictions rgRestrictions, // array of restrictions riid, // rowset interface cPropSets, // # of properties rgPropSets, // properties ppIUnknown),S_OK); // rowset pointer TRACE_METHOD(hr, L"IDBSchemaRowset::GetRowset(0x%p, %s, %d, 0x%p, %s, %d, 0x%p, &0x%p)", pCAggregate, pwszSchemaName, cRestrictions, rgRestrictions, GetInterfaceName(riid), cPropSets, rgPropSets, ppIUnknown ? *ppIUnknown : NULL); //Display Errors (if occurred) TESTC(hr = DisplayPropErrors(hr, cPropSets, rgPropSets)); //Handle Aggregation if(pCAggregate) TESTC(hr = pCAggregate->HandleAggregation(riid, ppIUnknown)); CLEANUP: return hr; }
void SaveMediaInfo(struct MediaInfo *info) { HKEY hKey; LONG lRet = RegCreateKey(HKEY_CURRENT_USER, REG_PATH, &hKey); if( lRet != ERROR_SUCCESS ) { WriteLog("Faild(%d) to RegCreateKey\n", lRet); return ; } OLECHAR szCLSID[MAX_PATH]; HRESULT hr = StringFromGUID2(info->m_Id, szCLSID, MAX_PATH); assert( SUCCEEDED(hr) ); lRet = RegSetValueEx(hKey, szCLSID, 0L, REG_BINARY, (CONST BYTE *)info, REG_SIZE); if( lRet != ERROR_SUCCESS ) { WriteLog("Faild(%d) to RegSetValueEx\n", lRet); } RegCloseKey(hKey); }
/*********************************************************************** * RegisterActiveObject (OLEAUT32.33) * * Registers an object in the global item table. * * PARAMS * punk [I] Object to register. * rcid [I] CLSID of the object. * dwFlags [I] Flags. * pdwRegister [O] Address to store cookie of object registration in. * * RETURNS * Success: S_OK. * Failure: HRESULT code. */ HRESULT WINAPI RegisterActiveObject( LPUNKNOWN punk,REFCLSID rcid,DWORD dwFlags,LPDWORD pdwRegister ) { WCHAR guidbuf[80]; HRESULT ret; LPRUNNINGOBJECTTABLE runobtable; LPMONIKER moniker; StringFromGUID2(rcid,guidbuf,39); ret = CreateItemMoniker(pdelimiter,guidbuf,&moniker); if (FAILED(ret)) return ret; ret = GetRunningObjectTable(0,&runobtable); if (FAILED(ret)) { IMoniker_Release(moniker); return ret; } ret = IRunningObjectTable_Register(runobtable,dwFlags,punk,moniker,pdwRegister); IRunningObjectTable_Release(runobtable); IMoniker_Release(moniker); return ret; }
string Uuid::gen() { GUID *pguid = new GUID(); CoCreateGuid(pguid); WCHAR *pBuf = new WCHAR[64]; int nResult = StringFromGUID2(*pguid, pBuf, 64); char * pcBuf = new char[64]; for (int i = 0; i < nResult; i++) { pcBuf[i] = pBuf [i]; } //printf("asdfsdfsd %d %s", nResult, pcBuf); //wprintf(L"aaaa %s", pBuf); string s = pcBuf; delete [] pBuf; delete [] pcBuf; return s; }
HRESULT CEffectsListDlg::doAddEffect() { int sel = SendMessage(lHwnd, LB_GETCURSEL, 0, 0); if(sel == LB_ERR)return sel; GUID* pGUID = (GUID*)SendMessage(lHwnd, LB_GETITEMDATA, sel, 0); WCHAR sguid[256]; StringFromGUID2(*pGUID, sguid, 256); // OutputDebugString(_bstr_t(sguid).operator wchar_t*()); // OutputDebugString(_T("\r\n")); TCHAR buff[128]; SendMessage(t1Hwnd, WM_GETTEXT, 128, (LPARAM)buff); REFERENCE_TIME start = _ttoi64(buff); SendMessage(t2Hwnd, WM_GETTEXT, 128, (LPARAM)buff); REFERENCE_TIME stop = _ttoi64(buff); SendMessage(trkHwnd, WM_GETTEXT, 128, (LPARAM)buff); int track = _ttoi(buff); if(SendMessage(swapHwnd, BM_GETCHECK, 0, 0) == BST_UNCHECKED)swap = false; else swap = true; if(type)return pem->addTransition(track, *pGUID, start, stop, 0, swap, NULL); else return pem->addEffect(track, *pGUID, start, stop, 0, NULL); }
std::string CreateGUID() { std::string guidStr; #ifdef WIN32 std::wstring guidWStr; guidWStr.resize(50); GUID guid; CoCreateGuid(&guid); StringFromGUID2(guid, (wchar_t*)guidWStr.c_str(), (int)guidWStr.size()); g_wcstombs(guidStr, guidWStr); #else uuid_t out; uuid_generate_time(out); for(int i = 0; i < sizeof(out); i++) { char num[10] = {0}; snprintf(num, 10, "%d", out[i]); guidStr.append(num); } #endif return guidStr.c_str(); }
static HKEY open_category_key(const CLSID *clsid) { WCHAR key_name[sizeof(wszInstanceKeyName)/sizeof(WCHAR) + CHARS_IN_GUID-1 + 6 /* strlen("CLSID\") */], *ptr; HKEY ret; strcpyW(key_name, clsid_keyname); ptr = key_name + strlenW(key_name); *ptr++ = '\\'; if (!StringFromGUID2(clsid, ptr, CHARS_IN_GUID)) return NULL; ptr += strlenW(ptr); strcpyW(ptr, wszInstanceKeyName); if (RegOpenKeyExW(HKEY_CLASSES_ROOT, key_name, 0, KEY_READ, &ret) != ERROR_SUCCESS) { WARN("Could not open %s\n", debugstr_w(key_name)); return NULL; } return ret; }
/****************************************************************************** * GetIDsOfNames -- Takes an array of strings and returns an array of DISPID's * which correspond to the methods or properties indicated. In real life, * If the name is not recognized, then DISP_E_UNKNOWNNAME is returned. * However, this is T-Rexx, we know every thing. Log the name that is being * sought, and return a bogus DispID. ******************************************************************************/ STDMETHODIMP OrxScript::GetIDsOfNames(REFIID riid, OLECHAR **pNames, UINT pNamesCount, LCID plcid, DISPID *pbDispID) { HRESULT RetCode = S_OK,RC; UINT i; char lIID[100]; StringFromGUID2(riid,(LPOLESTR)lIID,sizeof(lIID)/2); FPRINTF(logfile,"OrxScript::GetIDsOfNames\n"); FPRINTF2(logfile,"pNamesCount %d riid %S \n",pNamesCount,lIID); //check parameters if (riid != IID_NULL) { RetCode = E_INVALIDARG; } else { //loop through all the pNames that were passed in, and pass //them to the routine that deals with one name at a time. for (i = 0; i < pNamesCount; i++) { RC = GetDispID(pNames[i],fdexNameCaseInsensitive,&pbDispID[i]); if (RC != S_OK) { RetCode = RC; // The only returns the last bad error code. } } } // RetCode = S_OK; return RetCode; }