LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Problem with Excel's COM interface in XLL

Hi,
I am developing an Excel add-in using XLL (Excel C API). In XLL along
with Excel C API I am using Excel's COM interfaces also. Now I am
stuck in one issue with the COM interfaces. I want to add a menu bar
to the Excel using COM interfaces, I tried the following code but
could not able to add the Menu Bar to the Excel.

Void AddMenuBar()
{

//excelApp is the global variable and is the object of "_Application"
//class. Assume that at this point this variable has been initialized
//with valid value.
LPDISPATCH pCommandBars = excelApp.GetCommandBars();

//After successful addition of menu bar this will have the IDispatch *
//for "MenuBar" class.
VARIANT vtMenuBar;
VariantInit(&vtMenuBar);

//Argument number 1, name of the menubar.
VARIANT vtParam1;
VariantInit(&vtParam1);
vtParam1.vt = VT_BSTR;
vtParam1.bstrVal = _bstr_t("MyComMenu").copy();

//Argument number 2, position of the menubar.
VARIANT vtParam2;
VariantInit(&vtParam2);
vtParam2.vt = VT_INT;
vtParam2.intVal = 2; //add to the right of the doc.

//Argument number 3, Boolean value which specifies whether the command
bar object // is menu bar or not
VARIANT vtParam3;
VariantInit(&vtParam3);
vtParam3.vt = VT_BOOL;
vtParam3.boolVal = VARIANT_TRUE;

//Argument number 4, Boolean value which should be TRUE I guess
VARIANT vtParam4;
VariantInit(&vtParam4);
vtParam4.vt = VT_BOOL;
vtParam4.boolVal = VARIANT_TRUE;

//Number of arguments to the Add method of "CommandBars" class
const int numArgs = 4;

VARIANT vtArg[numArgs];
vtArg[0].vt = VT_VARIANT;
vtArg[0].pvarVal = &vtParam1;

vtArg[1].vt = VT_VARIANT;
vtArg[1].pvarVal = &vtParam2;

vtArg[2].vt = VT_VARIANT;
vtArg[2].pvarVal = &vtParam3;

vtArg[3].vt = VT_VARIANT;
vtArg[3].pvarVal = &vtParam4;

DISPID dwDispID;
DISPPARAMS dispparams = {NULL, NULL, 0, 0};
dispparams.rgvarg = rgVarParams;
dispparams.cArgs = numArgs;

HRESULT hr = pDisp-GetIDsOfNames(IID_NULL, L"Add",
1,LOCALE_USER_DEFAULT,
&dwDispID);

if(SUCCEEDED(hr)) {
hr = pDisp-Invoke(dwDispID, IID_NULL, LOCALE_USER_DEFAULT,
DISPATCH_METHOD, &dispparams, &vtMenuBar,
NULL, NULL);

if (FAILED(hr)) {
hr = pDisp-Invoke(dwDispID, IID_NULL,
LOCALE_USER_DEFAULT,
DISPATCH_METHOD| DISPATCH_PROPERTYGET,
&dispparams,
&vtMenuBar, NULL, NULL);
}

}

//Do any clean ups here.

} //AddMenuBar ends here.

Can any one please point out the problem in my code, is there anything
which I am missing or is there any thing which I did in wrong way. Why
the above code fails to add the menu bar to the Excel?

Any help will be much appreciated.

Thanks & Regards,
Mousam Dubey

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem Loading Addins - Excel Started through COM Interface newbie73 Excel Programming 1 September 7th 07 07:30 PM
problem in Excel's VB Help deo89 Excel Discussion (Misc queries) 2 February 22nd 06 10:58 PM
Web Interface Brain Buster Problem (for me at least :) ski Excel Programming 3 December 24th 04 12:57 AM
Web Enabled Excel Interface Problem TerryG Excel Programming 1 October 20th 04 09:12 PM
Tired of Excel's Interface limitations...?? Chris Gorham[_4_] Excel Programming 1 January 9th 04 09:05 PM


All times are GMT +1. The time now is 06:59 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"