STDMETHODIMP MailAttachments::get_Item(LONG index, IMailAttachment** pVal) { try { if(pVal == 0) throw Workshare::ArgumentNullException(_T("pVal"), _T("The return argument may not be null")); LONG upper = (LONG)m_Attachments.size(); if((index <= 0) || (index > upper)) throw Workshare::System::IndexOutOfRangeException(_T("The index is out of range [1-%d]"), upper); IUnknownPtr spUnk = m_Attachments.at(index-1); HRESULT hr = spUnk.QueryInterface(__uuidof(IMailAttachment), *pVal); if(FAILED(hr)) { std::tostringstream os; os << _T("Failed to query the IMailAttachment instance at index ") << index << std::ends; throw Workshare::Com::ComException(os.str().c_str(), hr, spUnk); } } catch(const Workshare::Exception& e) { return AtlReportError(__uuidof(this), e.Message, __uuidof(IMailAttachments), e.ErrorCode); } catch(...) { return ProcessUnhandledException(); } return S_OK; }
/*---------------------------------------------------------------------------------------------- Open a main window on a particular object in a particular database on a particular field in a particular object using a particular view. Will fail if the specified tool cannot handle the specified top-level object. Returns a value which can be used to identify the particular window in subsequent calls. @param bstrServerName Name of the MSDE/SQLServer computer. @param bstrDbName Name of the database. @param hvoLangProj Which languate project within the database. @param hvoMainObj The top-level object on which to open the window. @param encUi The user-interface writing system. @param nTool A tool-dependent identifier of which tool to use. @param nParam Another tool-dependent parameter. @param prghvo Pointer to an array of object ids. @param chvo Number of object ids in prghvo. @param prgflid Pointer to an array of flids. @param cflid Number of flids in prgflid. @param ichCur Cursor offset from beginning of field. @param nView The view to display when showing the first object. Use -1 to use the first data entry view. @param ppidNew Process id of the new main window's process. @param phtool Handle to the newly created window. ----------------------------------------------------------------------------------------------*/ STDMETHODIMP AfFwTool::NewMainWndWithSel(BSTR bstrServerName, BSTR bstrDbName, int hvoLangProj, int hvoMainObj, int encUi, int nTool, int nParam, const HVO * prghvo, int chvo, const int * prgflid, int cflid, int ichCur, int nView, int * ppidNew, long * phtool) { BEGIN_COM_METHOD ChkComBstrArg(bstrServerName); ChkComBstrArg(bstrDbName); ChkComArrayArg(prghvo, chvo); ChkComArrayArg(prgflid, cflid); ChkComOutPtr(ppidNew); ChkComOutPtr(phtool); const CLSID * pclsid = AfApp::Papp()->GetAppClsid(); DWORD dwRegister = 0; if (pclsid) { // Check to see if the application is already running. IRunningObjectTablePtr qrot; CheckHr(::GetRunningObjectTable(0, &qrot)); IMonikerPtr qmnk; CheckHr(::CreateClassMoniker(*pclsid, &qmnk)); IUnknownPtr qunk; IFwToolPtr qtool; if (SUCCEEDED(qrot->GetObject(qmnk, &qunk))) { if (SUCCEEDED(qunk->QueryInterface(IID_IFwTool, (void **)&qtool)) && qtool.Ptr() != this) { // The document is already open in another process, so create a new // window in that process. qtool->NewMainWndWithSel(bstrServerName, bstrDbName, hvoLangProj, hvoMainObj, encUi, nTool, nParam, prghvo, chvo, prgflid, cflid, ichCur, nView, ppidNew, phtool); // After we create the new window in the other process, we exit here. // When the IFwTool pointer pointing to 'this' goes out of scope, the // second process (if it was launched from Windows Explorer or the // command line) will shut down automatically. return S_OK; } } else { // Note: ROTFLAGS_ALLOWANYCLIENT causes an error on Win2K (The class is // configured to run as a security ID different from the caller). CheckHr(qrot->Register(ROTFLAGS_REGISTRATIONKEEPSALIVE, this, qmnk, &dwRegister)); } } AfApp::Papp()->NewMainWndWithSel(bstrServerName, bstrDbName, hvoLangProj, hvoMainObj, encUi, nTool, nParam, prghvo, chvo, prgflid, cflid, ichCur, nView, dwRegister); // The handle we return is actually the hwnd of the top-level window. // ENHANCE JohnT: we should probably make htool a long... *phtool = (long)(AfApp::Papp()->GetCurMainWnd()->Hwnd()); if (ppidNew) *ppidNew = (int)::GetCurrentProcessId(); return S_OK; END_COM_METHOD(g_fact, IID_IFwTool); }
void IEToolbar::acquireSiteWindow(IUnknownPtr site) { // Query IOleWindow interface from specified site. IOleWindowPtr siteOLEWindow; const HRESULT getOleWindowResult = site.QueryInterface(IID_IOleWindow, &siteOLEWindow); if (FAILED(getOleWindowResult)) { throw _com_error(getOleWindowResult); } // Retrieve handle of site window. HWND siteWindowHandle = 0; const HRESULT getWindowResult = siteOLEWindow->GetWindow(&siteWindowHandle); if (FAILED(getWindowResult)) { throw _com_error(getWindowResult); } // Attach MFC-wrapper to site window. const BOOL attachResult = siteWindow_.Attach(siteWindowHandle); if (FALSE == attachResult) { throw Error("Failed to attach to site window handle\n"); } // Subclass site window to retrieve its messages. subclassWindow(siteWindow_.GetSafeHwnd()); }
void IEToolbar::acquireSite(IUnknownPtr site) { // Query IInputObjectSite from specified site. IInputObjectSite* sitePtr = 0; const HRESULT getSiteResult = site->QueryInterface(IID_IInputObjectSite, reinterpret_cast<void**>(&sitePtr)); if (FAILED(getSiteResult)) { throw _com_error(getSiteResult); } // Set up new site for toolbar. releaseSite(); site_ = sitePtr; }
static void InitializeClr(void) { ICorRuntimeHost *runtimeHost; if (FAILED(CorBindToRuntimeEx(NULL, NULL, STARTUP_LOADER_OPTIMIZATION_SINGLE_DOMAIN | STARTUP_CONCURRENT_GC, CLSID_CorRuntimeHost, IID_ICorRuntimeHost, (void **)&runtimeHost))) { return; } runtimeHost->Start(); IUnknownPtr punkAppDomain = NULL; runtimeHost->GetDefaultDomain(&punkAppDomain); punkAppDomain->QueryInterface(__uuidof(mscorlib::_AppDomain), (void **)&l_AppDomain); runtimeHost->Release(); }
Reference * Reference::getActiveObject (REFCLSID clsid, const Interface *pInterface) { HRESULT hr; // Retrieve the instance of the object. IUnknownPtr pActive; hr = GetActiveObject(clsid, NULL, &pActive); if (FAILED(hr)) { _com_issue_error(hr); } // If we know it's a custom interface, then query for an interface pointer // to that interface, otherwise query for an IUnknown interface. IUnknown *pUnknown; hr = pActive->QueryInterface( (pInterface == 0) ? IID_IUnknown : pInterface->iid(), reinterpret_cast<void **>(&pUnknown)); if (FAILED(hr)) { _com_issue_error(hr); } if (pInterface == 0) { pInterface = findInterface(pUnknown, clsid); if (pInterface != 0) { // Get a pointer to the derived interface. IUnknown *pNew; hr = pUnknown->QueryInterface( pInterface->iid(), reinterpret_cast<void **>(&pNew)); if (SUCCEEDED(hr)) { pUnknown->Release(); pUnknown = pNew; } } } return new Reference(pUnknown, pInterface, clsid); }
bool CFirewallOpener::DoAction(const EFOCAction eAction, const CICSRuleInfo& riPortRule){ if ( !Init() ) return false; //TODO lets see if we can find a reliable method to find out the internet standard connection set by the user bool bSuccess = true; bool bPartialSucceeded = false; bool bFoundAtLeastOneConn = false; INetSharingEveryConnectionCollectionPtr NSECCP; IEnumVARIANTPtr varEnum; IUnknownPtr pUnk; RETURN_ON_FAIL(m_pINetSM->get_EnumEveryConnection(&NSECCP)); RETURN_ON_FAIL(NSECCP->get__NewEnum(&pUnk)); RETURN_ON_FAIL(pUnk->QueryInterface(__uuidof(IEnumVARIANT), (void**)&varEnum)); _variant_t var; while (S_OK == varEnum->Next(1, &var, NULL)) { INetConnectionPtr NCP; if (V_VT(&var) == VT_UNKNOWN && SUCCEEDED(V_UNKNOWN(&var)->QueryInterface(__uuidof(INetConnection),(void**)&NCP))) { INetConnectionPropsPtr pNCP; if ( !SUCCEEDED(m_pINetSM->get_NetConnectionProps (NCP, &pNCP)) ) continue; DWORD dwCharacteristics = 0; pNCP->get_Characteristics(&dwCharacteristics); if (dwCharacteristics & (NCCF_FIREWALLED)) { NETCON_MEDIATYPE MediaType = NCM_NONE; pNCP->get_MediaType (&MediaType); if ((MediaType != NCM_SHAREDACCESSHOST_LAN) && (MediaType != NCM_SHAREDACCESSHOST_RAS) ){ INetSharingConfigurationPtr pNSC; if ( !SUCCEEDED(m_pINetSM->get_INetSharingConfigurationForINetConnection (NCP, &pNSC)) ) continue; VARIANT_BOOL varbool = VARIANT_FALSE; pNSC->get_InternetFirewallEnabled(&varbool); if (varbool == VARIANT_FALSE) continue; bFoundAtLeastOneConn = true; switch(eAction){ case FOC_ADDRULE:{ bool bResult; // we do not want to overwrite an existing rule if (FindRule(FOC_FINDRULEBYPORT, riPortRule, pNSC, NULL)){ bResult = true; } else bResult = AddRule(riPortRule, pNSC, pNCP); bSuccess = bSuccess && bResult; if (bResult && !bPartialSucceeded) m_liAddedRules.Add(riPortRule); // keep track of added rules bPartialSucceeded = bPartialSucceeded || bResult; break; } case FOC_FWCONNECTIONEXISTS: return true; case FOC_DELETERULEBYNAME: case FOC_DELETERULEEXCACT: bSuccess = bSuccess && FindRule(eAction, riPortRule, pNSC, NULL); break; case FOC_FINDRULEBYNAME: if (FindRule(FOC_FINDRULEBYNAME, riPortRule, pNSC, NULL)) return true; else bSuccess = false; break; case FOC_FINDRULEBYPORT: if (FindRule(FOC_FINDRULEBYPORT, riPortRule, pNSC, NULL)) return true; else bSuccess = false; break; default: ASSERT ( false ); } } } } var.Clear(); } return bSuccess && bFoundAtLeastOneConn; }
bool CFirewallOpener::FindRule(const EFOCAction eAction, const CICSRuleInfo& riPortRule, const INetSharingConfigurationPtr pNSC, INetSharingPortMappingPropsPtr* outNSPMP){ INetSharingPortMappingCollectionPtr pNSPMC; RETURN_ON_FAIL(pNSC->get_EnumPortMappings (ICSSC_DEFAULT, &pNSPMC)); INetSharingPortMappingPtr pNSPM; IEnumVARIANTPtr varEnum; IUnknownPtr pUnk; RETURN_ON_FAIL(pNSPMC->get__NewEnum(&pUnk)); RETURN_ON_FAIL(pUnk->QueryInterface(__uuidof(IEnumVARIANT), (void**)&varEnum)); _variant_t var; while (S_OK == varEnum->Next(1, &var, NULL)) { INetSharingPortMappingPropsPtr pNSPMP; if (V_VT(&var) == VT_DISPATCH && SUCCEEDED(V_DISPATCH(&var)->QueryInterface(__uuidof(INetSharingPortMapping),(void**)&pNSPM)) && SUCCEEDED(pNSPM->get_Properties (&pNSPMP))) { UCHAR ucProt = 0; long uExternal = 0; CComBSTR bstrName; pNSPMP->get_IPProtocol (&ucProt); pNSPMP->get_ExternalPort (&uExternal); pNSPMP->get_Name(&bstrName); switch(eAction){ case FOC_FINDRULEBYPORT: if (riPortRule.m_nPortNumber == uExternal && riPortRule.m_byProtocol == ucProt){ if (outNSPMP != NULL) *outNSPMP = pNSPM; return true; } break; case FOC_FINDRULEBYNAME: if (riPortRule.m_strRuleName == CString(bstrName)){ if (outNSPMP != NULL) *outNSPMP = pNSPM; return true; } break; case FOC_DELETERULEEXCACT: if (riPortRule.m_strRuleName == CString(bstrName) && riPortRule.m_nPortNumber == uExternal && riPortRule.m_byProtocol == ucProt) { RETURN_ON_FAIL(pNSC->RemovePortMapping(pNSPM)); theApp.QueueDebugLogLine(false,_T("Rule removed")); } break; case FOC_DELETERULEBYNAME: if (riPortRule.m_strRuleName == CString(bstrName)){ RETURN_ON_FAIL(pNSC->RemovePortMapping(pNSPM)); theApp.QueueDebugLogLine(false,_T("Rule removed")); } break; default: ASSERT( false ); } } var.Clear(); } switch(eAction){ case FOC_DELETERULEBYNAME: case FOC_DELETERULEEXCACT: return true; case FOC_FINDRULEBYPORT: case FOC_FINDRULEBYNAME: default: return false; } }
DWORD initialize_dotnet_host() { HRESULT hr = S_OK; ICLRMetaHost* clrMetaHost = NULL; ICLRRuntimeInfo* clrRuntimeInfo = NULL; ICorRuntimeHost* clrCorRuntimeHost = NULL; IUnknownPtr clrAppDomain = NULL; _AppDomainPtr clrAppDomainInterface = NULL; _AssemblyPtr clrPowershellAssembly = NULL; _TypePtr clrPowershellType = NULL; SAFEARRAY* clrByteArray = NULL; HMODULE hMsCoree = NULL; do { dprintf("[PSH] Locating CLR instance ..."); hMsCoree = LoadLibraryA("mscoree.dll"); if (hMsCoree == NULL) { hr = (HRESULT)GetLastError(); dprintf("[PSH] Failed to load mscoree, .NET probably isn't installed. 0x%x", hr); break; } pClrCreateInstance clrCreateInstance = (pClrCreateInstance)GetProcAddress(hMsCoree, "CLRCreateInstance"); if (clrCreateInstance != NULL) { dprintf("[PSH] .NET 4 method in use"); if (FAILED(hr = clrCreateInstance(CLSID_CLRMetaHost, IID_PPV_ARGS(&clrMetaHost)))) { dprintf("[PSH] Failed to create instace of the CLR metahost 0x%x", hr); break; } dprintf("[PSH] Getting a reference to the .NET runtime"); if (FAILED(hr = clrMetaHost->GetRuntime(L"v2.0.50727", IID_PPV_ARGS(&clrRuntimeInfo)))) { dprintf("[PSH] Failed to get runtime v2.0.50727 instance 0x%x", hr); if (FAILED(hr = clrMetaHost->GetRuntime(L"v4.0.30319", IID_PPV_ARGS(&clrRuntimeInfo)))) { dprintf("[PSH] Failed to get runtime v4.0.30319 instance 0x%x", hr); break; } } dprintf("[PSH] Determining loadablility"); BOOL loadable = FALSE; if (FAILED(hr = clrRuntimeInfo->IsLoadable(&loadable))) { dprintf("[PSH] Unable to determine of runtime is loadable 0x%x", hr); break; } if (!loadable) { dprintf("[PSH] Chosen runtime isn't loadable, exiting."); break; } dprintf("[PSH] Instantiating the COR runtime host"); hr = clrRuntimeInfo->GetInterface(CLSID_CorRuntimeHost, IID_PPV_ARGS(&clrCorRuntimeHost)); if (FAILED(hr)) { dprintf("[PSH] Unable to get a reference to the COR runtime host 0x%x", hr); break; } } else { dprintf("[PSH] .NET 4 method is missing, attempting to locate .NEt 2 method"); pCorBindToRuntime corBindToRuntime = (pCorBindToRuntime)GetProcAddress(hMsCoree, "CorBindToRuntime"); if (corBindToRuntime == NULL) { dprintf("[PSH] Unable to find .NET clr instance loader"); hr = E_NOTIMPL; break; } if (FAILED(hr = corBindToRuntime(L"v2.0.50727", L"wks", CLSID_CorRuntimeHost, IID_PPV_ARGS(&clrCorRuntimeHost)))) { dprintf("[PSH] Unable to bind to .NET 2 runtime host: 0x%x", hr); break; } } dprintf("[PSH] Starting the COR runtime host"); if (FAILED(hr = clrCorRuntimeHost->Start())) { dprintf("[PSH] Unable to start the COR runtime host 0x%x", hr); break; } dprintf("[PSH] Getting a ref to the app domain"); if (FAILED(hr = clrCorRuntimeHost->GetDefaultDomain(&clrAppDomain))) { dprintf("[PSH] Unable to get the app domain 0x%x", hr); break; } dprintf("[PSH] Getting a ref to the app domain interface"); if (FAILED(hr = clrAppDomain->QueryInterface(IID_PPV_ARGS(&clrAppDomainInterface)))) { dprintf("[PSH] Unable to get the app domain interface 0x%x", hr); break; } dprintf("[PSH] CLR app domain ready to run, now loading the powershell runner"); SAFEARRAYBOUND bounds[1]; bounds[0].cElements = PSHRUNNER_DLL_LEN; bounds[0].lLbound = 0; clrByteArray = SafeArrayCreate(VT_UI1, 1, bounds); if (clrByteArray == NULL) { dprintf("[PSH] Failed to create a usable safe array"); hr = ERROR_OUTOFMEMORY; break; } if (FAILED(hr = SafeArrayLock(clrByteArray))) { dprintf("[PSH] Safe array lock failed 0x%x", hr); break; } memcpy(clrByteArray->pvData, PowerShellRunnerDll, PSHRUNNER_DLL_LEN); SafeArrayUnlock(clrByteArray); if (FAILED(hr = clrAppDomainInterface->Load_3(clrByteArray, &clrPowershellAssembly))) { dprintf("[PSH] Failed to load the powershell runner assembly 0x%x", hr); break; } dprintf("[PSH] Loading the type from memory"); _bstr_t pshClassName("MSF.Powershell.Runner"); if (FAILED(hr = clrPowershellAssembly->GetType_2(pshClassName, &clrPowershellType))) { dprintf("[PSH] Unable to locate the powershell class type 0x%x", hr); break; } dprintf("[PSH] Runtime has been initialized successfully"); } while(0); if (clrByteArray != NULL) { SafeArrayDestroy(clrByteArray); } if (FAILED(hr)) { SAFE_RELEASE(clrPowershellAssembly); SAFE_RELEASE(clrAppDomainInterface); SAFE_RELEASE(clrCorRuntimeHost); SAFE_RELEASE(clrRuntimeInfo); SAFE_RELEASE(clrMetaHost); return (DWORD)hr; } gClrMetaHost = clrMetaHost; gClrRuntimeInfo = clrRuntimeInfo; gClrCorRuntimeHost = clrCorRuntimeHost; gClrAppDomainInterface = clrAppDomainInterface; gClrAppDomain = clrAppDomain; gClrPowershellAssembly = clrPowershellAssembly; gClrPowershellType = clrPowershellType; return ERROR_SUCCESS; }
/*---------------------------------------------------------------------------------------------- Close the current editor, saving changes that were made. hwnd is the editor hwnd. @param fForce True if we want to force the editor closed without making any validity checks or saving any changes. ----------------------------------------------------------------------------------------------*/ void AfDeFeSt::EndEdit(bool fForce) { if (m_qvcdMissing && !fForce) { ComBool fDirty; ISilDataAccessPtr qsdaTemp; CheckHr(m_qvcdMissing->QueryInterface(IID_ISilDataAccess, (void **)&qsdaTemp)); qsdaTemp->IsDirty(&fDirty); if (fDirty) { // The text got edited. So, make a real text and copy the relevant info. // First get the paragraph list HvoVec vhvoParas; int chvoParas; // If we already had a text, we will notify it of new paragraphs. bool fNotifyText = m_hvoText > 0; CheckHr(qsdaTemp->get_VecSize(m_hvoText, kflidStText_Paragraphs, &chvoParas)); int ihvo; // used twice for (ihvo = 0; ihvo < chvoParas; ihvo++) { HVO hvoPara; CheckHr(qsdaTemp->get_VecItem(m_hvoText, kflidStText_Paragraphs, ihvo, &hvoPara)); vhvoParas.Push(hvoPara); } // Actually, we may have had a real text...if so, skip this step if (m_hvoText < 0) { m_qcvd->MakeNewObject(kclidStText, m_hvoObj, m_flid, -2, &m_hvoText); } else { // Check if the record has been edited by someone else since we first loaded // the data. HRESULT hrTemp; if ((hrTemp = m_qcvd->CheckTimeStamp(m_hvoText)) != S_OK) { // If it was changed and the user does not want to overwrite it, perform a // refresh so the displayed field will revert to it's original value. SuperClass::EndEdit(fForce); // REVIEW KenZ (PaulP): There may need to be a refresh call made here. // It's difficult to know, however, since I haven't tracked down when // this method actually gets called. m_fDirty = false; return; } } // Now make real paragraph objects and set their properties. for (ihvo = 0; ihvo < chvoParas; ihvo++) { HVO hvoPara = vhvoParas[ihvo]; ITsStringPtr qtss; ITsTextPropsPtr qttp; IUnknownPtr qunkTtp; CheckHr(qsdaTemp->get_UnknownProp(hvoPara, kflidStStyle_Rules, &qunkTtp)); CheckHr(qunkTtp->QueryInterface(IID_ITsTextProps, (void **) &qttp)); CheckHr(qsdaTemp->get_StringProp(hvoPara, kflidStTxtPara_Contents, &qtss)); CheckHr(m_qcvd->MakeNewObject(kclidStTxtPara, m_hvoText, kflidStText_Paragraphs, ihvo, &hvoPara)); if (qttp) CheckHr(m_qcvd->SetUnknown(hvoPara, kflidStPara_StyleRules, qttp)); CheckHr(m_qcvd->SetString(hvoPara, kflidStTxtPara_Contents, qtss)); } m_qvcdMissing.Clear(); // Update the root object to point at the real text we just made. int frag = kfrText; IVwViewConstructor * pvvc = m_qstvc; CheckHr(m_qrootb->putref_DataAccess(m_qcvd)); CheckHr(m_qrootb->SetRootObjects(&m_hvoText, &pvvc, &frag, GetLpInfo()->GetAfStylesheet(), 1)); m_qadsc->UpdateAllDEWindows(m_hvoObj, m_flid); if (fNotifyText) { CheckHr(m_qcvd->PropChanged(m_qrootb, kpctNotifyAllButMe, m_hvoText, kflidStText_Paragraphs, 0, chvoParas, chvoParas)); } else { CheckHr(m_qcvd->PropChanged(m_qrootb, kpctNotifyAllButMe, m_hvoObj, m_flid, 0, 1, 1)); } } } // Do this after the changes above, otherwise, our hwnd is no longer the child of a main // window, and we can't find the style sheet for the SetRootObjects call. SuperClass::EndEdit(fForce); m_fDirty = false; }
void CExRichEditWindowless::InsertGif(LONG gif) { CComQIPtr<IDynamicOleCom> spDyn; HRESULT hr = spDyn.CoCreateInstance(STR_PROGID); if(SUCCEEDED(hr)) { LPOLEOBJECT lpOleObject = NULL; HRESULT hr = spDyn->QueryInterface(IID_IOleObject, (void**)&lpOleObject); IUnknownPtr lpUnk = lpOleObject; hr = lpUnk->QueryInterface(IID_IOleObject, (LPVOID*)&lpOleObject); if (lpOleObject == NULL) throw(E_OUTOFMEMORY); //hr = lpOleObject->SetClientSite( static_cast<IOleClientSite *>( this ) ); IViewObject2Ptr lpViewObject;// IViewObject for IOleObject above hr = lpOleObject->QueryInterface(IID_IViewObject2, (LPVOID*)&lpViewObject); if (hr != S_OK) { AtlThrow(hr); } IRichEditOle* pRichEditOle = GetIRichEditOle(); ////获取RichEdit的OLEClientSite IOleClientSitePtr lpClientSite; hr = pRichEditOle->GetClientSite(&lpClientSite); if (hr != S_OK) { AtlThrow(hr); } REOBJECT reobject; ZeroMemory(&reobject,sizeof(REOBJECT)); reobject.cbStruct = sizeof(REOBJECT); CLSID clsid; hr = lpOleObject->GetUserClassID(&clsid); if (hr != S_OK) { AtlThrow(hr); } reobject.clsid = clsid; reobject.cp = -1; //reobject.cp = REO_CP_SELECTION; reobject.dvaspect = DVASPECT_CONTENT;//DVASPECT_OPAQUE; reobject.poleobj = lpOleObject; reobject.polesite = lpClientSite; //reobject.pstg = lpStorage; SIZEL sizel; sizel.cx = sizel.cy = 0; // let richedit determine initial size Image* img = (Image*)gif; SIZEL sizeInPix = {img->GetWidth(), img->GetHeight()}; SIZEL sizeInHiMetric; AtlPixelToHiMetric(&sizeInPix, &sizeInHiMetric); reobject.sizel = sizeInHiMetric; reobject.dwFlags = REO_BELOWBASELINE|REO_STATIC;//REO_RESIZABLE CExRichEditData* pdata = new CExRichEditData; pdata->m_dataType = GIF; pdata->m_data = (void*)gif; reobject.dwUser = (DWORD)pdata;//TODO 用户数据 lpOleObject->SetClientSite(lpClientSite); hr = pRichEditOle->InsertObject(&reobject); lpOleObject->SetExtent(DVASPECT_CONTENT, &sizeInHiMetric); OleSetContainedObject(lpOleObject, TRUE); lpOleObject->Release(); spDyn->SetHostWindow((LONG)hwndParent); spDyn->InsertGif(gif); } }
int _tmain(int argc, _TCHAR* argv[]) { HRESULT hr; ICLRMetaHost *pMetaHost = NULL; ICLRRuntimeInfo *pRuntimeInfo = NULL; ICorRuntimeHost *pCorRuntimeHost = NULL; IUnknownPtr spAppDomainThunk = NULL; _AppDomainPtr spDefaultAppDomain = NULL; // The .NET assembly to load. bstr_t bstrAssemblyName("PowerShellRunner"); _AssemblyPtr spAssembly = NULL; // The .NET class to instantiate. bstr_t bstrClassName("PowerShellRunner.PowerShellRunner"); _TypePtr spType = NULL; // Start the runtime hr = CLRCreateInstance(CLSID_CLRMetaHost, IID_PPV_ARGS(&pMetaHost)); if (FAILED(hr)) { wprintf(L"CLRCreateInstance failed w/hr 0x%08lx\n", hr); goto Cleanup; } hr = pMetaHost->GetRuntime(L"v2.0.50727", IID_PPV_ARGS(&pRuntimeInfo)); if (FAILED(hr)) { wprintf(L"ICLRMetaHost::GetRuntime failed w/hr 0x%08lx\n", hr); goto Cleanup; } // Check if the specified runtime can be loaded into the process. BOOL fLoadable; hr = pRuntimeInfo->IsLoadable(&fLoadable); if (FAILED(hr)) { wprintf(L"ICLRRuntimeInfo::IsLoadable failed w/hr 0x%08lx\n", hr); goto Cleanup; } if (!fLoadable) { wprintf(L".NET runtime v2.0.50727 cannot be loaded\n"); goto Cleanup; } // Load the CLR into the current process and return a runtime interface hr = pRuntimeInfo->GetInterface(CLSID_CorRuntimeHost, IID_PPV_ARGS(&pCorRuntimeHost)); if (FAILED(hr)) { wprintf(L"ICLRRuntimeInfo::GetInterface failed w/hr 0x%08lx\n", hr); goto Cleanup; } // Start the CLR. hr = pCorRuntimeHost->Start(); if (FAILED(hr)) { wprintf(L"CLR failed to start w/hr 0x%08lx\n", hr); goto Cleanup; } // Get a pointer to the default AppDomain in the CLR. hr = pCorRuntimeHost->GetDefaultDomain(&spAppDomainThunk); if (FAILED(hr)) { wprintf(L"ICorRuntimeHost::GetDefaultDomain failed w/hr 0x%08lx\n", hr); goto Cleanup; } hr = spAppDomainThunk->QueryInterface(IID_PPV_ARGS(&spDefaultAppDomain)); if (FAILED(hr)) { wprintf(L"Failed to get default AppDomain w/hr 0x%08lx\n", hr); goto Cleanup; } // Load the .NET assembly. // (Option 1) Load it from disk - usefully when debugging the PowerShellRunner app (you'll have to copy the DLL into the same directory as the exe) //hr = spDefaultAppDomain->Load_2(bstrAssemblyName, &spAssembly); // (Option 2) Load the assembly from memory SAFEARRAYBOUND bounds[1]; bounds[0].cElements = PowerShellRunner_dll_len; bounds[0].lLbound = 0; SAFEARRAY* arr = SafeArrayCreate(VT_UI1, 1, bounds); SafeArrayLock(arr); memcpy(arr->pvData, PowerShellRunner_dll, PowerShellRunner_dll_len); SafeArrayUnlock(arr); hr = spDefaultAppDomain->Load_3(arr, &spAssembly); if (FAILED(hr)) { wprintf(L"Failed to load the assembly w/hr 0x%08lx\n", hr); goto Cleanup; } // Get the Type of PowerShellRunner. hr = spAssembly->GetType_2(bstrClassName, &spType); if (FAILED(hr)) { wprintf(L"Failed to get the Type interface w/hr 0x%08lx\n", hr); goto Cleanup; } // Call the static method of the class wchar_t* argument = L"Get-Process\n\ #This is a PowerShell Comment\n\ Write-Host \"`n`n******* The next command is going to throw an exception. This is planned *********`n`n\"\n\ Read-Host\n"; InvokeMethod(spType, L"InvokePS", argument); Cleanup: if (pMetaHost) { pMetaHost->Release(); pMetaHost = NULL; } if (pRuntimeInfo) { pRuntimeInfo->Release(); pRuntimeInfo = NULL; } if (pCorRuntimeHost) { pCorRuntimeHost->Release(); pCorRuntimeHost = NULL; } return 0; }
/*---------------------------------------------------------------------------------------------- The hwnd has been attached. ----------------------------------------------------------------------------------------------*/ void HwMainWnd::PostAttach(void) { StrAppBuf strbT; // Holds temp string // Set the default caption text. strbT.Load(kstidHelloWorld); ::SendMessage(m_hwnd, WM_SETTEXT, 0, (LPARAM)strbT.Chars()); // This creates the main frame window and sets it as the current window. It also // creates the rebar and status bar. SuperClass::PostAttach(); const int rgrid[] = { kridTBarStd, kridHwTBarIns, kridHwTBarTools, kridHwTBarWnd, }; GetMenuMgr()->LoadToolBars(rgrid, SizeOfArray(rgrid)); // Create the menu bar. AfMenuBarPtr qmnbr; qmnbr.Create(); qmnbr->Initialize(m_hwnd, kridAppMenu, kridAppMenu, "Menu Bar"); m_vqtlbr.Push(qmnbr.Ptr()); // Create the toolbars. AfToolBarPtr qtlbr; qtlbr.Create(); qtlbr->Initialize(kridTBarStd, kridTBarStd, "Standard"); m_vqtlbr.Push(qtlbr); qtlbr.Create(); qtlbr->Initialize(kridHwTBarIns, kridHwTBarIns, "Insert"); m_vqtlbr.Push(qtlbr); qtlbr.Create(); qtlbr->Initialize(kridHwTBarTools, kridHwTBarTools, "Tools"); m_vqtlbr.Push(qtlbr); qtlbr.Create(); qtlbr->Initialize(kridHwTBarWnd, kridHwTBarWnd, "Window"); m_vqtlbr.Push(qtlbr); // Load window settings. LoadSettings(NULL, false); g_app.AddCmdHandler(this, 1); m_qstbr->RestoreStatusText(); // Create the client window. const int kwidChild = 1000; WndCreateStruct wcs; wcs.InitChild("STATIC", m_hwnd, kwidChild); m_qwndHost.Create(); m_qwndHost->CreateAndSubclassHwnd(wcs); Assert(memcmp(&CLSID_SaCtrlEvent, &DIID__DSAEvents, isizeof(GUID)) == 0); CComCoClass<SaCtrlEvent>::CreateInstance(&m_qsce); IUnknownPtr qunk; CheckHr(AtlAxCreateControlEx(L"SA.SACtrl.1", m_qwndHost->Hwnd(), NULL, NULL, &qunk, DIID__DSAEvents, (IUnknown *)m_qsce.Ptr())); CheckHr(qunk->QueryInterface(DIID__DSA, (void **)&m_qctrl)); m_qsce->Init(this, m_qctrl); StrUni stu(L"baluchi.wav"); CheckHr(m_qctrl->put_WaveFile(stu.Bstr())); CheckHr(m_qctrl->raw_SetGraphs(GRAPH_MAGNITUDE, GRAPH_MAGNITUDE)); CheckHr(m_qctrl->put_ShowContextMenu(false)); CheckHr(m_qctrl->put_ShowCursorContextMenu(false)); ::ShowWindow(m_qwndHost->Hwnd(), SW_SHOW); g_app.AddCmdHandler(this, 1); }