Click here to Skip to main content
15,070,511 members
Home / Discussions / COM
   

COM

 
AnswerRe: Unable to register 64 bit COM Server Pin
Shameel17-Aug-11 2:32
professionalShameel17-Aug-11 2:32 
AnswerRe: Unable to register 64 bit COM Server Pin
«_Superman_»19-Aug-11 4:18
professional«_Superman_»19-Aug-11 4:18 
QuestionRegarding SheetCalculate event in Excel API Pin
gtag20-Jun-11 10:02
Membergtag20-Jun-11 10:02 
AnswerRe: Regarding SheetCalculate event in Excel API Pin
«_Superman_»13-Jul-11 7:04
professional«_Superman_»13-Jul-11 7:04 
AnswerI need help...(context menu shell extension) [modified] Pin
T800G5-Jun-11 4:53
MemberT800G5-Jun-11 4:53 
Questionhow do i find all "src" attributes from frame object of html document? Pin
yogish29313-May-11 3:20
Memberyogish29313-May-11 3:20 
AnswerRe: how do i find all "src" attributes from frame object of html document? Pin
«_Superman_»21-Jun-11 19:43
professional«_Superman_»21-Jun-11 19:43 
QuestionHow to create an OLE control in EXCEL sheet? Pin
whiteclouds27-Apr-11 23:46
Memberwhiteclouds27-Apr-11 23:46 
Hi, all!

I had met a problem when I developing an addin for Excel. I want to create a new OLE control which developed by myself into Excel sheet. But an error occurred when I add it.

I had try to do this by two ways. One is to call the method "Add" of the class "OLEObjects". Another is to call the method "AddOLEObject" of the class "Shapes". Both are all failure.

When I call OLEObject.Add, an exception was throwed which said a com_error occured in Excel. The code I used is as below:
CComPtr<MSEXCEL::_Workbook> spBook;
HRESULT hr = m_spAppExcel->get_ActiveWorkbook(&spBook);
if(spBook == NULL)
{
    return;
}
CComPtr<MSEXCEL::Sheets> spSheets;
spBook->get_Sheets(&spSheets);
CComPtr<MSEXCEL::OLEObjects> spObjs;
CComVariant vtIndex(1);
spSheets->get_Item(vtIndex,(IDispatch**)&spObjs);
VARIANT vtResult;
VariantInit(&vtResult);
CComVariant ClassType(_MYPROGID);
CComVariant vtFalse(VARIANT_FALSE);
CComVariant left,top;
int x,y;
GetInsertPosX(x,y);
left=x; top = y;
CComVariant vEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR);
CComPtr<MSEXCEL::_OLEObject> pObj;
try
{
    pObj = spObjs->Add(ClassType,vEmpty,vtFalse,vtFalse,vEmpty,vEmpty,vEmpty,left,top,g_iCtrlInitWidth,g_iCtrlInitHeight);
    if(pObj == 0)
    {
        //Failure
        return;
    }
}
catch(...)
{
    DWORD dwError = GetLastError();
    TCHAR info[10];
    wnsprintf(info,10,L"%x",dwError);
    MessageBox(NULL,info,L"Error",MB_OK);
    return;
}

When I call Shapes.AddOLEObject, the calling is success. But the value it returned can't be converted to the pointer I need. The code is as below:
CComPtr<MSEXCEL::_Workbook> spBook;
HRESULT hr = m_spAppExcel->get_ActiveWorkbook(&spBook);
if(spBook == NULL)
{
    return;
}
CComPtr<MSEXCEL::_Worksheet> spSheet;
spBook->get_ActiveSheet((IDispatch**)&spSheet);
CComPtr<MSEXCEL::Shapes> spShapes;
spSheet->get_Shapes(&spShapes);
ATLASSERT(spShapes);
VARIANT vtResult;
VariantInit(&vtResult);
CComVariant ClassType(_MYPROGID);
CComVariant vtFalse(VARIANT_FALSE);
CComVariant left,top;
int x,y;
GetInsertPosX(x,y);
left=x; top = y;
CComVariant vEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR);
CComPtr<MSEXCEL::Shape> spCtrl;
spCtrl = spShapes->AddOLEObject(ClassType,vEmpty,vEmpty,vtFalse,vEmpty,0,vEmpty,left,top,g_iCtrlInitWidth,g_iCtrlInitHeight);
if(spCtrl == 0)
{
    //Failure
    return;
}
CComPtr<MSEXCEL::OLEFormat>spOleFormat;
spOleFormat = spCtrl->get_OLEFormat();
IDispatch *pObj;
pObj = spOleFormat->get_Object();
CComQIPtr<ICASign> cpCASign(pObj);//Here an error occur. The value of pObj is valid. But the value of cpCASign is zero!
if(cpCASign == 0)
{
    return;
}

