Problem with AddOleObject!

A

Ahmad Jalil Qarshi

hi!

I want to insert an object into MS Word using function AddOleObject. i did it using visual basic 6 using the following function.

InlineShape.AddOleObject(insRange,"{7A4960FC-645E-4971-B2C4-E4C3DB896D10}","",False,False);
where insRange is of Range type. it worked fine. but the problem is that i want to do it in Visual C++6. Now the function prototype in VC++6 is hereunder

MSWord::InlineShapes::AddOLEObject ( VARIANT * ClassType, VARIANT * FileName, VARIANT * LinkToFile, VARIANT * DisplayAsIcon, VARIANT * IconFileName, VARIANT * IconIndex, VARIANT * IconLabel, VARIANT * Range )

i am a bit confused about how to use this function in VC. I tried it using following code.

VARIANT varClassType; VariantInit(&varClassType);
VARIANT varLinkToFile; VariantInit(&varLinkToFile);
VARIANT varDisplayAsIcon; VariantInit(&varDisplayAsIcon);
VARIANT varEmpty; VariantInit(&varEmpty);
VARIANT range; VariantInit(&range);
varClassType.vt = VT_BSTR;
varLinkToFile.vt = VT_BOOL;
varDisplayAsIcon.vt = VT_BOOL;
range.vt = VT_I4;
_bstr_t clsID = "{7A4960FC-645E-4971-B2C4-E4C3DB896D10}";
varClassType.bstrVal = clsID.copy();
varLinkToFile.boolVal = FALSE;
varDisplayAsIcon.boolVal = FALSE;
varEmpty.vt = VT_EMPTY;
range.lVal = 0;
MSWord::InlineShapePtr SigObj = m_pWordApp->ActiveDocument->InlineShapes->AddOLEObject(&varClassType, &varEmpty, &varLinkToFile,&varDisplayAsIcon,
&varEmpty, &varEmpty,&varEmpty,&range);

but unfortunately when last line of above code executes my program crashes. i think that the problem is with my first and last parameter in the AddOleObject function. I dont know how to resolve it.

Please help me.

Sorry for posting this Question in many groups. actually i don't know where to send query related to VC++ & Word Both.


Thanks

Ahmad Jalil Qarshi
 
A

Ahmad Jalil Qarshi

Isn't anybody there to help me!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
hi!

I want to insert an object into MS Word using function AddOleObject. i did it using visual basic 6 using the following function.

InlineShape.AddOleObject(insRange,"{7A4960FC-645E-4971-B2C4-E4C3DB896D10}","",False,False);
where insRange is of Range type. it worked fine. but the problem is that i want to do it in Visual C++6. Now the function prototype in VC++6 is hereunder

MSWord::InlineShapes::AddOLEObject ( VARIANT * ClassType, VARIANT * FileName, VARIANT * LinkToFile, VARIANT * DisplayAsIcon, VARIANT * IconFileName, VARIANT * IconIndex, VARIANT * IconLabel, VARIANT * Range )

i am a bit confused about how to use this function in VC. I tried it using following code.

VARIANT varClassType; VariantInit(&varClassType);
VARIANT varLinkToFile; VariantInit(&varLinkToFile);
VARIANT varDisplayAsIcon; VariantInit(&varDisplayAsIcon);
VARIANT varEmpty; VariantInit(&varEmpty);
VARIANT range; VariantInit(&range);
varClassType.vt = VT_BSTR;
varLinkToFile.vt = VT_BOOL;
varDisplayAsIcon.vt = VT_BOOL;
range.vt = VT_I4;
_bstr_t clsID = "{7A4960FC-645E-4971-B2C4-E4C3DB896D10}";
varClassType.bstrVal = clsID.copy();
varLinkToFile.boolVal = FALSE;
varDisplayAsIcon.boolVal = FALSE;
varEmpty.vt = VT_EMPTY;
range.lVal = 0;
MSWord::InlineShapePtr SigObj = m_pWordApp->ActiveDocument->InlineShapes->AddOLEObject(&varClassType, &varEmpty, &varLinkToFile,&varDisplayAsIcon,
&varEmpty, &varEmpty,&varEmpty,&range);

but unfortunately when last line of above code executes my program crashes. i think that the problem is with my first and last parameter in the AddOleObject function. I dont know how to resolve it.

Please help me.

Sorry for posting this Question in many groups. actually i don't know where to send query related to VC++ & Word Both.


Thanks

Ahmad Jalil Qarshi
 
A

Ahmad Jalil Qarshi

i have solved the problem myself using CComVariant in place of VARIANT.
i replaced the code in my first post with following 2 lines and it worked
fine.

CComVariant varClsType("Ascertia.AscertiaObj.1");
MSWord::InlineShapePtr SigObj =
m_pWordApp->Selection->InlineShapes->AddOLEObject(&varClsType);

may be it will help someone else.


Ahmad Jalil Qarshi





Isn't anybody there to help me!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
hi!

I want to insert an object into MS Word using function AddOleObject. i did
it using visual basic 6 using the following function.

InlineShape.AddOleObject(insRange,"{7A4960FC-645E-4971-B2C4-E4C3DB896D10}","
",False,False);
where insRange is of Range type. it worked fine. but the problem is that i
want to do it in Visual C++6. Now the function prototype in VC++6 is
hereunder

MSWord::InlineShapes::AddOLEObject ( VARIANT * ClassType, VARIANT *
FileName, VARIANT * LinkToFile, VARIANT * DisplayAsIcon, VARIANT *
IconFileName, VARIANT * IconIndex, VARIANT * IconLabel, VARIANT * Range )

i am a bit confused about how to use this function in VC. I tried it using
following code.

VARIANT varClassType; VariantInit(&varClassType);
VARIANT varLinkToFile; VariantInit(&varLinkToFile);
VARIANT varDisplayAsIcon; VariantInit(&varDisplayAsIcon);
VARIANT varEmpty; VariantInit(&varEmpty);
VARIANT range; VariantInit(&range);
varClassType.vt = VT_BSTR;
varLinkToFile.vt = VT_BOOL;
varDisplayAsIcon.vt = VT_BOOL;
range.vt = VT_I4;
_bstr_t clsID = "{7A4960FC-645E-4971-B2C4-E4C3DB896D10}";
varClassType.bstrVal = clsID.copy();
varLinkToFile.boolVal = FALSE;
varDisplayAsIcon.boolVal = FALSE;
varEmpty.vt = VT_EMPTY;
range.lVal = 0;
MSWord::InlineShapePtr SigObj =
m_pWordApp->ActiveDocument->InlineShapes->AddOLEObject(&varClassType,
&varEmpty, &varLinkToFile,&varDisplayAsIcon,

&varEmpty, &varEmpty,&varEmpty,&range);

but unfortunately when last line of above code executes my program crashes.
i think that the problem is with my first and last parameter in the
AddOleObject function. I dont know how to resolve it.

Please help me.

Sorry for posting this Question in many groups. actually i don't know where
to send query related to VC++ & Word Both.


Thanks

Ahmad Jalil Qarshi
 
Top