Jaro Kollár
Jaro Kollár

Reputation: 263

c++ MS Word - OleAutomation

I am creating IDispatch like this:

IDispatch *m_pWApp = NULL;
CoInitialize(NULL);
CLSID clsid;
m_hr = CLSIDFromProgID(L"Word.Application", &clsid);
if(SUCCEEDED(m_hr))
{

    m_hr = CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER, IID_IDispatch, (void **)&m_pWApp);
    if(FAILED(m_hr)) m_pWApp=NULL;
}

I am using this to automate word like in example

But now I need to use method from interface IOleCommandTarget::Exec for hide menu bar for opening word. I know that with this method it is possible.

My question is, how can I get IOleCommandTarget to use it for calling Exec and of course to have possibility to use IDispatch line in example.

Upvotes: 1

Views: 1222

Answers (1)

72DFBF5B A0DF5BE9
72DFBF5B A0DF5BE9

Reputation: 5012

Your code is correct, just add:

LPOLECOMMANDTARGET lpOleCommandTarget = NULL;
lpDispatch->QueryInterface(IID_IOleCommandTarget, (void**)&lpOleCommandTarget);

or

IOleCommandTarget* target;
disp->QueryInterface (IID_IOleCommandTarget, (void **) &target);

Then **lpOleCommandTarget->Exec(...);**

For example:

lpOleCommandTarget->Exec(NULL, OLECMDID_PRINT, 0, NULL,NULL);

Upvotes: 1

Related Questions