referencing com add-in programatically


B

Birgit

Hi all,
I want to reference a public function in a Word add-in. This has me stumped.

I found article 240768 on the site of microsoft and a few scarce references
on the internet, but it doesn't work for me. It does not help dat I want to
do this in c++.

I understand that I need to do the following:
Private Sub IDTExtensibility2_OnConnection(ByVal Application As Object, _
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
ByVal AddInInst As Object, custom() As Variant)

Application.COMAddIns.Item("MyAddin.Connect").Object = Me
End Sub
where MyAddin is the name of my addin (which one: friendly, progID, etc?)
and Connect is the designer in the project (what is that supposed to mean?)

This is what I do in C:
//Get Addins collection

VARIANT vtParam; VariantInit(&vtParam);

VARIANT vtAddins; VariantInit(&vtAddins);

HRESULT hr = GetProperty(m_pParentApp, L"AddIns", &vtAddins);

if (FAILED(hr))

{

::MessageBox(0, "Addin collectie niet gelukt", "addin test", 0);

}

else

{

//Get item of Addin collection

VARIANT vtAddin; VariantInit(&vtAddin);

vtParam.vt = VT_BSTR; vtParam.bstrVal = ::SysAllocString(L"Test voor
Word.Connect");

hr = CallMethod(vtAddins.pdispVal, L"Item", &vtAddin, 1, &vtParam);

VariantClear(&vtParam);

VariantClear(&vtAddins);

if (FAILED(hr))

{

::MessageBox(0, "Addin niet gelukt", "addin test", 0);

}

else

{

//object van item benaderen

vtParam.vt = VT_DISPATCH; vtParam.pdispVal = addInInstance;

hr = PutProperty(vtAddin.pdispVal, L"Object", &vtParam);

if (FAILED(hr))

{

::MessageBox(0, "object niet gelukt", "addin test", 0);

}

else

{

//object te pakken krijgen

}

VariantClear(&vtParam);

VariantClear(&vtAddin);

}

VariantClear(&vtParam);

}



This fails on getting the addin. The collection is still fine. Please help?

Cheers, Birgit
 
Ad

Advertisements


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