Trying to create a COM addin for VS2005 using a homebrew
programming language, I am stuck with the AddNamedCommand method.
My IDTExtensibility2:OnConnection goes like this:
OnConnection (env, mode, addin, ignore)
{if (mode = 5)
{commands = env.Commands;
command = commands.AddNamedCommand (addin, "Fee", "Fie", "Foe", true);
command.AddControl (env.CommandBars.Item("Tools"), 1);
}
return S_OK;
}
I have got this up and running in a COM registered DLL which I can start
from the VS Addin manager.
The extension::OnConnection method is, as need be, vtable based.
The other calls are done the IDispatch way, that is, using the
GetIDsOfNames/Invoke drill, passing the objects as
VT_DISPATCH variants.
The AddNamedCommand method seems to fail no matter what I do.
Given the 5 arguments shown, a type mismatch is returned with
an argument index of 0, which is supposed to mean the 5th parameter
is to blame. If I supply further arguments, I get a "bad argument" error,
I find it hard do determine whether the problem is:
1. my COM interfacing code (which is NASM assembler code),
2. the way I use the object,
or
3. these objects have less than perfect IDispatch implementation.
I would tend to assume the IDispatch implementation would work
as expected, if it weren't for the the peculiar fact that supplying values
for the optional parameters makes the type mismatch go away -
which puzzles me - I would figure the IDispatch implementation would
try to coerce the variants to the required types, failing with a
Type mismatch if this wasn't possible, then pass the parameters to
the vtable based method which might then detect an argument error
other than type mismatch. So this behaviour leads me to a suspicion
that the Type mismatch might be caused by a missing parameter, say,
a default value of wrong type.
Has anybody else used late-bound calls on these objects?
Did it work?
Does anyone know of an ATL or VB6 or whatever project that
isn't top secret and does or could be easily modified to do
what my addin tries to do, using late binding? This would enable
me to decide whether the problem is with my COM interfacing
mechanism or elsewhere - which is vital for me to know.
I'm using beta2 of VS2005.
Ole Nielsby - 17 Aug 2005 13:27 GMT
I wrote:
> Trying to create a COM addin for VS2005 using a homebrew
> programming language, I am stuck with the AddNamedCommand method.
Well, it turns out VB6 does the same. Here is the code, and Dummy is
simply a wrapper around MsgBox. I compile it with VB6 and load the
addin in VS2005 beta 2. (The other IDTExtensibility2 have trivial
implementations.)
My system is XP sp2 DK (danish) if that matters.
Private Sub IDTExtensibility2_OnConnection( _
ByVal Application As Object, _
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
ByVal AddInInst As Object, _
custom() As Variant)
Dim Commands As Object
Dummy "OnConnection"
Set Commands = Application.Commands
Dummy "Got Commands"
' This errs with Type mismatch:
Commands.AddNamedCommand AddInInst, "Katze1", "Katze2", "Katze3", True
Dummy "Leave"
End Sub
Now, the docs define the AddNamedCommand as:
Function AddNamedCommand( _
<InAttribute()> ByVal AddInInstance As AddIn, _
<InAttribute()> ByVal Name As String, _
<InAttribute()> ByVal ButtonText As String, _
<InAttribute()> ByVal Tooltip As String, _
<InAttribute()> ByVal MSOButton As Boolean, _
<InAttribute()> Optional ByVal Bitmap As Integer, _
<InAttribute()> Optional ByRef ContextUIGUIDs() As Object, _
<InAttribute()> Optional ByVal vsCommandDisabledFlagsValue As Integer _
) As Command
and I can't figure what I'm doing wrong. I supply all the required
parameters
of the required types.
(I know the addin is supposed to test ConnectMode and only add the
command
when in install mode. But this should not cause a type mismatch.)
ON/Remove the slow slimy animal from my reply address