#include "stdafx.h"
#import "C:\\Program Files (x86)\\Microsoft Office\\Office12\\MSWORD.OLB" no_namespace raw_interfaces_only \
rename("FindText","_FindText") \
rename("Rectangle","_Rectangle") \
rename("ExitWindows","_ExitWindows")
#include <atlbase.h>
#include <atlcom.h>
#include <string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
HRESULT hr;
if (S_FALSE==::CoInitialize(NULL))
{
printf("初始化com失败");
}
_ApplicationPtr app=NULL;
app.CreateInstance(__uuidof(Application));
app->put_Visible(true);
DocumentsPtr docs=NULL;
app->get_Documents(&docs);
_DocumentPtr doc=NULL;
doc.CreateInstance(__uuidof(Document));
CComVariant Template(_T("D:\\JOB\\Projects\\Test\\wordDocTest\\6.docx"));
CComVariant NewTemplate(false),DocumentType,Visible;
docs->Add(&Template,&NewTemplate,&DocumentType,&Visible,&doc);
ShapesPtr shapes=NULL;
doc->get_Shapes(&shapes);
/*CComVariant Start(10),End(20);
doc->Range(&Start,&End,&range1);*/
ShapePtr shape=NULL;
RangePtr p_Range=NULL;
SelectionPtr sel=NULL;
app->get_Selection(&sel);
RangePtr firstRange;
RangePtr secondRange;
ParagraphsPtr pras;
doc->get_Paragraphs(&pras);
ParagraphPtr pra;
pras->Item(1,&pra);
pra->get_Range(&firstRange);
CComVariant Anchor(firstRange);
hr= shapes->AddLine(10,10,100,100,&Anchor,&shape);
//问题就在这里 调用addline后shape仍为空 __vfptr = CXX0030: Error: expression cannot be evaluated 返回值hr = -2146824070;
//hr=shapes->AddTextbox(MsoTextOrientation(1),0,30,25,25,&Anchor,&shape);
}