예제 #1
0
파일: TypeInfo.cpp 프로젝트: enebo/racob
 JNIEXPORT jobject JNICALL Java_org_racob_com_TypeInfo_getContainingTypeLib
  (JNIEnv *env, jobject obj, jint pointer) {
   ITypeInfo *typeInfo = (ITypeInfo *) pointer;
   ITypeLib* typeLib = NULL;
   unsigned int index = 0;
   HRESULT hr = typeInfo->GetContainingTypeLib(&typeLib, &index);
   if (!SUCCEEDED(hr)) {
      ThrowComFail(env, "GetContainingTypeLib failed", hr);
      return NULL;
   }

   int typeCount = typeLib->GetTypeInfoCount();
   if (typeCount == E_NOTIMPL) {
      ThrowComFail(env, "GetContainingTypeLib failed to get count", hr);
      return NULL;
   }

 TLIBATTR *libAttr = NULL;
 hr = typeLib->GetLibAttr(&libAttr);
 if (!SUCCEEDED(hr)) {
    ThrowComFail(env, "Automation.loadTypeLibEx failed", hr);
    return NULL;
 }

 jstring guid = makeGUIDString(env, libAttr->guid);
 jclass autoClass = env->FindClass("org/racob/com/TypeLib");
 jmethodID autoCons = env->GetMethodID(autoClass, "<init>", "(IILjava/lang/String;IIII)V");
 jobject newAuto = env->NewObject(autoClass, autoCons, (jint) typeLib, index,
         guid, typeCount, libAttr->wLibFlags, libAttr->wMajorVerNum,
         libAttr->wMinorVerNum);

 typeLib->ReleaseTLibAttr(libAttr);

 return newAuto;
 }
예제 #2
0
PyObject *PyITypeLib::GetTypeInfoCount()
{
	ITypeLib *pMyTypeLib = GetI(this);
	if (pMyTypeLib==NULL) return NULL;
	PY_INTERFACE_PRECALL;
	long rc = pMyTypeLib->GetTypeInfoCount();
	PY_INTERFACE_POSTCALL;
	return PyInt_FromLong(rc);
}
예제 #3
0
/* Extract IIDs and CLSIDs from qedit type library */
static void
InitAllQeditTypeLibGUIDs()
{
    ITypeLib* pQeditTypeLib = 0;
    HRESULT result = LoadTypeLib(
        kFilenameQeditTypeLib.BeginReading(), &pQeditTypeLib
    );
    
    if (result == S_OK) {
        PRUint32 countTypeInfo = pQeditTypeLib->GetTypeInfoCount();
        ITypeInfo** typeInfoPtrArray = new ITypeInfo*[countTypeInfo];
        MEMBERID* memberIdArray = new MEMBERID[countTypeInfo];
        
        InitTypeLibGUID(
            pQeditTypeLib, typeInfoPtrArray, memberIdArray,
            kNameISampleGrabber, TKIND_INTERFACE, IID_ISampleGrabber
        );
        InitTypeLibGUID(
            pQeditTypeLib, typeInfoPtrArray, memberIdArray,
            kNameISampleGrabberCB, TKIND_INTERFACE, IID_ISampleGrabberCB
        );
        InitTypeLibGUID(
            pQeditTypeLib, typeInfoPtrArray, memberIdArray,
            kNameClassSampleGrabber, TKIND_COCLASS, CLSID_SampleGrabber
        );
        InitTypeLibGUID(
            pQeditTypeLib, typeInfoPtrArray, memberIdArray,
            kNameClassNullRenderer, TKIND_COCLASS, CLSID_NullRenderer
        );
        
        delete[] memberIdArray;
        delete[] typeInfoPtrArray;
    }
    
    SAFE_RELEASE(pQeditTypeLib);
}
예제 #4
0
CLSID tCOMUtil::FindCLSID(ITypeInfo* interface_typeinfo)
{
  ITypeLib* ptypelib    = NULL;
  ITypeInfo* ptypeinfo  = NULL;
  long count            = 0;
  IID iid               = IID_NULL;
  TYPEATTR* ptypeattr   = NULL;
  TYPEKIND tkind;
  bool found            = false;
  CLSID clsid           = IID_NULL;

  // gets IID
  interface_typeinfo->GetTypeAttr(&ptypeattr);

  iid = ptypeattr->guid;
  interface_typeinfo->ReleaseTypeAttr(ptypeattr);
  ptypeattr = NULL;

  // Gets type library
  interface_typeinfo->GetContainingTypeLib(&ptypelib, NULL);

  // iterates looking for IID inside some coclass
  count = ptypelib->GetTypeInfoCount();

  while(count-- && !found)
  {
    ptypelib->GetTypeInfoType(count, &tkind);

    if(tkind != TKIND_COCLASS)
      continue;

    // look inside
    ptypelib->GetTypeInfo(count, &ptypeinfo);

    // gets counts and clsid
    ptypeinfo->GetTypeAttr(&ptypeattr);
    long ifaces_count   = ptypeattr->cImplTypes;
    clsid = ptypeattr->guid;

    ptypeinfo->ReleaseTypeAttr(ptypeattr);
    ptypeattr = NULL;

    TYPEFLAGS typeflags;
    HREFTYPE RefType;
    ITypeInfo* piface_typeinfo = NULL;

    while(ifaces_count-- && !found)
    {
      ptypeinfo->GetRefTypeOfImplType(ifaces_count, &RefType);
      ptypeinfo->GetRefTypeInfo(RefType, &piface_typeinfo);
      piface_typeinfo->GetTypeAttr(&ptypeattr);

      if(IsEqualIID(ptypeattr->guid, iid))
      {
        found = true;
      }

      piface_typeinfo->ReleaseTypeAttr(ptypeattr);
      ptypeattr = NULL;

      COM_RELEASE(piface_typeinfo);
    }

    COM_RELEASE(ptypeinfo);
  }

  COM_RELEASE(ptypelib);

  return clsid;
}
예제 #5
0
파일: plugins.cpp 프로젝트: Nalatroz/trans3
/*
 * Load a plugin.
 */
