extern "C" HRESULT EXPORTS DBIFN DllGetDataSnapClassObject(REFCLSID rclsid, REFIID riid, pVOID *ppv)
{
#if defined(__ANDROID__)
   if (InitICUMidas())
     return E_UNABLETOLOADICU;
   else
#endif
     return DllGetClassObject(rclsid, riid, ppv);
}
Esempio n. 2
0
//--------------------------------------------------------------------------
// getInstance
//  Singleton: Handled by COM.
CComPtr<IProtPatchApplication> Application::getInstance()
{
  CComPtr<IProtPatchApplication> protocolPatchApp;
  // get class factory
  CComPtr<IClassFactory> classFactory;
  if (SUCCEEDED(DllGetClassObject(CLSID_ProtPatchApplication, IID_IClassFactory, (LPVOID*)&classFactory.p))) {
    classFactory->CreateInstance(NULL, IID_IProtPatchApplication, (void**)&protocolPatchApp.p);
  }
  return protocolPatchApp;
}
Esempio n. 3
0
int main(void) {
	CISavi3 *pSAVI;
	HRESULT hr;
	U32 ide_string_length  = 100;
	CIEnumIDEDetails *IDElist = NULL;
	OLECHAR ide_version_string[101];
	SYSTEMTIME ide_date;
	U32 ide_detects_viruses;
	U32 engine_version; 
	const char *ClientName = "tracenetwork";
	CISweepClassFactory2 *pFactory;
	hr=DllGetClassObject(
		(REFIID)&SOPHOS_CLASSID_SAVI,
		(REFIID)&SOPHOS_IID_CLASSFACTORY2,
		(void **) &pFactory);

	if(!(hr==SOPHOS_S_OK)) {
		printf("Could not initialize SAVI class/object\n");
                exit(1);
        } else {
                hr=pFactory->pVtbl->CreateInstance(pFactory, NULL, &SOPHOS_IID_SAVI3, (void **) &pSAVI );
                pFactory->pVtbl->Release(pFactory);
                if (hr == SOPHOS_S_OK) {
                        hr=pSAVI->pVtbl->InitialiseWithMoniker(pSAVI, ClientName);
                        if(SOPHOS_FAILED(hr)) {
                                printf("%s Failed to initialize SAVI [%ld]\n",(long) hr);
				pSAVI->pVtbl->Release(pSAVI);
				pSAVI = NULL;
				exit(1);
			}
		}
	}

	hr = pSAVI->pVtbl->GetVirusEngineVersion(pSAVI,
						&engine_version,
						(LPOLESTR) ide_version_string,
						ide_string_length,
						&ide_date,
						&ide_detects_viruses,
						NULL,
						(REFIID) &SOPHOS_IID_ENUM_IDEDETAILS,
						(void **) &IDElist);

	if(SOPHOS_FAILED(hr)) {
		printf("Failed to obtain version information for engine/IDE\n");
		exit(1);
	} else {
		printf("Engine version\t: %u.%u\n", (unsigned int) ((engine_version & 0xFFFF0000) >> 16), (unsigned int) (engine_version & 0x0000FFFF));
		printf("IDE version\t: %s \n", ide_version_string);
		printf("Virus detection\t: %u\n", (unsigned int) ide_detects_viruses);

	}
	exit(0);
}
static COMPtr<IClassFactory> classFactory(const CLSID& clsid)
{
    typedef HashMap<CLSID, COMPtr<IClassFactory>, CLSIDHash, CLSIDHashTraits> FactoryMap;
    static FactoryMap& factories = *new FactoryMap;

    pair<FactoryMap::iterator, bool> result = factories.add(clsid, 0);
    COMPtr<IClassFactory>& factory = result.first->second;
    bool added = result.second;
    if (added && FAILED(DllGetClassObject(clsid, __uuidof(factory), reinterpret_cast<void**>(&factory))))
        factory = 0;

    return factory;
}
Esempio n. 5
0
bool CNavDesktopModule::_InitDownInterface()
{
	bool bRet = false;
	HMODULE _hModule = ::LoadLibrary(L"navdownloader.dll");
	if ( !_hModule )	goto Exit0;

	pfnDllGetClassObject DllGetClassObject = (pfnDllGetClassObject)::GetProcAddress(_hModule, "DllGetClassObject");
	if ( !DllGetClassObject )	goto Exit0;

	DllGetClassObject(CLSID_CNavDownLoader, IID_INavDownloader, (void**)&m_piDownLoader);
	if ( !m_piDownLoader )	goto Exit0;

	bRet = true;
	m_piDownLoader->Initialize();

Exit0:
	return bRet;
}
Esempio n. 6
0
int main(int argc, char** argv)
{
	try
	{
#ifdef WIN32
		DllMain(0, DLL_PROCESS_ATTACH, 0);
#endif

		IClassFactory* pFact = 0;
		CheckHr(DllGetClassObject(CLSID_TestGenericFactory, IID_IClassFactory, (void**)&pFact));

		IUnknown* pTest = 0;
		CheckHr(pFact->CreateInstance(0, IID_IUnknown, (void**)&pTest));

		pFact->Release();
		pTest->Release();

#ifdef WIN32
		return DllMain(0, DLL_PROCESS_DETACH, 0) ? 0 : 1;
#else
		return 0;
#endif
	}
	catch (Throwable& thr)
	{
		std::cerr << "Failed HRESULT: " << thr.Error() << "\n";
	}
	catch (std::exception& e)
	{
		std::cerr << "Exception: " << e.what() << "\n";
	}
	catch (...)
	{
		std::cerr << "Unknown Exception:\n";
	}

	return 2;
}
Esempio n. 7
0
// Creates and returns an Impl object based on the given class ID.
// Will create the appropriate kind of API class and attach it.
//
// Implementation note:  This function does the following:
// 1) Create the API class.  (The API class will create the Impl class
//    and attach it.)
// 2) Ask the newly created API class for its contained Impl class.
// 3) Return that Impl class.
//
ImplAAFRoot * CreateImpl (const aafClassID_t & rClassID)
{
    IAAFRoot	*pIAAFRoot;
    ImplAAFRoot	*implRoot;
    HRESULT		hr;
    CLSID           classID;

    // Cast (by bitwise copy) from aafClassID_t to CLSID.
    //
    memcpy(&classID, &rClassID, sizeof(CLSID));

    // The reference implementation must be "self-contained". We do
    // not want any user supplied classes to be created and used
    // instead on one our built-in classes.
    //
    // The simplest change is to just simulate a call to
    // CoCreateInstance:
    //
    // This code is invoked within the current module so we
    // should just be able to call the DllGetClassObject entry point
    // instead of calling CoCreateInstance and searching the
    // registry.
    IClassFactory *pFactory = NULL;
    hr = DllGetClassObject(classID, IID_IClassFactory, (void **)&pFactory);
    if (SUCCEEDED(hr))
    {
        hr = pFactory->CreateInstance(NULL, IID_IAAFRoot, (void **)&pIAAFRoot);
        pFactory->Release();
    }

    if (SUCCEEDED(hr))
        pIAAFRoot->GetImplRep((void **)&implRoot);
    else
        implRoot = NULL;

    return (implRoot);
}
Esempio n. 8
0
/*************************************************************************
 * SHCoCreateInstance [SHELL32.102]
 *
 * Equivalent to CoCreateInstance. Under Windows 9x this function could sometimes
 * use the shell32 built-in "mini-COM" without the need to load ole32.dll - see
 * SHLoadOLE for details.
 *
 * Under wine if a "LoadWithoutCOM" value is present or the object resides in
 * shell32.dll the function will load the object manually without the help of ole32
 *
 * NOTES
 *     exported by ordinal
 *
 * SEE ALSO
 *     CoCreateInstace, SHLoadOLE
 */
