예제 #1
1
//---------------------------------------------------------------------------
// UnregisterServer
//---------------------------------------------------------------------------
BOOL UnregisterServer(CLSID clsid, LPTSTR lpszTitle) {
  TCHAR szCLSID[GUID_SIZE + 1];
  TCHAR szCLSIDKey[GUID_SIZE + 32];
  TCHAR szKeyTemp[MAX_PATH + GUID_SIZE];
  LPWSTR pwsz;

  StringFromIID(clsid, &pwsz);
  if(pwsz) {
#ifdef UNICODE
    lstrcpy(szCLSID, pwsz);
#else
    WideCharToMultiByte(CP_ACP, 0, pwsz, -1, szCLSID, ARRAYSIZE(szCLSID), NULL, NULL);
#endif
    //free the string
    LPMALLOC pMalloc;
    CoGetMalloc(1, &pMalloc);
    pMalloc->Free(pwsz);
    pMalloc->Release();
  }

  lstrcpy(szCLSIDKey, TEXT("CLSID\\"));
  lstrcat(szCLSIDKey, szCLSID);

  wsprintf(szKeyTemp, TEXT("*\\shellex\\ContextMenuHandlers\\%s"), lpszTitle);
  RegDeleteKey(HKEY_CLASSES_ROOT, szKeyTemp);

  wsprintf(szKeyTemp, TEXT("%s\\%s"), szCLSIDKey, TEXT("InprocServer32"));
  RegDeleteKey(HKEY_CLASSES_ROOT, szKeyTemp);
  RegDeleteKey(HKEY_CLASSES_ROOT, szCLSIDKey);

  return TRUE;
}
예제 #2
0
	//*
	STDMETHODIMP data_callback::QueryInterface( REFIID iid, LPVOID* ppInterface)
	{
		if ( ppInterface == NULL)
		{
			return E_INVALIDARG;
		}

#if defined _DEBUG && defined _CONSOLE
		LPOLESTR str = NULL;
		if ( SUCCEEDED( StringFromIID( iid, &str ) ) )
		{
			wprintf( L"data_callback::QueryInterface( %s )\n", str );
		}		

		if ( str )
			::CoTaskMemFree( str );
#endif

		if ( iid == IID_IUnknown )
		{
			*ppInterface = (IUnknown*) this;
		} else if ( iid == IID_IOPCDataCallback)
		{
			*ppInterface = (IOPCDataCallback*) this;
		} else
		{
			*ppInterface = NULL;
			return E_NOINTERFACE;
		}

		AddRef();
		return S_OK;
	}
예제 #3
0
STDAPI DllUnregisterServer(VOID)
{
    LPWSTR   pwsz;
    TCHAR    szCLSID[MAX_PATH];
    TCHAR    szSubKey[MAX_PATH];

    //get the CLSID in string form
    StringFromIID(CLSID_AdminEventHandler, &pwsz);

    if(pwsz)
    {
        WideCharToLocal(szCLSID, ARRAYSIZE(szCLSID), pwsz, ARRAYSIZE(szCLSID));

        //free the string
        CoTaskMemFree(pwsz);
    }
    else
    {
        return E_FAIL;
    }

    //delete the object's registry entries
    _stprintf_s(szSubKey, ARRAYSIZE(szSubKey), TEXT("CLSID\\%s"), szCLSID);
    DeleteEntireKey(HKEY_CLASSES_ROOT, szSubKey);

    return S_OK;
}
예제 #4
0
HRESULT
WINAPI
IDirectSound8_fnQueryInterface(
    LPDIRECTSOUND8 iface,
    REFIID riid,
    LPVOID * ppobj)
{
    LPOLESTR pStr;
    LPCDirectSoundImpl This = (LPCDirectSoundImpl)CONTAINING_RECORD(iface, CDirectSoundImpl, lpVtbl);

    if ((IsEqualIID(riid, &IID_IDirectSound) && This->bDirectSound8 == FALSE) || 
        (IsEqualIID(riid, &IID_IDirectSound8) && This->bDirectSound8 == TRUE) ||
        (IsEqualIID(riid, &IID_IUnknown)))
    {
        *ppobj = (LPVOID)&This->lpVtbl;
        InterlockedIncrement(&This->ref);
        return S_OK;
    }

    if (SUCCEEDED(StringFromIID(riid, &pStr)))
    {
        DPRINT("No Interface for class %s\n", pStr);
        CoTaskMemFree(pStr);
    }
    return E_NOINTERFACE;
}
예제 #5
0
파일: kdecm.cpp 프로젝트: KDE/kde-runtime
//---------------------------------------------------------------------------
// UnregisterServer
//---------------------------------------------------------------------------
BOOL UnregisterServer(CLSID clsid, LPTSTR lpszTitle)
{
/*!
 * This function removes the keys from registry
 * NOTE: we can do this better with Qt
 */

    TCHAR szCLSID[GUID_SIZE + 1];
    TCHAR szCLSIDKey[GUID_SIZE + 32];
    TCHAR szKeyTemp[MAX_PATH + GUID_SIZE];
    LPTSTR pwsz;

    StringFromIID(clsid, &pwsz);
    if(pwsz) {
        lstrcpy(szCLSID, pwsz);
        //free the string
        LPMALLOC pMalloc;
        CoGetMalloc(1, &pMalloc);
        pMalloc->Free(pwsz);
        pMalloc->Release();
    }

    lstrcpy(szCLSIDKey, TEXT("CLSID\\"));
    lstrcat(szCLSIDKey, szCLSID);

    wsprintf(szKeyTemp, TEXT("*\\shellex\\ContextMenuHandlers\\%s"), lpszTitle);
    RegDeleteKey(HKEY_CLASSES_ROOT, szKeyTemp);

    wsprintf(szKeyTemp, TEXT("%s\\%s"), szCLSIDKey, TEXT("InprocServer32"));
    RegDeleteKey(HKEY_CLASSES_ROOT, szKeyTemp);
    RegDeleteKey(HKEY_CLASSES_ROOT, szCLSIDKey);

    return TRUE;
}
예제 #6
0
	//*
	STDMETHODIMP data_callback::QueryInterface( REFIID iid, LPVOID* ppInterface)
	{
		if ( ppInterface == NULL)
		{
			return E_INVALIDARG;
		}

#if DEBUG_PRINT
		{
			cotask_holder str;
			if ( SUCCEEDED( StringFromIID( iid, str.addr() ) ) )
			{
				DWPRINT( L"data_callback::QueryInterface( %s )\n", str.get() );
			}
		}

#endif

		if ( iid == IID_IUnknown )
		{
			*ppInterface = (IUnknown*) this;
		} else if ( iid == IID_IOPCDataCallback)
		{
			*ppInterface = (IOPCDataCallback*) this;
		} else
		{
			*ppInterface = NULL;
			return E_NOINTERFACE;
		}

		AddRef();
		return S_OK;
	}