IPlugin *loadPlugin(const STRING path)
{
    const STRING file = resolve(path);

    HMODULE mod = LoadLibrary(file.c_str());

    if (!mod)
    {
        messageBox(_T("The file ") + file + _T(" is not a valid dynamically linkable library."));
        return NULL;
    }

    FARPROC pReg = GetProcAddress(mod, _T("DllRegisterServer"));

    if (!pReg)
    {
        FreeLibrary(mod);
        COldPlugin *p = new COldPlugin();
        if (p->load(file))
        {
            p->initialize();
            return p;
        }
        messageBox(_T("The file ") + file + _T(" is not a valid plugin."));
        delete p;
        return NULL;
    }

    FreeLibrary(mod);

    CComPlugin *p = new CComPlugin();
    STRING manifestFile = file + ".x.manifest";

    // Create an "Active Context" to load the DLL into this processes
    // execution address.
    //
    // Normally you would have to register a COM DLL to access it which
    // would require administrative rights, to get around that issue
    // we are using "Registration Free COM".
    ACTCTX actCtx;
    memset((void*)&actCtx, 0, sizeof(ACTCTX));
    actCtx.cbSize = sizeof(ACTCTX);
    actCtx.lpSource = manifestFile.c_str();

    HANDLE hCtx = ::CreateActCtx(&actCtx);

    if (hCtx == INVALID_HANDLE_VALUE)
    {
        messageBox(_T("Failed to load the type library manifest ") + manifestFile + _T("."));
        return NULL;
    }
    else
    {
        ULONG_PTR cookie;

        if (::ActivateActCtx(hCtx, &cookie))
        {
            ITypeLib *pTypeLib = NULL;

            // Because we can't simply cast to 'LPCOLESTR'.
            std::wstring fileWstring = getUnicodeString(file);
            LPCOLESTR fileLibrary = fileWstring.c_str();

            if (FAILED(LoadTypeLib(fileLibrary, &pTypeLib)))
            {
                messageBox(_T("Failed to load the type library of ") + file + _T("."));
                return NULL;
            }

            const int types = pTypeLib->GetTypeInfoCount();

            // Check all the types in the library.
            bool bLoaded = false;
            for (int i = 0; i < types; ++i)
            {
                ITypeInfo *pTypeInfo = NULL;
                pTypeLib->GetTypeInfo(i, &pTypeInfo);

                if (bLoaded = p->load(pTypeInfo))
                {
                    break;
                }
            }

            // Release the type library.
            pTypeLib->Release();

            if (!bLoaded)
            {
                messageBox(_T("A remotable class was not found in ") + file + _T("."));
                delete p;
                return NULL;
            }

            ::DeactivateActCtx(0, cookie);
        }
    }

    p->initialize();

    return p;
}