When I use the second way, I had found the constructor of CCASign had been executed. But when constructor is return, the value of cpCASign is still zero. I think maybe ICASign isn't matched with CCASign. But this object can be inserted into Word correctly. When adding this object into word, the same procedure is done. The value after converted is correct. So I don't know the reason of this error. I hope someone could be kind to help me. Thank you!
There is some white cloud floating on the blue sky. That's the landscape I like.

AnswerRe: How to create an OLE control in EXCEL sheet? Pin
barneyman28-Apr-11 18:52
Memberbarneyman28-Apr-11 18:52 
GeneralRe: How to create an OLE control in EXCEL sheet? Pin
whiteclouds28-Apr-11 21:07
Memberwhiteclouds28-Apr-11 21:07 
GeneralRe: How to create an OLE control in EXCEL sheet? Pin
barneyman29-Apr-11 13:55
Memberbarneyman29-Apr-11 13:55 
GeneralRe: How to create an OLE control in EXCEL sheet? Pin
whiteclouds1-May-11 19:21
Memberwhiteclouds1-May-11 19:21 
GeneralRe: How to create an OLE control in EXCEL sheet? Pin
barneyman1-May-11 19:30
Memberbarneyman1-May-11 19:30 
GeneralRe: How to create an OLE control in EXCEL sheet? Pin
whiteclouds2-May-11 15:48
Memberwhiteclouds2-May-11 15:48 
GeneralRe: How to create an OLE control in EXCEL sheet? Pin
barneyman2-May-11 17:11
Memberbarneyman2-May-11 17:11 
GeneralRe: How to create an OLE control in EXCEL sheet? Pin
whiteclouds3-May-11 0:38
Memberwhiteclouds3-May-11 0:38 
GeneralRe: How to create an OLE control in EXCEL sheet? [modified] Pin
barneyman3-May-11 13:57
Memberbarneyman3-May-11 13:57 
GeneralRe: How to create an OLE control in EXCEL sheet? Pin
whiteclouds3-May-11 15:29
Memberwhiteclouds3-May-11 15:29 
GeneralRe: How to create an OLE control in EXCEL sheet? Pin
whiteclouds3-May-11 21:16
Memberwhiteclouds3-May-11 21:16 
GeneralRe: How to create an OLE control in EXCEL sheet? Pin
barneyman3-May-11 22:15
Memberbarneyman3-May-11 22:15 
GeneralRe: How to create an OLE control in EXCEL sheet? Pin
whiteclouds3-May-11 23:32
Memberwhiteclouds3-May-11 23:32 
GeneralRe: How to create an OLE control in EXCEL sheet? Pin
barneyman4-May-11 18:15
Memberbarneyman4-May-11 18:15 
GeneralRe: How to create an OLE control in EXCEL sheet? Pin
whiteclouds4-May-11 22:16
Memberwhiteclouds4-May-11 22:16 
QuestionIAccessible, IAccessible2 Interface for Microsoft Active Accessibility Pin
kamaljagesia7-Apr-11 4:09
Memberkamaljagesia7-Apr-11 4:09 
AnswerRe: IAccessible, IAccessible2 Interface for Microsoft Active Accessibility Pin
xrg_soft@163.com1-Sep-11 4:43
Memberxrg_soft@163.com1-Sep-11 4:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.