Trying to install an add in using automatisation directly via C++

S

soeren

Hi,

I'm quite new to automatisation programming and really just want to
touch it (at least right now... ,-)). I've created an Excel-Addin which
gets installed using an installer package. At the end of the
installation process the add-In should be installed in Excel
automagically so the user does not have to care for this.
Using VBA the following two lines would do the job (add some glue code
here):

// AddIns.Add "E:\CreditToolbox\ExcelAddin\build\Managed.XLL"
// AddIns("KreditPricer PLUS").Installed = True

However, I don't have VBA available and I'd like to do it with C++ as
all the other parts of the project are also C++. So I crossed to
solutions from MS at http://support.microsoft.com/kb/q216686/ and
http://support.microsoft.com/kb/196776/ and tried to modify them for my
purpose. The following code is here (the XLL to register is hardcoded
in the example, AutoWrap function is copied from KB216686):

=========================================================================
// Start server and get IDispatch...this one works
IDispatch *pXlApp;
hr = CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER, IID_IDispatch,
(void **)&pXlApp);
if(FAILED(hr)) {
::MessageBox(NULL, "Excel not registered properly", "Error",
0x10010);
return -2;
};

// Get Addins collection...this one works
IDispatch *pXlAddins;
{
VARIANT result;
VariantInit(&result);
AutoWrap(DISPATCH_PROPERTYGET, &result, pXlApp, L"AddIns", 0);
pXlAddins = result.pdispVal;
};

// Call the "Add" method and install the Addin
{
VARIANT param;
param.vt = VT_BSTR;
param.bstrVal =
::SysAllocString(L"E:\\CreditToolbox\\ExcelAddin\\build\\Managed.XLL");
AutoWrap(DISPATCH_METHOD, NULL, pXlAddins, L"Add", 1, param);
VariantClear(&param);
};
=========================================================================

While the first two calls work, the third fails with the error
0x800a03ec which says something like " [Method name] method of [object]
class failed.".

So what am I missing here, this should be dead simple...



Thanks a lot in advance,
Soeren Gerlach
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top