none
Calling get_FormsDesign - a method that is generated from the word 2016 type library - causes application to crash. RRS feed

  • Question

  • I generated a _Document class from the "Microsoft Word 16.0 Object Library<8.7>

    The resulting CDocument0.h header file contained the following method:

    BOOL get_FormsDesign()
    {
    	BOOL result;
    	InvokeHelper(0x64, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
    	return result;
    }


    When I attempted to call this method, my application crashed.  Previous versions of my application called this method (or I should say a very method generated from a previous type version of the type library which had the exact same code in it - but was named slightly differently) without any problem.

    Can anyone tell me why this is suddenly causing my application to crash?

    Thank You


    Below is a snipped of the code used to call this method:

    #include "stdafx.h"
    #include "WrapWordTst.h"
    #include "CApplication.h"
    #include "CDocument0.h"
    #include "CDocuments.h"
    
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #endif
    
    BOOL OpenDocument(CApplication *app, CDocument0 **d, TCHAR *myTemplate);
    
    CWinApp theApp;
    HWND WordHwnd;
    
    using namespace std;
    
    int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
    {
    	int nRetCode = 0;
    
    	HMODULE hModule = ::GetModuleHandle(NULL);
    
    	if (hModule != NULL)
    	{
    		if (!AfxWinInit(hModule, NULL, ::GetCommandLine(), 0))
    		{
    			_tprintf(_T("Fatal Error: MFC initialization failed\n"));
    			nRetCode = 1;
    		}
    		else
    		{
    			CApplication WordApplication;
    
    			COleException exception;
    			try {
    				OleInitialize(NULL);
    				COleException exception;
    				if (!WordApplication.CreateDispatch(TEXT("Word.Application"), &exception))
    					return FALSE;
    
    				WordHwnd = ::FindWindow(TEXT("OpusApp"), WordApplication.get_Name());
    				WordApplication.put_Visible(FALSE);
    				WordApplication.put_ScreenUpdating(FALSE);
    			}
    			catch (COleException *e) {
    				return FALSE;
    			}
    			catch (COleDispatchException *e) {
    				return FALSE;
    			}
    			catch (CException *e) {
    				return FALSE;
    			}
    
    			CDocument0 *doc;
    			if (!OpenDocument(&WordApplication, &doc, TEXT(""))){
    				// We should normally have delete and cleanup code here - but since this is a simple example we arent including it.
    				return FALSE;
    			}
    
    			WordApplication.put_Visible(TRUE);
    			WordApplication.put_ScreenUpdating(TRUE);
    			CDocument0 dc = (CDocument0) WordApplication.get_ActiveDocument();
    			// The code throws an exception in the call to dc.get_FormsDesign(). 
    			if (dc != NULL && !dc.get_FormsDesign())
    				dc.ToggleFormsDesign();
    			// We should normally have delete and cleanup code here - but since this is a simple example we arent including it.
    
    
    		}
    	}
    	else
    	{
    		_tprintf(_T("Fatal Error: GetModuleHandle failed\n"));
    		nRetCode = 1;
    	}
    
    	return nRetCode;
    }
    
    BOOL OpenDocument(CApplication *app, CDocument0 **d, TCHAR *myTemplate)
    {
    	COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
    	LPDISPATCH result;
    	long once = 0;
    
    	try {
    
    		CDocuments docs(app->get_Documents());
    		if (docs.get_Count() > 0) {
    			(*d)->Close(
    				COleVariant((long)0, VT_I4),	//SaveChanges=wdDoNotSaveChanges
    				covOptional,			//OriginalFormat
    				covOptional);			//RouteDocuemnt
    			delete *d;
    			once = 1;
    		}
    		result = docs.Add(
    			COleVariant(myTemplate, VT_BSTR),	// Template
    			covOptional, 				// New Template
    			covOptional, 				// Document Type
    			covOptional 				//Visible
    			);
    		*d = new CDocument0(result);
    	}
    	catch (COleException *e) {
    		return FALSE;
    	}
    	catch (COleDispatchException *e) {
    		return FALSE;
    	}
    	catch (CException *e) {
    		return FALSE;
    	}
    	return TRUE;
    }
    

    Thursday, February 4, 2016 1:53 PM

All replies