HRESULT WINAPI SHCoCreateInstance(
    LPCWSTR aclsid,
    const CLSID *clsid,
    LPUNKNOWN pUnkOuter,
    REFIID refiid,
    LPVOID *ppv)
{
    DWORD    hres;
    CLSID    iid;
    const    CLSID * myclsid = clsid;
    WCHAR    sKeyName[MAX_PATH];
    const    WCHAR sCLSID[7] = {'C','L','S','I','D','\\','\0'};
    WCHAR    sClassID[60];
    const WCHAR sInProcServer32[16] ={'\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2','\0'};
    const WCHAR sLoadWithoutCOM[15] ={'L','o','a','d','W','i','t','h','o','u','t','C','O','M','\0'};
    WCHAR    sDllPath[MAX_PATH];
    HKEY    hKey;
    DWORD    dwSize;
    BOOLEAN bLoadFromShell32 = FALSE;
    BOOLEAN bLoadWithoutCOM = FALSE;
    CComPtr<IClassFactory>        pcf;

    if(!ppv) return E_POINTER;
    *ppv=NULL;

    /* if the clsid is a string, convert it */
    if (!clsid)
    {
      if (!aclsid) return REGDB_E_CLASSNOTREG;
      CLSIDFromString((LPOLESTR)aclsid, &iid);
      myclsid = &iid;
    }

    TRACE("(%p,%s,unk:%p,%s,%p)\n",
        aclsid, shdebugstr_guid(myclsid), pUnkOuter, shdebugstr_guid(&refiid), ppv);

    /* we look up the dll path in the registry */
        __SHGUIDToStringW(*myclsid, sClassID);
    wcscpy(sKeyName, sCLSID);
    wcscat(sKeyName, sClassID);
    wcscat(sKeyName, sInProcServer32);

    if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_CLASSES_ROOT, sKeyName, 0, KEY_READ, &hKey)) {
        dwSize = sizeof(sDllPath);
        SHQueryValueExW(hKey, NULL, 0,0, sDllPath, &dwSize );

        /* if a special registry key is set, we load a shell extension without help of OLE32 */
        bLoadWithoutCOM = (ERROR_SUCCESS == SHQueryValueExW(hKey, sLoadWithoutCOM, 0, 0, 0, 0));

        /* if the com object is inside shell32, omit use of ole32 */
        bLoadFromShell32 = (0==lstrcmpiW( PathFindFileNameW(sDllPath), sShell32));

        RegCloseKey (hKey);
    } else {
        /* since we can't find it in the registry we try internally */
        bLoadFromShell32 = TRUE;
    }

    TRACE("WithoutCom=%u FromShell=%u\n", bLoadWithoutCOM, bLoadFromShell32);

    /* now we create an instance */
    if (bLoadFromShell32) {
        if (! SUCCEEDED(DllGetClassObject(*myclsid, IID_IClassFactory, (LPVOID*)&pcf))) {
            ERR("LoadFromShell failed for CLSID=%s\n", shdebugstr_guid(myclsid));
        }
    } else if (bLoadWithoutCOM) {

        /* load an external dll without ole32 */
        HINSTANCE hLibrary;
        typedef HRESULT (CALLBACK *DllGetClassObjectFunc)(REFCLSID clsid, REFIID iid, LPVOID *ppv);
        DllGetClassObjectFunc DllGetClassObject;

        if ((hLibrary = LoadLibraryExW(sDllPath, 0, LOAD_WITH_ALTERED_SEARCH_PATH)) == 0) {
            ERR("couldn't load InprocServer32 dll %s\n", debugstr_w(sDllPath));
        hres = E_ACCESSDENIED;
            goto end;
        } else if (!(DllGetClassObject = (DllGetClassObjectFunc)GetProcAddress(hLibrary, "DllGetClassObject"))) {
            ERR("couldn't find function DllGetClassObject in %s\n", debugstr_w(sDllPath));
            FreeLibrary( hLibrary );
        hres = E_ACCESSDENIED;
            goto end;
        } else if (! SUCCEEDED(hres = DllGetClassObject(*myclsid, IID_IClassFactory, (LPVOID*)&pcf))) {
            TRACE("GetClassObject failed 0x%08x\n", hres);
            goto end;
        }

    } else {

        /* load an external dll in the usual way */
        hres = CoCreateInstance(*myclsid, pUnkOuter, CLSCTX_INPROC_SERVER, refiid, ppv);
        goto end;
    }

    /* here we should have a ClassFactory */
    if (!pcf) return E_ACCESSDENIED;

    hres = pcf->CreateInstance(pUnkOuter, refiid, ppv);
