调用COM新建一个空白文档并加入链接
[cpp]// AddHyperLinkViaCom.cpp : Defines the entry point for the console application.//#include "stdafx.h"HRESULT AutoWrap(int autoType, VARIANT *pvResult, IDispatch *pDisp,LPOLESTR ptName, int cArgs...) {va_list marker;va_start(marker, cArgs);if(!pDisp) {_exit(0);}DISPPARAMS dp = { NULL, NULL, 0, 0 };DISPID dispidNamed = DISPID_PROPERTYPUT;DISPID dispID;HRESULT hr;char buf[200];char szName[200];WideCharToMultiByte(CP_ACP, 0, ptName, -1, szName, 256, NULL, NULL);hr = pDisp->GetIDsOfNames(IID_NULL, &ptName, 1, LOCALE_USER_DEFAULT,&dispID);if(FAILED(hr)) {sprintf(buf, "IDispatch::GetIDsOfNames(\"%s\") failed w/err 0x%08lx",szName, hr);printf("%s\n",buf);//_exit(0);return hr;}VARIANT *pArgs = new VARIANT[cArgs+1];for(int i=0; i<cArgs; i++) {pArgs[i] = va_arg(marker, VARIANT);}dp.cArgs = cArgs;dp.rgvarg = pArgs;if(autoType & DISPATCH_PROPERTYPUT) {dp.cNamedArgs = 1;dp.rgdispidNamedArgs = &dispidNamed;}hr = pDisp->Invoke(dispID, IID_NULL, LOCALE_SYSTEM_DEFAULT, autoType, &dp,pvResult, NULL, NULL);if(FAILED(hr)) {sprintf(buf, "IDispatch::Invoke(\"%s\"=%08lx) failed w/err 0x%08lx",szName, dispID, hr);printf("%s\n",buf);//_exit(0);return hr;}va_end(marker);delete [] pArgs;return hr;}int _tmain(int argc, _TCHAR* argv[]){HRESULT hr;CLSID wdCLSID;IDispatch *wdApp;hr = OleInitialize(NULL);if(SUCCEEDED(hr)){CLSIDFromProgID(L"Word.Application",&wdCLSID);CoCreateInstance(wdCLSID,NULL,hr = CLSCTX_LOCAL_SERVER|CLSCTX_INPROC_SERVER,IID_IDispatch,(void **)&wdApp);if(SUCCEEDED(hr)){VARIANT x;x.vt = VT_I4;x.lVal =1;hr = AutoWrap(DISPATCH_PROPERTYPUT,NULL,wdApp,L"Visible",1,x);if(SUCCEEDED(hr)){IDispatch *wdDocuments;VariantInit(&x);hr = AutoWrap(DISPATCH_PROPERTYGET, &x, wdApp,L"Documents", 0);if(SUCCEEDED(hr)){wdDocuments = x.pdispVal;IDispatch * wdDocument;VariantInit(&x);VARIANT m;m.vt = VT_ERROR;m.lVal = (long)DISP_E_PARAMNOTFOUND;VARIANT F,T;F.vt = VT_BOOL;F.boolVal = false;T.vt = VT_BOOL;T.boolVal = true;//这里用DISPATCH_METHOD不能用DISPATCH_PROPERTYGEThr = AutoWrap(DISPATCH_METHOD,&x,wdDocuments,L"Add",4,T,m,F,m);if(SUCCEEDED(hr)){wdDocument = x.pdispVal;IDispatch * wdHyperLinks;IDispatch * wdRange;VariantInit(&x);hr = AutoWrap(DISPATCH_PROPERTYGET, &x,wdDocument,L"HyperLinks",0);if(SUCCEEDED(hr)){wdHyperLinks = x.pdispVal; 补充:软件开发 , C++ ,
上一个:查找之顺序查找
下一个:Objective-c的FoundObjective-c的Foundation中常用类2——NSString和NSMutableStringation中常用类2——NSString和NSMutableStri
- 更多C/C++疑问解答:
- 关于c++的cout输出的问题。
- 在学校里学过C和C++,不过学的很一般,现在自学C#,会不会很难?
- 全国计算机二级C语言笔试题
- 已知某树有2个2度结点,3个3度结点,4个4度结点,问有几个叶子结点?
- c++数据结构内部排序问题,整数排序
- 2012九月计算机二级C语言全国题库,,急求急求
- 如果assert只有一个字符串作为参数,是什么意思呢?
- C语言中,哪些运算符具有左结合性,哪些具有右结合性,帮忙总结下,谢谢了!
- 为什么用结构体编写的程序输入是,0输不出来啊~~~
- 将IEEE—754的十六进制转化为十进制浮点类型,用C或C++都行,多谢各位大侠啊,非常感谢!
- 为什么这个程序求不出公式?
- 这个链表倒置的算法请大家分析下
- c语言函数库调用
- C语言unsigned int纠错
- C语言快排求解啊