TypeFactory.cpp
上传用户:bjlvip
上传日期:2010-02-08
资源大小:744k
文件大小:1k
- #define _WIN32_DCOM
- #include <windows.h>
- #include <iostream.h>
- #include <stdio.h>
- CLSID CLSID_TypeFactory = {0xB5866878, 0xBD99, 0x11D0, 0xB0, 0x4B, 0x00, 0xC0, 0x4F, 0xD9, 0x15, 0x50};
- void main()
- {
- HRESULT hr = 0;
- hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
- ITypeLib* pTypeLib = 0;
- GUID LIBID_Component = {0x10000003, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
- hr = LoadRegTypeLib(LIBID_Component, 1, 0, LANG_NEUTRAL, &pTypeLib);
- ITypeInfo* pTypeInfo = 0;
- IID IID_ISum = {0x10000001, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
- hr = pTypeLib->GetTypeInfoOfGuid(IID_ISum, &pTypeInfo);
- printf("hr = %0xn", hr);
- ITypeFactory* pTypeFactory = 0;
- hr = CoGetClassObject(CLSID_TypeFactory, CLSCTX_INPROC_SERVER, 0, IID_ITypeFactory, (void**)&pTypeFactory);
- printf("hr = %0xn", hr);
- IUnknown* pUnknown = 0;
- hr = pTypeFactory->CreateFromTypeInfo(pTypeInfo, IID_IUnknown, &pUnknown);
- printf("hr = %0xn", hr);
- ITypeMarshal* pTypeMarshal = 0;
- hr = pUnknown->QueryInterface(IID_ITypeMarshal, (void**)&pTypeMarshal);
- printf("hr = %0xn", hr);
- IMarshal* pMarshal = 0;
- hr = pTypeMarshal->QueryInterface(IID_IMarshal, (void**)&pMarshal);
- printf("hr = %0xn", hr);
- // pTypeMarshal->
- // pMarshal->
- pMarshal->Release();
- pTypeMarshal->Release();
- pUnknown->Release();
- pTypeFactory->Release();
- CoUninitialize();
- }