end:
    if(hres!=S_OK)
    {
      ERR("failed (0x%08x) to create CLSID:%s IID:%s\n",
              hres, shdebugstr_guid(myclsid), shdebugstr_guid(&refiid));
      ERR("class not found in registry\n");
    }

    TRACE("-- instance: %p\n",*ppv);
    return hres;
}
Esempio n. 9
0
/*************************************************************************
 * SHCoCreateInstance [SHELL32.102]
 *
 * Equivalent to CoCreateInstance. Under Windows 9x this function could sometimes
 * use the shell32 built-in "mini-COM" without the need to load ole32.dll - see
 * SHLoadOLE for details.
 *
 * Under wine if a "LoadWithoutCOM" value is present or the object resides in
 * shell32.dll the function will load the object manually without the help of ole32
 *
 * NOTES
 *     exported by ordinal
 *
 * SEE ALSO
 *     CoCreateInstace, SHLoadOLE
 */
HRESULT WINAPI SHCoCreateInstance(
	LPCWSTR aclsid,
	const CLSID *clsid,
	LPUNKNOWN pUnkOuter,
	REFIID refiid,
	LPVOID *ppv)
{
	DWORD	hres;
	IID	iid;
	const	CLSID * myclsid = clsid;
	WCHAR	sKeyName[MAX_PATH];
	const	WCHAR sCLSID[7] = {'C','L','S','I','D','\\','\0'};
	WCHAR	sClassID[60];
	const WCHAR sInProcServer32[16] ={'\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2','\0'};
	const WCHAR sLoadWithoutCOM[15] ={'L','o','a','d','W','i','t','h','o','u','t','C','O','M','\0'};
	WCHAR	sDllPath[MAX_PATH];
	HKEY	hKey = 0;
	DWORD	dwSize;
	IClassFactory * pcf = NULL;

	if(!ppv) return E_POINTER;
	*ppv=NULL;

	/* if the clsid is a string, convert it */
	if (!clsid)
	{
	  if (!aclsid) return REGDB_E_CLASSNOTREG;
	  SHCLSIDFromStringW(aclsid, &iid);
	  myclsid = &iid;
	}

	TRACE("(%p,%s,unk:%p,%s,%p)\n",
		aclsid,shdebugstr_guid(myclsid),pUnkOuter,shdebugstr_guid(refiid),ppv);

        if (SUCCEEDED(DllGetClassObject(myclsid, &IID_IClassFactory,(LPVOID*)&pcf)))
        {
            hres = IClassFactory_CreateInstance(pcf, pUnkOuter, refiid, ppv);
            IClassFactory_Release(pcf);
            goto end;
        }

	/* we look up the dll path in the registry */
        SHStringFromGUIDW(myclsid, sClassID, sizeof(sClassID)/sizeof(WCHAR));
	lstrcpyW(sKeyName, sCLSID);
	lstrcatW(sKeyName, sClassID);
	lstrcatW(sKeyName, sInProcServer32);

	if (RegOpenKeyExW(HKEY_CLASSES_ROOT, sKeyName, 0, KEY_READ, &hKey))
            return E_ACCESSDENIED;

        /* if a special registry key is set, we load a shell extension without help of OLE32 */
        if (!SHQueryValueExW(hKey, sLoadWithoutCOM, 0, 0, 0, 0))
        {
	    /* load an external dll without ole32 */
	    HANDLE hLibrary;
	    typedef HRESULT (CALLBACK *DllGetClassObjectFunc)(REFCLSID clsid, REFIID iid, LPVOID *ppv);
	    DllGetClassObjectFunc DllGetClassObject;

            dwSize = sizeof(sDllPath);
            SHQueryValueExW(hKey, NULL, 0,0, sDllPath, &dwSize );

	    if ((hLibrary = LoadLibraryExW(sDllPath, 0, LOAD_WITH_ALTERED_SEARCH_PATH)) == 0) {
	        ERR("couldn't load InprocServer32 dll %s\n", debugstr_w(sDllPath));
		hres = E_ACCESSDENIED;
	        goto end;
	    } else if (!(DllGetClassObject = (DllGetClassObjectFunc)GetProcAddress(hLibrary, "DllGetClassObject"))) {
	        ERR("couldn't find function DllGetClassObject in %s\n", debugstr_w(sDllPath));
	        FreeLibrary( hLibrary );
		hres = E_ACCESSDENIED;
	        goto end;
            } else if (FAILED(hres = DllGetClassObject(myclsid, &IID_IClassFactory, (LPVOID*)&pcf))) {
		    TRACE("GetClassObject failed 0x%08x\n", hres);
		    goto end;
	    }

            hres = IClassFactory_CreateInstance(pcf, pUnkOuter, refiid, ppv);
            IClassFactory_Release(pcf);
	} else {

	    /* load an external dll in the usual way */
	    hres = CoCreateInstance(myclsid, pUnkOuter, CLSCTX_INPROC_SERVER, refiid, ppv);
	}

end:
        if (hKey) RegCloseKey(hKey);
	if(hres!=S_OK)
	{
	  ERR("failed (0x%08x) to create CLSID:%s IID:%s\n",
              hres, shdebugstr_guid(myclsid), shdebugstr_guid(refiid));
	  ERR("class not found in registry\n");
	}

	TRACE("-- instance: %p\n",*ppv);
	return hres;
}