Windows Vista Forums

"Invalid callee" calling a com object
  1. #1


    Garios Guest

    "Invalid callee" calling a com object

    Hi!

    I have a com object and what it does is upload content into a database and
    returns the id of the generated content passing to a variable by reference.
    So the scripts looks something like this:
    -----------------
    $ArticleId = 0
    $impObj = New-Object –com mycomobject ;
    $impObj.ImportContent($content, ([ref]$ArticleId))
    ----------------
    I can see the content is generated in the database, but the ArticleId is not
    returned instead I get an error message like this:

    Exception calling "ImportContent" with "2" argument(s): "Invalid callee.
    (Exception from HRESULT: 0x80020010 (DISP_E_BADCALLEE))"

    So I am assuming the problem is the way the referenced Variable is passed,
    but I don't know why. I've ran the same object using VBSCript instead and it
    works returning the expected Id.

    Any help is appreciated.




      My System SpecsSystem Spec

  2. #2


    Bob Landau Guest

    RE: "Invalid callee" calling a com object

    [ref] is used by COM or RPC to declare pointer attributes. [ref] in .NET is
    used for parameter direction. These are in no way compatible.

    Do you have the return parameter which I assume is ArticleId attributed with
    "retval"

    Try this instead

    > $impObj.ImportContent($content, $ArticleId)

    "Garios" wrote:

    > Hi!
    >
    > I have a com object and what it does is upload content into a database and
    > returns the id of the generated content passing to a variable by reference.
    > So the scripts looks something like this:
    > -----------------
    > $ArticleId = 0
    > $impObj = New-Object –com mycomobject ;
    > $impObj.ImportContent($content, ([ref]$ArticleId))
    > ----------------
    > I can see the content is generated in the database, but the ArticleId is not
    > returned instead I get an error message like this:
    >
    > Exception calling "ImportContent" with "2" argument(s): "Invalid callee.
    > (Exception from HRESULT: 0x80020010 (DISP_E_BADCALLEE))"
    >
    > So I am assuming the problem is the way the referenced Variable is passed,
    > but I don't know why. I've ran the same object using VBSCript instead and it
    > works returning the expected Id.
    >
    > Any help is appreciated.
    >

      My System SpecsSystem Spec

  3. #3


    Garios Guest

    RE: "Invalid callee" calling a com object

    Thanks Bob for your help,

    But how should I attribute $ArticleId with retval in Powershell? I can't
    find the right sintax

    "Bob Landau" wrote:

    > [ref] is used by COM or RPC to declare pointer attributes. [ref] in .NET is
    > used for parameter direction. These are in no way compatible.
    >
    > Do you have the return parameter which I assume is ArticleId attributed with
    > "retval"
    >
    > Try this instead
    >

    > > $impObj.ImportContent($content, $ArticleId)
    >
    >
    > "Garios" wrote:
    >

    > > Hi!
    > >
    > > I have a com object and what it does is upload content into a database and
    > > returns the id of the generated content passing to a variable by reference.
    > > So the scripts looks something like this:
    > > -----------------
    > > $ArticleId = 0
    > > $impObj = New-Object –com mycomobject ;
    > > $impObj.ImportContent($content, ([ref]$ArticleId))
    > > ----------------
    > > I can see the content is generated in the database, but the ArticleId is not
    > > returned instead I get an error message like this:
    > >
    > > Exception calling "ImportContent" with "2" argument(s): "Invalid callee.
    > > (Exception from HRESULT: 0x80020010 (DISP_E_BADCALLEE))"
    > >
    > > So I am assuming the problem is the way the referenced Variable is passed,
    > > but I don't know why. I've ran the same object using VBSCript instead and it
    > > works returning the expected Id.
    > >
    > > Any help is appreciated.
    > >

      My System SpecsSystem Spec

  4. #4


    Bob Landau Guest

    RE: "Invalid callee" calling a com object

    You should not need to add any attribute. ArticleId is a simple integer,
    there must be thousands if not more COM components that return integers as a
    [retval].

    Post the IDL syntax for this specific method
    Is this an inproc or exe coclass?
    Is this a 32 or 64 bit OS?
    Are you using 32 or 64 bit powershell host to instanciate this coclass?
    Are you able to call any methods/properties on this coclass from powershell?
    What does "$impObj | Get-Member" return?
    Do the members look correct?
    Search for the IID of the interface in the registry with RegEdit.
    Get-Member returns this as

    TypeName: System.__ComObject#{<IID of the Interface that you have>}

    bob
    "Garios" wrote:

    > Hi!
    >
    > I have a com object and what it does is upload content into a database and
    > returns the id of the generated content passing to a variable by reference.
    > So the scripts looks something like this:
    > -----------------
    > $ArticleId = 0
    > $impObj = New-Object –com mycomobject ;
    > $impObj.ImportContent($content, ([ref]$ArticleId))
    > ----------------
    > I can see the content is generated in the database, but the ArticleId is not
    > returned instead I get an error message like this:
    >
    > Exception calling "ImportContent" with "2" argument(s): "Invalid callee.
    > (Exception from HRESULT: 0x80020010 (DISP_E_BADCALLEE))"
    >
    > So I am assuming the problem is the way the referenced Variable is passed,
    > but I don't know why. I've ran the same object using VBSCript instead and it
    > works returning the expected Id.
    >
    > Any help is appreciated.
    >

      My System SpecsSystem Spec

  5. #5


    Garios Guest

    RE: "Invalid callee" calling a com object

    Thank you Bob,

    Here is what I have:

    Method int ImportContent (string, Variant)

    So this component is returning a Variant as a [retval]

    I am using PS 32bit on a 32bit OS (W2008)

    Get-Member returns all properties and methods for the object, this COM
    object actually works on the same box when using with VBScript.

    If I don't use [ref] then I get this error:
    Argument: '2' should be a System.Management.Automation.PSReference. Use [ref].

    If I use [ref] then I get the error at the beginning of this post.


    "Bob Landau" wrote:

    > You should not need to add any attribute. ArticleId is a simple integer,
    > there must be thousands if not more COM components that return integers as a
    > [retval].
    >
    > Post the IDL syntax for this specific method
    > Is this an inproc or exe coclass?
    > Is this a 32 or 64 bit OS?
    > Are you using 32 or 64 bit powershell host to instanciate this coclass?
    > Are you able to call any methods/properties on this coclass from powershell?
    > What does "$impObj | Get-Member" return?
    > Do the members look correct?
    > Search for the IID of the interface in the registry with RegEdit.
    > Get-Member returns this as
    >
    > TypeName: System.__ComObject#{<IID of the Interface that you have>}
    >

      My System SpecsSystem Spec

  6. #6


    Bob Landau Guest

    RE: "Invalid callee" calling a com object

    What language did you write this in? The signature doesn't look correct at
    all. With the exception of 2 or so special interfaces COM methods all return
    HRESULTS.

    Here is what it should look like in Powershell once you're components been
    instanciated

    AToI Method Variant AToI (string)

    Here is the IDL syntax for the above
    id(1), helpstring("method AToI")] HRESULT AToI([in] BSTR strNum,
    [out,retval] VARIANT* Number);

    Here is the implementation
    STDMETHODIMP CNumber::AToI(BSTR strNum, VARIANT* Number)
    {
    int retVal = _wtoi(strNum);
    VariantInit(Number);
    Number->vt = VT_I4;
    Number->lVal = retVal;
    return S_OK;
    }

    I suggest that you start with something very simple such as this, get the
    protocol correct so that .NET and COM understand each other and then make
    your real component match.


    "Garios" wrote:

    > Thank you Bob,
    >
    > Here is what I have:
    >
    > Method int ImportContent (string, Variant)
    >
    > So this component is returning a Variant as a [retval]
    >
    > I am using PS 32bit on a 32bit OS (W2008)
    >
    > Get-Member returns all properties and methods for the object, this COM
    > object actually works on the same box when using with VBScript.
    >
    > If I don't use [ref] then I get this error:
    > Argument: '2' should be a System.Management.Automation.PSReference. Use [ref].
    >
    > If I use [ref] then I get the error at the beginning of this post.
    >
    >
    > "Bob Landau" wrote:
    >

    > > You should not need to add any attribute. ArticleId is a simple integer,
    > > there must be thousands if not more COM components that return integers as a
    > > [retval].
    > >
    > > Post the IDL syntax for this specific method
    > > Is this an inproc or exe coclass?
    > > Is this a 32 or 64 bit OS?
    > > Are you using 32 or 64 bit powershell host to instanciate this coclass?
    > > Are you able to call any methods/properties on this coclass from powershell?
    > > What does "$impObj | Get-Member" return?
    > > Do the members look correct?
    > > Search for the IID of the interface in the registry with RegEdit.
    > > Get-Member returns this as
    > >
    > > TypeName: System.__ComObject#{<IID of the Interface that you have>}
    > >
    >

      My System SpecsSystem Spec

  7. #7


    Garios Guest

    RE: "Invalid callee" calling a com object

    Hi Bob,

    Thank you for stayiing with me on this one.

    Your wrote:

    Here is what it should look like in Powershell once you're components been
    instanciated

    AToI Method Variant AToI (string)


    And what I have with get-member is this:

    ImportContent Method int ImportContent (string, Variant)

    So this method is returning an integer wich is an error code and also is
    passing as a reference ArticleId on the second field of the method.

    I think you are assuming that I wrote the COM object (I know nothing about
    IDL or implementation), that's not the case, I am just an IT guy trying to
    use the same COM object that has been working for years with VBScript and
    re-use it in powershell.


    "Bob Landau" wrote:

    > What language did you write this in? The signature doesn't look correct at
    > all. With the exception of 2 or so special interfaces COM methods all return
    > HRESULTS.
    >
    > Here is what it should look like in Powershell once you're components been
    > instanciated
    >
    > AToI Method Variant AToI (string)
    >
    > Here is the IDL syntax for the above
    > id(1), helpstring("method AToI")] HRESULT AToI([in] BSTR strNum,
    > [out,retval] VARIANT* Number);
    >
    > Here is the implementation
    > STDMETHODIMP CNumber::AToI(BSTR strNum, VARIANT* Number)
    > {
    > int retVal = _wtoi(strNum);
    > VariantInit(Number);
    > Number->vt = VT_I4;
    > Number->lVal = retVal;
    > return S_OK;
    > }
    >
    > I suggest that you start with something very simple such as this, get the
    > protocol correct so that .NET and COM understand each other and then make
    > your real component match.
    >
    >
    > "Garios" wrote:
    >

    > > Thank you Bob,
    > >
    > > Here is what I have:
    > >
    > > Method int ImportContent (string, Variant)
    > >
    > > So this component is returning a Variant as a [retval]
    > >
    > > I am using PS 32bit on a 32bit OS (W2008)
    > >
    > > Get-Member returns all properties and methods for the object, this COM
    > > object actually works on the same box when using with VBScript.
    > >
    > > If I don't use [ref] then I get this error:
    > > Argument: '2' should be a System.Management.Automation.PSReference. Use [ref].
    > >
    > > If I use [ref] then I get the error at the beginning of this post.
    > >
    > >
    > > "Bob Landau" wrote:
    > >

    > > > You should not need to add any attribute. ArticleId is a simple integer,
    > > > there must be thousands if not more COM components that return integers as a
    > > > [retval].
    > > >
    > > > Post the IDL syntax for this specific method
    > > > Is this an inproc or exe coclass?
    > > > Is this a 32 or 64 bit OS?
    > > > Are you using 32 or 64 bit powershell host to instanciate this coclass?
    > > > Are you able to call any methods/properties on this coclass from powershell?
    > > > What does "$impObj | Get-Member" return?
    > > > Do the members look correct?
    > > > Search for the IID of the interface in the registry with RegEdit.
    > > > Get-Member returns this as
    > > >
    > > > TypeName: System.__ComObject#{<IID of the Interface that you have>}
    > > >
    > >

      My System SpecsSystem Spec

  8. #8


    Garios Guest

    RE: "Invalid callee" calling a com object

    BTW:

    I've found by using OLEView that the syntax is this:

    [id(0x0000000c), helpstring("method ImportContent")]
    HRESULT ImportContent(
    [in] BSTR strArticleName,
    [out] VARIANT* pArticleId,
    [out, retval] long* pError);




    "Bob Landau" wrote:

    > What language did you write this in? The signature doesn't look correct at
    > all. With the exception of 2 or so special interfaces COM methods all return
    > HRESULTS.
    >
    > Here is what it should look like in Powershell once you're components been
    > instanciated
    >
    > AToI Method Variant AToI (string)
    >
    > Here is the IDL syntax for the above
    > id(1), helpstring("method AToI")] HRESULT AToI([in] BSTR strNum,
    > [out,retval] VARIANT* Number);
    >
    > Here is the implementation
    > STDMETHODIMP CNumber::AToI(BSTR strNum, VARIANT* Number)
    > {
    > int retVal = _wtoi(strNum);
    > VariantInit(Number);
    > Number->vt = VT_I4;
    > Number->lVal = retVal;
    > return S_OK;
    > }
    >
    > I suggest that you start with something very simple such as this, get the
    > protocol correct so that .NET and COM understand each other and then make
    > your real component match.
    >
    >
    > "Garios" wrote:
    >

    > > Thank you Bob,
    > >
    > > Here is what I have:
    > >
    > > Method int ImportContent (string, Variant)
    > >
    > > So this component is returning a Variant as a [retval]
    > >
    > > I am using PS 32bit on a 32bit OS (W2008)
    > >
    > > Get-Member returns all properties and methods for the object, this COM
    > > object actually works on the same box when using with VBScript.
    > >
    > > If I don't use [ref] then I get this error:
    > > Argument: '2' should be a System.Management.Automation.PSReference. Use [ref].
    > >
    > > If I use [ref] then I get the error at the beginning of this post.
    > >
    > >
    > > "Bob Landau" wrote:
    > >

    > > > You should not need to add any attribute. ArticleId is a simple integer,
    > > > there must be thousands if not more COM components that return integers as a
    > > > [retval].
    > > >
    > > > Post the IDL syntax for this specific method
    > > > Is this an inproc or exe coclass?
    > > > Is this a 32 or 64 bit OS?
    > > > Are you using 32 or 64 bit powershell host to instanciate this coclass?
    > > > Are you able to call any methods/properties on this coclass from powershell?
    > > > What does "$impObj | Get-Member" return?
    > > > Do the members look correct?
    > > > Search for the IID of the interface in the registry with RegEdit.
    > > > Get-Member returns this as
    > > >
    > > > TypeName: System.__ComObject#{<IID of the Interface that you have>}
    > > >
    > >

      My System SpecsSystem Spec

"Invalid callee" calling a com object problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Exception calling "CreateInstance" with "2" argument(s): for Microsoft.Update.UpdateColl Rich PowerShell 2 26 Jan 2009
Exception calling "Send" with "1" argument(s) error using PING bass_player PowerShell 4 08 Jul 2008
Not a "Genuine Copy", and an "Invalid Activation Key" from Gateway karlano Vista installation & setup 6 13 Jun 2008
Separate hashtable vs $alist | where-object { "key" = "value" } versus something else? ydroam PowerShell 2 12 Dec 2006
interesting "issue" or "bug" with psobjects when calling DOTNET framework stuff klumsy@xtra.co.nz PowerShell 0 09 Nov 2006