Answered by:
My post was by mistake considered as spam. Please verify

Question
-
Original message that I tried to post on "Microsoft Office for Developers" was:
Hi! I'm using Office Automation with C++ in my software and it turned out that DocumentWindow.HWND property cannot be accessed in [at least] Powerpoint 2013 .
GetIDsOfNames returns HRESULT S_OK and dispatch ID 0x000007e4. But when I try to get DocumentWindow property with given dispatch ID, pDisp->Invoke(dispID, ...) returns error 0x80020003 - "Member not found"
How do I access DocumentWindow.HWND property in PowerPoint 2013 ? OR is there any way to programmatically get any PP's window HWND ?
I'll post some code below to demonstrate how I do calls to Powerpoint interfaces. Also, I'd like to note that the code that does the call works fine in any other place in my code (it works out on Open document, Save, Close etc. ).... do { //m_pApp is IDispatch interface for PowerPoint.Application CComPtr<IDispatch> pPresentations; { VARIANT result; VariantInit(&result); hr = InvokeDispatchMethod(DISPATCH_PROPERTYGET, &result, &stErrorInfo, m_pApp, L"Presentations", 0); BreakOnFailure(hr, "Documents"); pPresentations.Attach(result.pdispVal); } if (pPresentations == nullptr) BreakOn0(hr, E_FAIL); { VARIANT result; VariantInit(&result); hr = InvokeDispatchMethod(DISPATCH_METHOD, &result, &stErrorInfo, pPresentations, L"Add", 0); BreakOnFailure(hr, "Documents.Add"); pNewPres.Attach(result.pdispVal); } if (pNewPres == nullptr) BreakOn0(hr, E_FAIL); CComPtr<IDispatch> pWindows; { VARIANT result; VariantInit(&result); hr = InvokeDispatchMethod(DISPATCH_PROPERTYGET, &result, &stErrorInfo, pNewPres, L"Windows", 0); BreakOnFailure(hr, "Windows"); pWindows.Attach(result.pdispVal); } if (pWindows == nullptr) BreakOn0(hr, E_FAIL); LONG nCount = 0; { VARIANT result; VariantInit(&result); hr = InvokeDispatchMethod(DISPATCH_PROPERTYGET, &result, &stErrorInfo, pWindows, L"Count", 0); BreakOnFailure(hr, "Count"); nCount = (LONG)result.intVal; } ASSERT((nCount != 0) && "No window has been added, or we should wait some time for Word to create it"); // without it we will not find its HWND if (nCount == 0) BreakOn0(hr, E_FAIL); CComPtr<IDispatch> pPresentationWindow; //get window //.... { VARIANT vtParam; vtParam.vt = VT_INT; vtParam.intVal = 1; // it starts from 1 VARIANT result; VariantInit(&result); hr = InvokeDispatchMethod(DISPATCH_METHOD, &result, &stErrorInfo, pWindows, L"Item", 1, vtParam); BreakOnFailure(hr, "Windows.Item"); pPresentationWindow.Attach(result.pdispVal); } HWND hwndPresWnd = NULL; if (pPresentationWindow != nullptr) { VARIANT result; VariantInit(&result); //THIS CALL FAILS ("Member not found") hr = InvokeDispatchMethod(DISPATCH_PROPERTYGET, &result, &stErrorInfo, pPresentationWindow, L"Hwnd", 0); //THIS CALL ALSO FAILS ("Member not found") hr = InvokeDispatchMethod(DISPATCH_PROPERTYGET, &result, &stErrorInfo, pPresentationWindow, L"HWND", 0); BreakOnFailure(hr, "HWND"); hwndPresWnd = (HWND)(HANDLE_T)result.intVal; } } while (false); .... ..... HRESULT vOfficeAppWrapperBase::InvokeDispatchMethod(int autoType, VARIANT *pvResult, EXCEPINFO* pExcepInfo, IDispatch *pDisp, LPOLESTR ptName, int cArgs...) { if (!pDisp) { return E_INVALIDARG; } // Variables used DISPPARAMS dp = { NULL, NULL, 0, 0 }; DISPID dispidNamed = DISPID_PROPERTYPUT; DISPID dispID; HRESULT hr; // Get DISPID for name passed hr = pDisp->GetIDsOfNames(IID_NULL, &ptName, 1, LOCALE_USER_DEFAULT, &dispID); if (FAILED(hr)) { return hr; } // Begin variable-argument list va_list marker; va_start(marker, cArgs); // Allocate memory for arguments VARIANT *pArgs = new VARIANT[cArgs + 1]; // Extract arguments... for (int i = 0; i < cArgs; i++) { pArgs[i] = va_arg(marker, VARIANT); } // Build DISPPARAMS dp.cArgs = cArgs; dp.rgvarg = pArgs; // Handle special-case for property-puts if (autoType & DISPATCH_PROPERTYPUT) { dp.cNamedArgs = 1; dp.rgdispidNamedArgs = &dispidNamed; } // Make the call EXCEPINFO stInfo; if (pExcepInfo == nullptr) pExcepInfo = &stInfo; hr = pDisp->Invoke(dispID, IID_NULL, LOCALE_SYSTEM_DEFAULT, autoType, &dp, pvResult, pExcepInfo, NULL); // End variable-argument section va_end(marker); delete[] pArgs; return hr; }
Answers
-
Lately this happens when really you just need to have your account verified. You need to post a request in the current verification thread here:
The current verification thread periodically changes, but is always a sticky thread at the top of this forum:
https://social.technet.microsoft.com/Forums/en-US/home?forum=reportabug
I checked your post and it is not marked as spam. The message you got is misleading. But you still need to request verification in the thread I linked.
Richard Mueller - MVP Enterprise Mobility (Identity and Access)
- Proposed as answer by Vincenzo Di RussoMVP Tuesday, May 22, 2018 10:52 AM
- Marked as answer by Vincenzo Di RussoMVP Saturday, May 26, 2018 12:31 PM