How load class for automation with MFC

0

I want to load class of an application with MFC project and use them for software automation.The project type is MFC application my compiler is visual studio 2012 . I loaded class from typelib wizard. whole of my code is:

my code is :

#include "stdafx.h"
#include "MFCApplication1.h"
#include "CGPNSApplicationDisp.h"
#include "ChildFrm.h"
#include <iostream>
#include <string>

 void CChildFrame::AssertValid() const
    {

CLSID clsid;
LPDISPATCH pWMPDispatch = NULL;
::CLSIDFromProgID(OLESTR("SGNSAutomation.SGNSApplication"), &clsid);
IID iid;
HRESULT hr = CoCreateInstance(clsid, NULL, CLSCTX_ALL, 
  IID_IDispatch, (LPVOID*)&pWMPDispatch);//creating base class of application
  CGPNSApplicationDisp *GPNSApplication1;
 hr=pWMPDispatch->QueryInterface(__uuidof(IGPNSApplicationDisp), 
  (void**)&GPNSApplication1);
 LPDISPATCH  myNet = NULL;
 myNet=GPNSApplication1->addSimulationCase();//error occured here
 ISimulationCaseDisp* mysym= NULL;
 mysym=GPNSApplication1->openCase(myfile.c_str());*/
 CMDIChildWndEx::AssertValid();

}

list of method for CGPNSApplicaionDisp: addSimulationCase() getSimulationCase(file path) importCase(file path) openCase(file path)

an error occurred when the program want to invoke this method in the oledisp2.cpp in the line : SCODE sc = m_lpDispatch->Invoke(dwDispID, IID_NULL, 0, wFlags, &dispparams, pvarResult, &excepInfo, &nArgErr); error is Unhandled exception at 0x0FB3F03A (mfc110ud.dll) in MFCApplication1.exe: 0xC0000005: Access violation reading location 0x00000002. I am not a professional in MFC project and COM interface. Please help me. Thank You.

automation
mfc
com
asked on Stack Overflow Apr 21, 2018 by mahdi Lotfi • edited Apr 24, 2018 by mahdi Lotfi

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0