Call Word.cpp
上传用户:bjlvip
上传日期:2010-02-08
资源大小:744k
文件大小:1k
- #include <windows.h>
- #include <iostream.h>
- void main()
- {
- CoInitialize(NULL);
- CLSID clsid;
- OLECHAR wb[] = L"Word.Application";
- CLSIDFromProgID(wb, &clsid);
- OLECHAR pszCLSID[39];
- StringFromGUID2(clsid, pszCLSID, 39);
-
- char buffer[39];
- wsprintf(buffer, "%S", pszCLSID);
- cout << "CLSID: " << buffer << endl;
- IDispatch* pDispatch;
- CoCreateInstance(clsid, NULL, CLSCTX_SERVER, IID_IDispatch, (void**)&pDispatch);
- DISPID dispid;
- OLECHAR* szMember = L"Visible";
- HRESULT hr = pDispatch->GetIDsOfNames(IID_NULL, &szMember, 1, LOCALE_SYSTEM_DEFAULT, &dispid);
- if(FAILED(hr))
- cout << "GetIDsOfNames failed" << endl;
- cout << "DispID of Visible = " << dispid << endl;
- VARIANTARG test = { VT_BOOL, 0, 0, 0, VARIANT_TRUE };
- DISPID dispidnamed = DISPID_PROPERTYPUT;
- DISPPARAMS param = { &test, &dispidnamed, 1, 1 };
- hr = pDispatch->Invoke(dispid, IID_NULL, LOCALE_SYSTEM_DEFAULT,
- DISPATCH_PROPERTYPUT, ¶m, NULL, NULL, NULL);
- if(FAILED(hr))
- cout << "Invoke failed" << endl;
- pDispatch->Release();
- CoUninitialize();
- }