예제 #7
0
파일: primary.c 프로젝트: RareHare/reactos
HRESULT
WINAPI
PrimaryDirectSoundBuffer8Impl_fnQueryInterface(
    LPDIRECTSOUNDBUFFER8 iface,
    IN REFIID riid,
    LPVOID* ppobj)
{
    LPOLESTR pStr;
    LPCDirectSoundBuffer This = (LPCDirectSoundBuffer)CONTAINING_RECORD(iface, CDirectSoundBuffer, lpVtbl);

    if (IsEqualIID(riid, &IID_IUnknown) ||
        IsEqualIID(riid, &IID_IDirectSoundBuffer) ||
        IsEqualIID(riid, &IID_IDirectSoundBuffer8))
    {
        *ppobj = (LPVOID)&This->lpVtbl;
        InterlockedIncrement(&This->ref);
        return S_OK;
    }

    if (SUCCEEDED(StringFromIID(riid, &pStr)))
    {
        DPRINT("No Interface for class %s\n", pStr);
        CoTaskMemFree(pStr);
    }
    return E_NOINTERFACE;
}
예제 #8
0
HRESULT
WINAPI
KSPropertySetImpl_fnQueryInterface(
    LPKSPROPERTYSET iface,
    REFIID riid,
    LPVOID * ppobj)
{
    LPOLESTR pStr;
    LPCKsPropertySetImpl This = (LPCKsPropertySetImpl)CONTAINING_RECORD(iface, CKsPropertySetImpl, lpVtbl);


    if (IsEqualIID(riid, &IID_IUnknown) ||
        IsEqualIID(riid, &IID_IKsPropertySet))
    {
        *ppobj = (LPVOID)&This->lpVtbl;
        InterlockedIncrement(&This->ref);
        return S_OK;
    }

    if (SUCCEEDED(StringFromIID(riid, &pStr)))
    {
        DPRINT("No Interface for riid %s\n", pStr);
        CoTaskMemFree(pStr);
    }
    return E_NOINTERFACE;
}
예제 #9
0
BOOL RegisterToolBand(CLSID clsid)
{
HKEY     hKey;
LRESULT  lResult;
DWORD    dwDisp;
TCHAR    szCLSID[MAX_PATH];
LPWSTR   pwsz;

//get the CLSID in string form
StringFromIID(clsid, &pwsz);

if(pwsz)
   {
#ifdef UNICODE
   lstrcpyn(szCLSID, pwsz, ARRAYSIZE(szCLSID));
#else
   WideCharToMultiByte( CP_ACP,
                        0,
                        pwsz,
                        -1,
                        szCLSID,
                        ARRAYSIZE(szCLSID),
                        NULL,
                        NULL);
#endif

   //free the string
   CoTaskMemFree(pwsz);
   }

lResult = RegCreateKeyEx(  HKEY_LOCAL_MACHINE,
                           TEXT("Software\\Microsoft\\Internet Explorer\\Toolbar"),
                           0,
                           NULL,
                           REG_OPTION_NON_VOLATILE,
                           KEY_WRITE,
                           NULL,
                           &hKey,
                           &dwDisp);
   
if(NOERROR == lResult)
   {
   TCHAR szData[] = TEXT("");

   lResult = RegSetValueEx(   hKey,
                              szCLSID,
                              0,
                              REG_SZ,
                              (LPBYTE)szData,
                              lstrlen(szData) + 1);
   
   RegCloseKey(hKey);
   }
else
   return FALSE;

return TRUE;
}
예제 #10
0
//---------------------------------------------------------------------------
// RegisterServer
//---------------------------------------------------------------------------
BOOL RegisterServer(CLSID clsid, LPTSTR lpszTitle) {
  int      i;
  HKEY     hKey;
  LRESULT  lResult;
  DWORD    dwDisp;
  TCHAR    szSubKey[MAX_PATH];
  TCHAR    szCLSID[MAX_PATH];
  TCHAR    szModule[MAX_PATH];
  LPWSTR   pwsz;

  if (!CheckNpp()) {
    MsgBoxError(TEXT("To register the Notepad++ context menu extension,\r\ninstall nppcm.dll in the same directory than Notepad++.exe."));
    return FALSE;
  }

  StringFromIID(clsid, &pwsz);
  if(pwsz) {
#ifdef UNICODE
    lstrcpy(szCLSID, pwsz);
#else
    WideCharToMultiByte(CP_ACP, 0, pwsz, -1, szCLSID, ARRAYSIZE(szCLSID), NULL, NULL);
#endif
    //free the string
    LPMALLOC pMalloc;
    CoGetMalloc(1, &pMalloc);
    pMalloc->Free(pwsz);
    pMalloc->Release();
  }

  //get this app's path and file name
  GetModuleFileName(_hModule, szModule, MAX_PATH);

  DOREGSTRUCT ClsidEntries[] = {
    HKEY_CLASSES_ROOT,   TEXT("CLSID\\%s"),                              NULL,                   lpszTitle,
    HKEY_CLASSES_ROOT,   TEXT("CLSID\\%s\\InprocServer32"),              NULL,                   szModule,
    HKEY_CLASSES_ROOT,   TEXT("CLSID\\%s\\InprocServer32"),              TEXT("ThreadingModel"), TEXT("Apartment"),
    HKEY_CLASSES_ROOT,   TEXT("*\\shellex\\ContextMenuHandlers\\Notepad++"), NULL,                   szCLSID,
    NULL,                NULL,                                           NULL,                   NULL
  };

  // Register the CLSID entries
  for(i = 0; ClsidEntries[i].hRootKey; i++) {
    // Create the sub key string - for this case, insert the file extension
    wsprintf(szSubKey, ClsidEntries[i].szSubKey, szCLSID);
    lResult = RegCreateKeyEx(ClsidEntries[i].hRootKey, szSubKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, &dwDisp);
    if(NOERROR == lResult) {
      TCHAR szData[MAX_PATH];
      // If necessary, create the value string
      wsprintf(szData, ClsidEntries[i].szData, szModule);
      lResult = RegSetValueEx(hKey, ClsidEntries[i].lpszValueName, 0, REG_SZ, (LPBYTE)szData, (lstrlen(szData) + 1) * sizeof(TCHAR));
      RegCloseKey(hKey);
    }
    else
      return FALSE;
  }
  return TRUE;
}
예제 #11
0
파일: dsound.c 프로젝트: GYGit/reactos
HRESULT
WINAPI
DllGetClassObject(
  REFCLSID rclsid,
  REFIID riid,
  LPVOID* ppv)
{
    LPOLESTR pStr, pStr2;
    UINT i;
    HRESULT	hres = E_OUTOFMEMORY;
    IClassFactory * pcf = NULL;	

    if (!ppv)
        return E_INVALIDARG;

    *ppv = NULL;

    for (i = 0; InterfaceTable[i].riid; i++) 
    {
        if (IsEqualIID(InterfaceTable[i].riid, rclsid)) 
        {
            pcf = IClassFactory_fnConstructor(InterfaceTable[i].lpfnCI, NULL, NULL);
            break;
        }
    }

    if (!pcf) 
    {
        StringFromIID(rclsid, &pStr);
        StringFromIID(riid, &pStr2);
        DPRINT("No Class Available for %ws IID %ws\n", pStr, pStr2);
        CoTaskMemFree(pStr);
        CoTaskMemFree(pStr2);
        //ASSERT(0);
        return CLASS_E_CLASSNOTAVAILABLE;
    }

    hres = IClassFactory_QueryInterface(pcf, riid, ppv);
    IClassFactory_Release(pcf);

    return hres;
}
예제 #12
0
void tCOMUtil::DumpTypeInfo(ITypeInfo *typeinfo)
{
  HRESULT hr = S_OK;
  TYPEATTR* pta = NULL;

  CHECKPARAM(typeinfo);

  hr = typeinfo->GetTypeAttr(&pta);
  CHK_COM_CODE(hr);

  // prints IID
  LPOLESTR lpsz = NULL;

#ifdef __WINE__
  hr = 0;
  MessageBox(NULL, "FIX - not implemented - StringFromIID", "LuaCOM", MB_ICONEXCLAMATION);
  #warning FIX - not implemented - StringFromIID
#else
  hr = StringFromIID(pta->guid, &lpsz);
#endif

  if(FAILED(hr))
  {
    hr = StringFromCLSID(pta->guid, &lpsz);
  }

  if(SUCCEEDED(hr))
  {
    wprintf(L"\nInterface:  %s\n\n", lpsz);

    CoTaskMemFree(lpsz);
  }

  int i = 0;
  FUNCDESC *pfd = NULL;

  for(i = 0; i < pta->cFuncs; i++)
  {
    typeinfo->GetFuncDesc(i, &pfd);

    BSTR names[1];
    unsigned int dumb;

    typeinfo->GetNames(pfd->memid, names, 1, &dumb);

    printf("%.3d: %-30s\tid=0x%d\t%d param(s)\n", i,
      tUtil::bstr2string(names[0]), pfd->memid, pfd->cParams);

    typeinfo->ReleaseFuncDesc(pfd);
    SysFreeString(names[0]);
  }

  typeinfo->ReleaseTypeAttr(pta);
}
예제 #13
0
KString KIIDToString(REFIID rIID)
{
	LPOLESTR pBuf = NULL;

	if(StringFromIID(rIID, &pBuf))
		return WRONG_IID_TEXT;

	TDefaultString Ret = pBuf;

	CoTaskMemFree(pBuf);

	return (LPCTSTR)Ret;
}
예제 #14
0
// create a guid-like unique name for what have you
// this is suitable as a generic helper
TString CConsolePipe::UGHGetUniqueName() 
{
	GUID gui;
	// here i use GUIDs; other techniques include getting GetTickCount with Thread ID etc
	HRESULT hr = CoCreateGuid(&gui); // $TSEK this don't requires CoInitialize

	LPOLESTR ole = NULL;
	hr = StringFromIID(gui, &ole); // this includes enclosing {braces}

	TString str = W2TConvert(ole); // converts as necessary
	if(ole)
		CoTaskMemFree(ole);

	return str;
}
예제 #15
0
void tCOMUtil::DumpTypeInfo(ITypeInfo *typeinfo)
{
  HRESULT hr = S_OK;
  TYPEATTR* pta = NULL;

  CHECKPARAM(typeinfo);

  hr = typeinfo->GetTypeAttr(&pta);
  CHK_COM_CODE(hr);

  // prints IID
  LPOLESTR lpsz = NULL;

  hr = StringFromIID(pta->guid, &lpsz);

  if(FAILED(hr))
  {
    hr = StringFromCLSID(pta->guid, &lpsz);
  }

  if(SUCCEEDED(hr))
  {
    wprintf(L"\nInterface:  %s\n\n", lpsz);

    CoTaskMemFree(lpsz);
  }

  int i = 0;
  FUNCDESC *pfd = NULL;

  for(i = 0; i < pta->cFuncs; i++)
  {
    typeinfo->GetFuncDesc(i, &pfd);

    BSTR names[1];
    unsigned int dumb;

    typeinfo->GetNames(pfd->memid, names, 1, &dumb);

    printf("%.3d: %-30s\tid=0x%p\t%d param(s)\n", i,
      tUtil::bstr2string(names[0]), pfd->memid, pfd->cParams);

    typeinfo->ReleaseFuncDesc(pfd);
    SysFreeString(names[0]);
  }

  typeinfo->ReleaseTypeAttr(pta);
}
예제 #16
0
HRESULT
WINAPI
IDirectSoundCaptureBufferImpl_QueryInterface(
    LPDIRECTSOUNDCAPTUREBUFFER8 iface,
    IN REFIID riid,
    LPVOID* ppobj)
{
    LPOLESTR pStr;
    LPCDirectSoundCaptureBufferImpl This = (LPCDirectSoundCaptureBufferImpl)CONTAINING_RECORD(iface, CDirectSoundCaptureBufferImpl, lpVtbl);

    /* check if requested interface is supported */
    if (IsEqualIID(riid, &IID_IUnknown) ||
        IsEqualIID(riid, &IID_IDirectSoundCaptureBuffer) ||
        IsEqualIID(riid, &IID_IDirectSoundCaptureBuffer8))
    {
        *ppobj = (LPVOID)&This->lpVtbl;
        InterlockedIncrement(&This->ref);
        return S_OK;
    }

    /* check if the interface is supported */
    if (IsEqualIID(riid, &IID_IDirectSoundNotify))
    {
        if (!This->Notify)
        {
            HRESULT hr = NewDirectSoundNotify(&This->Notify, This->bLoop, This->bMix, This->hPin, This->BufferSize);
            if (FAILED(hr))
                return hr;

            *ppobj = (LPVOID)This->Notify;
            return S_OK;
        }

        /* increment reference count on existing notify object */
        IDirectSoundNotify_AddRef(This->Notify);
        *ppobj = (LPVOID)This->Notify;
        return S_OK;
    }

    /* interface not supported */
    if (SUCCEEDED(StringFromIID(riid, &pStr)))
    {
        DPRINT("No Interface for class %s\n", pStr);
        CoTaskMemFree(pStr);
    }
    return E_NOINTERFACE;
}
예제 #17
0
STDMETHODIMP C_Items::get_IID(BSTR * pVal)
{
	if (pVal == NULL)
		return E_POINTER;
		
	try {

		BSTR bs = NULL;
		StringFromIID(IID_I_Items, &bs);

		*pVal = String(bs).toBSTR();
		CoTaskMemFree(bs);
	}
	catch (C_STLNonStackException const &exception) {
		exception.Log(_T("Exception in C_Items::get_IID"));
	}

	return E_NOTIMPL;
}
예제 #18
0
HRESULT
CALLBACK
NewDirectSound(
    IUnknown* pUnkOuter,
    REFIID riid,
    LPVOID* ppvObject)
{
    LPOLESTR pStr;
    LPCDirectSoundImpl This;

    /* check param */
    if (!ppvObject)
    {
        /* invalid param */
        return E_INVALIDARG;
    }

    /* check requested interface */
    if (!IsEqualIID(riid, &IID_IUnknown) && !IsEqualIID(riid, &IID_IDirectSound) && !IsEqualIID(riid, &IID_IDirectSound8))
    {
        *ppvObject = 0;
        StringFromIID(riid, &pStr);
        DPRINT("KsPropertySet does not support Interface %ws\n", pStr);
        CoTaskMemFree(pStr);
        return E_NOINTERFACE;
    }

    /* allocate CDirectSoundCaptureImpl struct */
    This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CDirectSoundImpl));
    if (!This)
    {
        /* not enough memory */
        return DSERR_OUTOFMEMORY;
    }

    /* initialize object */
    This->ref = 1;
    This->lpVtbl = &vt_DirectSound8;
    This->bInitialized = FALSE;
    *ppvObject = (LPVOID)&This->lpVtbl;

    return S_OK;
}
예제 #19
0
void EnumConnectionPoint(IDispatch *pDisp, LPCSTR comment)
{
	if (!pDisp) return;
	HRESULT hr = S_OK;

	USES_CONVERSION;
	IConnectionPointContainer *spCPC = NULL;
	IConnectionPoint *spCP = NULL;
	IEnumConnectionPoints *ppEnum = NULL;
	IID id;
	LPOLESTR strGUID = 0;
	CComBSTR bstrId = NULL;

	if(comment) cout << comment << _T(" ");
	cout << _T("ConnectionPoint: [");
	hr = pDisp->QueryInterface(IID_IConnectionPointContainer, reinterpret_cast<void**>(&spCPC));
	if (SUCCEEDED(hr) && spCPC)
	{
		hr = spCPC->EnumConnectionPoints(&ppEnum);
		while(SUCCEEDED(ppEnum->Next(1, &spCP, NULL)) && spCP) 
		{
			spCP->GetConnectionInterface(&id);
			// 注意此处StringFromIID的正确用法, 否则会在Debug状态下出错: user breakpoint called from code 0x7c901230
			StringFromIID(id, &strGUID);
			bstrId = strGUID;
			CoTaskMemFree(strGUID);
			cout << (bstrId ? OLE2CT(bstrId) : _T("")) << _T(", ");
		}
	}
	cout << "]" << endl;
	if(spCP) spCP->Release();
	if(ppEnum) ppEnum->Release();
	if(spCPC) spCPC->Release();
/*
	{9bfbbc02-eff1-101a-84ed-00aa00341d07}	IPropertyNotifySink
	{3050f3c4-98b5-11cf-bb82-00aa00bdce0b}	HTMLObjectElementEvents
	{3050f620-98b5-11cf-bb82-00aa00bdce0b}	HTMLObjectElementEvents2
	{00020400-0000-0000-c000-000000000046}	IDispatch
	{1dc9ca50-06ef-11d2-8415-006008c3fbfc}	ITridentEventSink
	{d27cdb6d-ae6d-11cf-96b8-444553540000}	ShockwaveFlashObjects::_IShockwaveFlashEvents
*/
}
예제 #20
0
int main()
{
	// Get the name of privilege for a LUID. LUIDs can change from a Windows version to another.
	LUID privilege = { 31, 0 };
	wchar_t priv_name[100];
	DWORD len_priv_name = sizeof(priv_name);
	if (LookupPrivilegeName(nullptr, &privilege, priv_name, &len_priv_name)) {
		std::wstring priv{ priv_name };
		std::wcout << priv << std::endl;
	}
	
	// IID_IGlassTerminal       dd 6344A5B7h; Data1
	// .rdata:0000000100036320  dw 0EF1Ch; Data2
	// .rdata:0000000100036320  dw 47BAh; Data3
	// .rdata:0000000100036320  db 98h, 0B7h, 28h, 0C6h, 64h, 42h, 77h, 93h; Data4
	IID iid_glassterminal{ 0x6344A5B7, 0x0EF1C, 0x47BA, {0x98, 0xB7, 0x28, 0xC6, 0x64, 0x42, 0x77, 0x93} };

	LPOLESTR iid_string;
	StringFromIID(iid_glassterminal, &iid_string);
	std::wcout << "IID_GlassTerminal " << iid_string << std::endl;
	return 0;
}
예제 #21
0
STDMETHODIMP MyClientSite::QueryInterface(REFIID riid, void ** ppAny) {
	LPOLESTR riidString;
	HRESULT r = StringFromIID(riid, &riidString);
	if (FAILED(r)) {
		return r;
	}
	std::wcout << L"MyClientSite::QueryInterface " << riidString << std::endl;
	CoTaskMemFree(riidString);
	
    // IID_IUnknown is the REFIID of standard interface IUnknown
    if(riid == IID_IUnknown) {
		// to avoid confusion caused by virtual inheritance
		*ppAny = (IUnknown *)(IOleClientSite *)this;
		
	} else if(riid == IID_IOleClientSite) {
		*ppAny = (IOleClientSite *)this;

    } else {
		*ppAny = NULL;
		return E_NOINTERFACE;
	}
	((IUnknown *)(*ppAny))->AddRef();
	return S_OK;
}
bool CViewProps::OnButtonGUID(CButton* Button, CPLPropertyEditEx *Prop, CPLCategory *Cat)
{
	if(!m_View) return false;
	CProjectDoc* Doc = m_View->GetDocument();
	if(!Doc || !Doc->Game) return false;

	CGuidDlg dlg;
	dlg.m_Guid = Doc->m_Settings->m_GameGUID;
	if(dlg.DoModal()==IDOK)
	{
		Doc->m_Settings->m_GameGUID = dlg.m_Guid;

		CString str;
		LPOLESTR  olestr;
		StringFromIID(Doc->m_Settings->m_GameGUID, &olestr);
		str = CString(olestr);
		CoTaskMemFree(olestr);

		Prop->SetValue(str);
		m_PropList.Redraw();
	}

	return false;
}
예제 #23
0
STDAPI UnregisterServer(CLSID clsid, LPTSTR lpszTitle)
{
    int      i;
    LRESULT  lResult;
    TCHAR    szSubKey[MAX_PATH];
    TCHAR    szCLSID[MAX_PATH];
    TCHAR    szModule[MAX_PATH];
    LPWSTR   pwsz;
    DWORD    retval;
    HRESULT  hr;

    // Get the CLSID in string form.
    StringFromIID(clsid, &pwsz);

    if(pwsz)
    {
#ifdef UNICODE
        hr = StringCchCopyW(szCLSID, MAX_PATH, pwsz);
        // TODO: Add error handling for hr here.
#else
        WideCharToMultiByte( CP_ACP,
            0,
            pwsz,
            -1,
            szCLSID,
            MAX_PATH * sizeof(TCHAR),
            NULL,
            NULL);
#endif

        // Free the string.
        LPMALLOC pMalloc;
        CoGetMalloc(1, &pMalloc);
        pMalloc->Free(pwsz);
        pMalloc->Release();
    }

    // Get this app's path and file name.
    retval = GetModuleFileName(DllhInstance, szModule, MAX_PATH);
    // TODO: Add error handling to check return value for success/failure
    //       before using szModule.

    DOREGSTRUCT ClsidEntries[ ] = {
        {HKEY_CLASSES_ROOT,TEXT("CLSID\\%38s"),NULL,lpszTitle},
        {HKEY_CLASSES_ROOT,TEXT("CLSID\\%38s\\InprocServer32"),NULL,szModule},
        {HKEY_CLASSES_ROOT,TEXT("CLSID\\%38s\\InprocServer32"),TEXT("ThreadingModel"),TEXT("Apartment")},
        {NULL,NULL,NULL,NULL}
    };

    //register the CLSID entries
    for(i = 0; ClsidEntries[i].hRootKey; i++)
    {
        //create the sub key string - for this case, insert the file extension
        hr = StringCchPrintf(szSubKey, 
            MAX_PATH, 
            ClsidEntries[i].szSubKey, 
            szCLSID);
        // TODO: Add error handling code here to check the hr return value.

        lResult = RegDeleteKey(ClsidEntries[i].hRootKey,ClsidEntries[i].szSubKey);
    }
    return S_OK;  
}
예제 #24
0
void CAtmoComRegistry::SaveSettings(ATMO_BOOL force) {
    CAtmoRegistry *reg = new CAtmoRegistry(HKEY_CLASSES_ROOT);
    char buffer[MAX_PATH];
    char exe[MAX_PATH];
//    char tlb[MAX_PATH];
    wchar_t widePath[MAX_PATH];

    GetModuleFileName(GetModuleHandle(NULL),exe,MAX_PATH);

    LPOLESTR aguid = NULL;

    if((reg->RegistryKeyExists("AtmoRemoteControl.1") == ATMO_FALSE) || force) {
        reg->WriteRegistryString("AtmoRemoteControl.1\\",NULL,"AtmoRemoteControl Basic Functions");
        StringFromCLSID(CLSID_AtmoRemoteControl,&aguid);
        reg->WriteRegistryString("AtmoRemoteControl.1\\CLSID\\",NULL,(char *)(_bstr_t)aguid);
        sprintf(buffer,"CLSID\\%s",(char *)(_bstr_t)aguid);
        reg->WriteRegistryString(buffer,NULL,"AtmoRemoteControl Basic Functions");
        sprintf(buffer,"CLSID\\%s\\LocalServer32",(char *)(_bstr_t)aguid);
        reg->WriteRegistryString(buffer,NULL,exe);
        sprintf(buffer,"CLSID\\%s\\ProgID",(char *)(_bstr_t)aguid);
        reg->WriteRegistryString(buffer,NULL,"AtmoRemoteControl.1");
        CoTaskMemFree(aguid);
    }

    if((reg->RegistryKeyExists("AtmoLiveViewControl.1") == ATMO_FALSE) || force) {
        reg->WriteRegistryString("AtmoLiveViewControl.1\\",NULL,"Atmo Live View Control Object");

        StringFromCLSID(CLSID_AtmoLiveViewControl,&aguid);
        reg->WriteRegistryString("AtmoLiveViewControl.1\\CLSID\\",NULL,(char *)(_bstr_t)aguid);

        sprintf(buffer,"CLSID\\%s",(char *)(_bstr_t)aguid);
        reg->WriteRegistryString(buffer,NULL,"Atmo Live View Control Object");

        sprintf(buffer,"CLSID\\%s\\LocalServer32",(char *)(_bstr_t)aguid);
        reg->WriteRegistryString(buffer,NULL,exe);

        sprintf(buffer,"CLSID\\%s\\ProgID",(char *)(_bstr_t)aguid);
        reg->WriteRegistryString(buffer,NULL,"AtmoLiveViewControl.1");

        CoTaskMemFree(aguid);
    }


//IAtmoRemoteControl
    StringFromIID(IID_IAtmoRemoteControl,&aguid);
    sprintf(buffer,"Interface\\%s",(char *)(_bstr_t)aguid);
    reg->WriteRegistryString(buffer,NULL,"IAtmoRemoteControl");

    sprintf(buffer,"Interface\\%s\\ProxyStubClsid32",(char *)(_bstr_t)aguid);
    reg->WriteRegistryString(buffer,NULL,"{00020424-0000-0000-C000-000000000046}");

    sprintf(buffer,"Interface\\%s\\TypeLib",(char *)(_bstr_t)aguid);
    reg->WriteRegistryString(buffer,NULL,"{e01e2041-5afc-11d3-8e80-00805f91cdd9}");
    reg->WriteRegistryString(buffer,"Version","1.0");
    CoTaskMemFree(aguid);


//IAtmoRemoteControl2
    StringFromIID(IID_IAtmoRemoteControl2,&aguid);
    sprintf(buffer,"Interface\\%s",(char *)(_bstr_t)aguid);
    reg->WriteRegistryString(buffer,NULL,"IAtmoRemoteControl2");

    sprintf(buffer,"Interface\\%s\\ProxyStubClsid32",(char *)(_bstr_t)aguid);
    reg->WriteRegistryString(buffer,NULL,"{00020424-0000-0000-C000-000000000046}");

    sprintf(buffer,"Interface\\%s\\TypeLib",(char *)(_bstr_t)aguid);
    reg->WriteRegistryString(buffer,NULL,"{e01e2041-5afc-11d3-8e80-00805f91cdd9}");
    reg->WriteRegistryString(buffer,"Version","1.0");
    CoTaskMemFree(aguid);

//IID_IAtmoLiveViewControl
    StringFromIID(IID_IAtmoLiveViewControl,&aguid);
    sprintf(buffer,"Interface\\%s",(char *)(_bstr_t)aguid);
    reg->WriteRegistryString(buffer,NULL,"IAtmoLiveViewControl");

    sprintf(buffer,"Interface\\%s\\ProxyStubClsid32",(char *)(_bstr_t)aguid);
    reg->WriteRegistryString(buffer,NULL,"{00020424-0000-0000-C000-000000000046}");

// {e01e2041-5afc-11d3-8e80-00805f91cdd9}
    sprintf(buffer,"Interface\\%s\\TypeLib",(char *)(_bstr_t)aguid);
    reg->WriteRegistryString(buffer,NULL,"{e01e2041-5afc-11d3-8e80-00805f91cdd9}");
    reg->WriteRegistryString(buffer,"Version","1.0");
    CoTaskMemFree(aguid);

    MultiByteToWideChar(CP_ACP, 0, exe, lstrlen(exe) + 1, widePath, MAX_PATH);
    ITypeLib *typeLib = NULL;
    HRESULT res;
    res = LoadTypeLib( widePath, &typeLib);
    if(res != S_OK) 
    {
       char buf[100];
       sprintf(buf, "LoadTypeLib failed. Code: 0x%.8x", res);
       MessageBox(0, buf, "Error" ,0);
    }

/*
 S_OK
 E_OUTOFMEMORY
 E_INVALIDARG
 TYPE_E_IOERROR
 TYPE_E_REGISTRYACCESS --> Vista Problem mit Registry und dem UAC krams!
 TYPE_E_INVALIDSTATE 
*/
    if(typeLib)
    {
       res = RegisterTypeLib(typeLib, widePath, 0);
       if(res == TYPE_E_REGISTRYACCESS)
       {
          HMODULE oleaut32 = GetModuleHandle("Oleaut32.dll");  
          if(oleaut32 != 0)
          {
            OaEnablePerUserTLibRegistrationFn oaEnablePerUserTLibRegistration = (OaEnablePerUserTLibRegistrationFn )GetProcAddress(oleaut32, "OaEnablePerUserTLibRegistration");
            if(oaEnablePerUserTLibRegistration)
            {
               oaEnablePerUserTLibRegistration();
               res = RegisterTypeLib(typeLib, widePath, 0);
            }
          }
       }
       if( res != S_OK ) 
       {
           if(force)
           {
              char buf[100];
              sprintf(buf, "RegisterTypeLib failed. Code: 0x%.8x", res);
              MessageBox(0, buf, "Error" ,0);
           }
       } else {
           if(force)
              MessageBox(0,"COM Server registered Ok!","Info",0);
       }
       typeLib->Release();
    }

    delete reg;
};
예제 #25
0
STDAPI DllRegisterServer(void)
{
    int      i;
    HKEY     hKey;
    LRESULT  lResult;
    DWORD    dwDisp;
    TCHAR    szSubKey[MAX_PATH];
    TCHAR    szCLSID[MAX_PATH];
    TCHAR    szModule[MAX_PATH];
    LPWSTR   pwsz;

    //get the CLSID in string form
    StringFromIID(CLSID_AdminEventHandler, &pwsz);

    if(pwsz)
    {
        WideCharToLocal(szCLSID, ARRAYSIZE(szCLSID), pwsz, ARRAYSIZE(szCLSID));

        //free the string
        LPMALLOC pMalloc;
        CoGetMalloc(1, &pMalloc);
        if(pMalloc)
        {
            pMalloc->Free(pwsz);
            pMalloc->Release();
        }
    }

    //get this DLL's path and file name
    GetModuleFileName(g_hInst, szModule, ARRAYSIZE(szModule));

    //register the CLSID entries
    REGSTRUCT ClsidEntries[] = {HKEY_CLASSES_ROOT,   TEXT("CLSID\\%s"),                                   NULL,                   g_szMainTitle,
                                HKEY_CLASSES_ROOT,   TEXT("CLSID\\%s\\InprocServer32"),                   NULL,                   TEXT("%s"),
                                HKEY_CLASSES_ROOT,   TEXT("CLSID\\%s\\InprocServer32"),                   TEXT("ThreadingModel"), TEXT("Apartment"),
                                NULL,                NULL,                                                NULL,                   NULL};

    for(i = 0; ClsidEntries[i].hRootKey; i++)
    {
        //Create the sub key string.
        _stprintf_s(szSubKey, ARRAYSIZE(szSubKey), ClsidEntries[i].lpszSubKey, szCLSID);

        lResult = RegCreateKeyEx(   ClsidEntries[i].hRootKey,
                                    szSubKey,
                                    0,
                                    NULL,
                                    REG_OPTION_NON_VOLATILE,
                                    KEY_WRITE,
                                    NULL,
                                    &hKey,
                                    &dwDisp);
           
        if(NOERROR == lResult)
        {
            TCHAR szData[MAX_PATH] = TEXT("");

            //if necessary, create the value string
            _stprintf_s(szData, ARRAYSIZE(szData), ClsidEntries[i].lpszData, szModule);

            lResult = RegSetValueEx(    hKey,
                                        ClsidEntries[i].lpszValueName,
                                        0,
                                        REG_SZ,
                                        (LPBYTE)szData,
                                        lstrlen(szData) + 1);

            RegCloseKey(hKey);
        }
        else
        {
            return SELFREG_E_CLASS;
        }
    }

    return S_OK;
}
예제 #26
0
STDAPI RegisterServer(CLSID clsid, LPTSTR lpszTitle)
{
    int      i;
    HKEY     hKey;
    LRESULT  lResult;
    DWORD    dwDisp;
    TCHAR    szSubKey[MAX_PATH];
    TCHAR    szCLSID[MAX_PATH];
    TCHAR    szModule[MAX_PATH];
    LPWSTR   pwsz;
    DWORD    retval;
    HRESULT  hr;
    size_t   length;

    // Get the CLSID in string form.
    StringFromIID(clsid, &pwsz);

    if(pwsz)
    {
#ifdef UNICODE
        hr = StringCchCopyW(szCLSID, MAX_PATH, pwsz);
        // TODO: Add error handling for hr here.
#else
        WideCharToMultiByte( CP_ACP,
            0,
            pwsz,
            -1,
            szCLSID,
            MAX_PATH * sizeof(TCHAR),
            NULL,
            NULL);
#endif

        // Free the string.
        LPMALLOC pMalloc;
        CoGetMalloc(1, &pMalloc);
        pMalloc->Free(pwsz);
        pMalloc->Release();
    }

    // Get this app's path and file name.
    retval = GetModuleFileName(DllhInstance, szModule, MAX_PATH);
    // TODO: Add error handling to check return value for success/failure
    //       before using szModule.

    DOREGSTRUCT ClsidEntries[ ] = {
        {HKEY_CLASSES_ROOT,TEXT("CLSID\\%38s"),NULL,lpszTitle},
        {HKEY_CLASSES_ROOT,TEXT("CLSID\\%38s\\InprocServer32"),NULL,szModule},
        {HKEY_CLASSES_ROOT,TEXT("CLSID\\%38s\\InprocServer32"),TEXT("ThreadingModel"),TEXT("Apartment")},
        {NULL,NULL,NULL,NULL}
    };

    //register the CLSID entries
    for(i = 0; ClsidEntries[i].hRootKey; i++)
    {
        //create the sub key string - for this case, insert the file extension
        hr = StringCchPrintf(szSubKey, 
            MAX_PATH, 
            ClsidEntries[i].szSubKey, 
            szCLSID);
        // TODO: Add error handling code here to check the hr return value.

        lResult = RegCreateKeyEx(ClsidEntries[i].hRootKey,
            szSubKey,
            0,
            NULL,
            REG_OPTION_NON_VOLATILE,
            KEY_WRITE,
            NULL,
            &hKey,
            &dwDisp);

        if(NOERROR == lResult)
        {
            TCHAR szData[MAX_PATH];

            // If necessary, create the value string.
            hr = StringCchPrintf(szData, 
                MAX_PATH, 
                ClsidEntries[i].szData, 
                szModule);
            // TODO: Add error handling code here to check the hr return value.

            hr = StringCchLength(szData, MAX_PATH, &length);
            // TODO: Add error handling code here to check the hr return value.

            lResult = RegSetValueEx(hKey,
                ClsidEntries[i].lpszValueName,
                0,
                REG_SZ,
                (LPBYTE)szData,
                (DWORD)((length + 1) * sizeof(TCHAR)));

            RegCloseKey(hKey);
        }
        else
            return E_FAIL;
    }

    return S_OK;
}
예제 #27
0
파일: Applet.cpp 프로젝트: 183amir/workrave
BOOL
RegisterServer(CLSID clsid, LPTSTR lpszTitle, BOOL reg)
{
  int      i;
  HKEY     hKey;
  LRESULT  lResult;
  DWORD    dwDisp;
  TCHAR    szSubKey[MAX_PATH];
  TCHAR    szCLSID[MAX_PATH];
  TCHAR    szModule[MAX_PATH];
  LPWSTR   pwsz;

  //get the CLSID in string form
  StringFromIID(clsid, &pwsz);

  if (pwsz)
    {
#ifdef UNICODE
      lstrcpy(szCLSID, pwsz);
#else
      WideCharToMultiByte( CP_ACP,
                           0,
                           pwsz,
                           -1,
                           szCLSID,
                           ARRAYSIZE(szCLSID),
                           NULL,
                           NULL);
#endif

      //free the string
      CoTaskMemFree(pwsz);
    }

  //get this app's path and file name
  GetModuleFileName(g_hInst, szModule, ARRAYSIZE(szModule));

  DOREGSTRUCT ClsidEntries[] = {HKEY_CLASSES_ROOT,   TEXT("CLSID\\%s"),                  NULL,                   lpszTitle,
                                HKEY_CLASSES_ROOT,   TEXT("CLSID\\%s\\InprocServer32"),  NULL,                   szModule,
                                HKEY_CLASSES_ROOT,   TEXT("CLSID\\%s\\InprocServer32"),  TEXT("ThreadingModel"), TEXT("Apartment")
    };

  if (reg)
    {
      //register the CLSID entries
      for(i = 0; i < sizeof(ClsidEntries)/sizeof(ClsidEntries[0]); i++)
        {
          //create the sub key string - for this case, insert the file extension
          wsprintf(szSubKey, ClsidEntries[i].szSubKey, szCLSID);

          lResult = RegCreateKeyEx(  ClsidEntries[i].hRootKey,
                                     szSubKey,
                                     0,
                                     NULL,
                                     REG_OPTION_NON_VOLATILE,
                                     KEY_WRITE,
                                     NULL,
                                     &hKey,
                                     &dwDisp);

          if (NOERROR == lResult)
            {
              TCHAR szData[MAX_PATH];

              //if necessary, create the value string
              wsprintf(szData, ClsidEntries[i].szData, szModule);

              lResult = RegSetValueEx(   hKey,
                                         ClsidEntries[i].lpszValueName,
                                         0,
                                         REG_SZ,
                                         (LPBYTE)szData,
                                         lstrlen(szData) + 1);

              RegCloseKey(hKey);
            }
          else
            return FALSE;
        }
    }
  else
    {
      //create the sub key string - for this case, insert the file extension
      wsprintf(szSubKey, ClsidEntries[0].szSubKey, szCLSID);

      SHDeleteKey(ClsidEntries[0].hRootKey, szSubKey);
    }

  //If running on NT, register the extension as approved.
  OSVERSIONINFO  osvi;

  osvi.dwOSVersionInfoSize = sizeof(osvi);
  GetVersionEx(&osvi);

  if (VER_PLATFORM_WIN32_NT == osvi.dwPlatformId)
    {
      lstrcpy( szSubKey, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved"));

      lResult = RegCreateKeyEx(  HKEY_LOCAL_MACHINE,
                                 szSubKey,
                                 0,
                                 NULL,
                                 REG_OPTION_NON_VOLATILE,
                                 KEY_WRITE,
                                 NULL,
                                 &hKey,
                                 &dwDisp);

      if (NOERROR == lResult)
        {
          TCHAR szData[MAX_PATH];

          //Create the value string.
          lstrcpy(szData, lpszTitle);

          if (reg)
            {
              lResult = RegSetValueEx(   hKey,
                                         szCLSID,
                                         0,
                                         REG_SZ,
                                         (LPBYTE)szData,
                                         (lstrlen(szData) + 1) * sizeof(TCHAR));
            }
          else
            {
              lResult = RegDeleteValue(hKey, szCLSID);
            }

          RegCloseKey(hKey);
        }
      else
        return FALSE;
    }

  return TRUE;
}
예제 #28
0
void GetInterfaceNameByIID(const GUID &aIID, BSTR *aName)
{
    Assert(aName);
    if (!aName)
        return;

    *aName = NULL;

#if !defined(VBOX_WITH_XPCOM)

    LONG rc;
    LPOLESTR iidStr = NULL;
    if (StringFromIID(aIID, &iidStr) == S_OK)
    {
        HKEY ifaceKey;
        rc = RegOpenKeyExW(HKEY_CLASSES_ROOT, L"Interface",
                           0, KEY_QUERY_VALUE, &ifaceKey);
        if (rc == ERROR_SUCCESS)
        {
            HKEY iidKey;
            rc = RegOpenKeyExW(ifaceKey, iidStr, 0, KEY_QUERY_VALUE, &iidKey);
            if (rc == ERROR_SUCCESS)
            {
                /* determine the size and type */
                DWORD sz, type;
                rc = RegQueryValueExW(iidKey, NULL, NULL, &type, NULL, &sz);
                if (rc == ERROR_SUCCESS && type == REG_SZ)
                {
                    /* query the value to BSTR */
                    *aName = SysAllocStringLen(NULL, (sz + 1) / sizeof(TCHAR) + 1);
                    rc = RegQueryValueExW(iidKey, NULL, NULL, NULL, (LPBYTE) *aName, &sz);
                    if (rc != ERROR_SUCCESS)
                    {
                        SysFreeString(*aName);
                        aName = NULL;
                    }
                }
                RegCloseKey(iidKey);
            }
            RegCloseKey(ifaceKey);
        }
        CoTaskMemFree(iidStr);
    }

#else /* !defined (VBOX_WITH_XPCOM) */

    nsresult rv;
    nsCOMPtr<nsIInterfaceInfoManager> iim =
        do_GetService(NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID, &rv);
    if (NS_SUCCEEDED(rv))
    {
        nsCOMPtr<nsIInterfaceInfo> iinfo;
        rv = iim->GetInfoForIID(&aIID, getter_AddRefs(iinfo));
        if (NS_SUCCEEDED(rv))
        {
            const char *iname = NULL;
            iinfo->GetNameShared(&iname);
            char *utf8IName = NULL;
            if (RT_SUCCESS(RTStrCurrentCPToUtf8(&utf8IName, iname)))
            {
                PRTUTF16 utf16IName = NULL;
                if (RT_SUCCESS(RTStrToUtf16(utf8IName, &utf16IName)))
                {
                    *aName = SysAllocString((OLECHAR *) utf16IName);
                    RTUtf16Free(utf16IName);
                }
                RTStrFree(utf8IName);
            }
        }
    }

#endif /* !defined (VBOX_WITH_XPCOM) */
}
예제 #29
0
I_MapItem *C_Items::NewItem(CLSID clsid, IID iid, String &key)		
{ 
	try {

		I_MapItem *item = NULL;
		IUnknown *pUnk = NULL;

		HRESULT hr = S_OK;

		//
		// Create an instance of the SimpleCalculator object 
		// and grab an IUnknown interface.
		//
		hr = CoCreateInstance(
			 clsid, 
			 NULL, 
			 CLSCTX_INPROC_SERVER, 
			 IID_IUnknown, 
			 (void**)&pUnk);

#ifdef DEBUG
		if (FAILED(hr)) {

			BSTR bs = NULL;

			StringFromCLSID(clsid, &bs);
			String sCLSID(bs);
			CoTaskMemFree(bs);

			StringFromIID(iid, &bs);
			String sIID(bs);
			CoTaskMemFree(bs);

			String s(_T("Failed to create instance\n"));
			s += sCLSID;
			s += _T("\n");
			s += sIID;

			::MessageBox(
				NULL, 
				s.toLPCTSTR(), 
				_T("Error!"), 
				MB_ICONERROR
			);
			return NULL;
		}
#endif

		//
		// Query the object for the IArithmetic interface.
		//
		hr = pUnk->QueryInterface(
		  iid, 
		  (void **)&item);
		pUnk->Release();

		if (FAILED(hr)) {
		  MessageBox(
			  NULL, 
			 _T("Failed to get IID"), 
			 _T("Error!"), 
			 MB_ICONERROR);	
		}

		if (item) {

			BSTR bs = NULL;

			C_ItemPtr mi(item);
			C_UniquePtr unique(item);

			if (mi && unique) {

				unique->get_UID(&bs);

				Add(bs, mi);
				String::FreeBSTR(&bs);
			}

			item->Release();
			return item;
		}
	}
	catch (C_STLNonStackException const &exception) {
		exception.Log(_T("Exception in C_Items::NewItem"));
	}
	catch (...) {
		_ASSERTE(0);
	}

	return NULL; 
}
예제 #30
0
파일: kdecm.cpp 프로젝트: KDE/kde-runtime
//---------------------------------------------------------------------------
// RegisterServer
//---------------------------------------------------------------------------
BOOL RegisterServer(CLSID clsid, LPTSTR lpszTitle)
{
#if 0
    TCHAR           dllPath[MAX_PATH];

    QSettings       settings("HKEY_CLASSES_ROOT", QSettings::NativeFormat);

    //get this app's path and file name
    GetModuleFileNameW(_hModule, dllPath, MAX_PATH);

    qDebug() << "register dll for KDE ContextMenu:" << lptstr2QString( dllPath );

    settings.setValue(QString("CLSID/") + clsid2QString(clsid) + 
                      QString("/Default"), lptstr2QString( lpszTitle ));
    settings.setValue(QString("CLSID/") + clsid2QString(clsid) + 
                      QString("/InprocServer32/Default"), lptstr2QString( dllPath ) );
    settings.setValue(QString("CLSID/") + clsid2QString(clsid) + 
                      QString("/InprocServer32/ThreadingModel"), "Apartment" );
    settings.setValue(QString("/*/shellex/ContextMenuHandlers/") + lptstr2QString(lpszTitle) + 
                      QString("/Default"), clsid2QString(clsid) );
    return TRUE;
#else
  int      i;
  HKEY     hKey;
  LRESULT  lResult;
  DWORD    dwDisp;
  TCHAR    szSubKey[MAX_PATH];
  TCHAR    szCLSID[MAX_PATH];
  TCHAR    szModule[MAX_PATH];
  LPOLESTR   pwsz;

  StringFromIID(clsid, &pwsz);
  if(pwsz) {
    lstrcpy(szCLSID, pwsz);
    //free the string
    LPMALLOC pMalloc;
    CoGetMalloc(1, &pMalloc);
    pMalloc->Free(pwsz);
    pMalloc->Release();
  }

  //get this app's path and file name
  GetModuleFileName(_hModule, szModule, MAX_PATH);

  DOREGSTRUCT ClsidEntries[] = {
    HKEY_CLASSES_ROOT,   TEXT("CLSID\\%s"),                              NULL,                   lpszTitle,
    HKEY_CLASSES_ROOT,   TEXT("CLSID\\%s\\InprocServer32"),              NULL,                   szModule,
    HKEY_CLASSES_ROOT,   TEXT("CLSID\\%s\\InprocServer32"),              TEXT("ThreadingModel"), TEXT("Apartment"),
    HKEY_CLASSES_ROOT,   TEXT("*\\shellex\\ContextMenuHandlers\\Kate"), NULL,                   szCLSID,
    NULL,                NULL,                                           NULL,                   NULL
  };

  // Register the CLSID entries
  for(i = 0; ClsidEntries[i].hRootKey; i++) {
    // Create the sub key string - for this case, insert the file extension
    wsprintf(szSubKey, ClsidEntries[i].szSubKey, szCLSID);
    lResult = RegCreateKeyEx(ClsidEntries[i].hRootKey, szSubKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, &dwDisp);
    if(NOERROR == lResult) {
      TCHAR szData[MAX_PATH];
      // If necessary, create the value string
      wsprintf(szData, ClsidEntries[i].szData, szModule);
      lResult = RegSetValueEx(hKey, ClsidEntries[i].lpszValueName, 0, REG_SZ, (LPBYTE)szData, (lstrlen(szData) + 1) * sizeof(TCHAR));
      RegCloseKey(hKey);
    }
    else
      return FALSE;
  }
  return TRUE;
#endif
}