Office 365 - Unable to interact with OLE servers

Steven Wendling 21 Reputation points
2022-11-09T16:04:21.69+00:00

Hello, I'm maintaining a application that uses OLE to embed Office viewers to display the various Office documents(.docx, .pptx, etc) in our MFC application. As of Office 2206 we are unable to interact with the OLE servers as we did before. I'm still trying to identify where our embedding process fails, but is anyone aware of anything that came with the Office 2206 update that would have impacted OLE functionality?

A similar bug cropped up in the past, and @Castorix31 supplied this useful app that seems to have a similar issue:

#include <windows.h>  
 #include <tchar.h>  
 #include <exdisp.h> // IWebBrowser2  
      
 HINSTANCE hInst;  
 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);  
 int nWidth = 800, nHeight = 600;  
 #define IDC_HTML 10  
      
 HINSTANCE hATLDLL;  
 typedef BOOL(__stdcall *PAAWI)(void);  
 PAAWI pAtlAxWinInit;  
 typedef HRESULT(__stdcall *PAAGC) (HWND hWnd, IUnknown** pUnknown);  
 PAAGC pAtlAxGetControl;  
      
 int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow)  
 {  
     hInst = hInstance;  
     hATLDLL = LoadLibrary(_T("atl.dll"));  
     pAtlAxWinInit = (PAAWI)GetProcAddress(hATLDLL, "AtlAxWinInit");  
     if (pAtlAxWinInit)  
         pAtlAxWinInit();  
     pAtlAxGetControl = (PAAGC)GetProcAddress(hATLDLL, "AtlAxGetControl");  
     WNDCLASSEX wcex =  
     {  
         sizeof(WNDCLASSEX), CS_HREDRAW | CS_VREDRAW, WndProc, 0, 0, hInst, LoadIcon(NULL, IDI_APPLICATION),  
         LoadCursor(NULL, IDC_ARROW), (HBRUSH)(COLOR_WINDOW + 1), NULL, TEXT("WindowClass"), NULL,  
     };  
     if (!RegisterClassEx(&wcex))  
         return MessageBox(NULL, TEXT("Cannot register class !"), TEXT("Error"), MB_ICONERROR | MB_OK);  
     int nX = (GetSystemMetrics(SM_CXSCREEN) - nWidth) / 2, nY = (GetSystemMetrics(SM_CYSCREEN) - nHeight) / 2;  
     HWND hWnd = CreateWindowEx(0, wcex.lpszClassName, TEXT("Test"), WS_OVERLAPPEDWINDOW, nX, nY, nWidth, nHeight, NULL, NULL, hInst, NULL);  
     if (!hWnd)  
         return MessageBox(NULL, TEXT("Cannot create window !"), TEXT("Error"), MB_ICONERROR | MB_OK);  
     ShowWindow(hWnd, SW_SHOWNORMAL);  
     UpdateWindow(hWnd);  
     MSG msg;  
     while (GetMessage(&msg, NULL, 0, 0))  
     {  
         TranslateMessage(&msg);  
         DispatchMessage(&msg);  
     }  
     return (int)msg.wParam;  
 }  
      
 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)  
 {  
     static HWND hHTMLWindow = NULL;  
     switch (message)  
     {  
     case WM_CREATE:  
     {  
         // .doc  
         HKEY hKey;  
         DWORD dwResult = 0;  
         LONG nResult = RegCreateKeyEx(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Classes\\Word.Document.12"), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwResult);  
         if (nResult == ERROR_SUCCESS)  
         {  
             DWORD nValue = 0x80000024;  
             RegSetValueEx(hKey, TEXT("BrowserFlags"), 0, REG_DWORD, (LPBYTE)&nValue, sizeof(nValue));      
             nValue = 0x10000;  
             RegSetValueEx(hKey, TEXT("EditFlags"), 0, REG_DWORD, (LPBYTE)&nValue, sizeof(nValue));  
         }  
         else  
         {  
             WCHAR wsMessage[255];  
             wsprintf(wsMessage, TEXT("Unable to open registry key : Error = %d"), nResult);  
             MessageBox(hWnd, wsMessage, TEXT("Error"), MB_OK | MB_ICONERROR | MB_SETFOREGROUND);  
             return 0;  
         }  
         if (hKey)  
             RegCloseKey(hKey);  
      
         // .dotx  
         dwResult = 0;  
         nResult = RegCreateKeyEx(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Classes\\Word.Template.12"), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwResult);  
         if (nResult == ERROR_SUCCESS)  
         {  
             DWORD nValue = 0x80000024;  
             RegSetValueEx(hKey, TEXT("BrowserFlags"), 0, REG_DWORD, (LPBYTE)&nValue, sizeof(nValue));  
             nValue = 0x10000;  
             RegSetValueEx(hKey, TEXT("EditFlags"), 0, REG_DWORD, (LPBYTE)&nValue, sizeof(nValue));  
         }  
         else  
         {  
             WCHAR wsMessage[255];  
             wsprintf(wsMessage, TEXT("Unable to open registry key : Error = %d"), nResult);  
             MessageBox(hWnd, wsMessage, TEXT("Error"), MB_OK | MB_ICONERROR | MB_SETFOREGROUND);  
             return 0;  
         }  
         if (hKey)  
             RegCloseKey(hKey);  
      
         hHTMLWindow = CreateWindow(_T("AtlAxWin"), _T("about:blank"), WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | WS_HSCROLL, 10, 10, 600, 400, hWnd, (HMENU)IDC_HTML, hInst, 0);  
         if (hHTMLWindow)  
         {  
             HRESULT hr = E_FAIL;  
             IUnknown* pUnknown = NULL;  
             IWebBrowser2 *pWebBrowser = NULL;  
             hr = pAtlAxGetControl(hHTMLWindow, &pUnknown);  
             if (SUCCEEDED(hr))  
             {  
                 hr = pUnknown->QueryInterface(__uuidof(IWebBrowser2), (void**)&pWebBrowser);  
                 if (SUCCEEDED(hr))  
                 {  
                     BSTR bstrURL;  
                     VARIANT_BOOL vb;  
                     //bstrURL = SysAllocString(_T("www.google.com"));  
                     //bstrURL = SysAllocString(L"e:\\youtube_test.htm");  
                     //bstrURL = SysAllocString(L"e:\\test.doc");  
                     bstrURL = SysAllocString(L"e:\\test1.dotx");  
                     VARIANT var;  
                     var.vt = VT_EMPTY;  
                     pWebBrowser->Navigate(bstrURL, &var, &var, &var, &var);  
                     SysFreeString(bstrURL);  
                     pWebBrowser->Release();  
                 }  
             }  
         }  
         return 0;  
     }  
     break;  
     case WM_SIZE:  
         MoveWindow(hHTMLWindow, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);  
         break;  
     case WM_DESTROY:  
     {  
         PostQuitMessage(0);  
         return 0;  
     }  
     break;  
     default:  
         return DefWindowProc(hWnd, message, wParam, lParam);  
     }  
     return 0;  
 }  

This can be run with VS 2019 in a new Windows Desktop Application, and with the bstrURL changed to a Word template(.dotx) or document(.docx) on your machine.

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,412 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,519 questions
{count} votes