
Returning a value from a VC++ COM to VB
Quote:
> So... I want to call my COM and I want him to return some value... how
> can I do that? With interface, you can't make your method to return a
> value because you must return a HRESULT... (else you got an error:
> procedures in an object interface must return an HRESULT).
> Pointer is the solution... but with Visual Basic, how can I call my
> method??
In your IDL file, add a parameter to your method with [out, retval]
attributes:
HRESULT MyMethod([in] long lMyParam, [out, retval] long* pResult);
Your code will looke something like this:
HRESULT CMyClass::MyMethod (long lParam, long* pResult)
{
....
*pResult = lValue;
return S_OK;
Quote:
}
VB will automatically interpret this as a Function which returns a Long (you
can check it in the Object Browser).
Since the parameter is declared [out, retval], VB will initialize the
variable, so all you have to do is fill the value in. Note that for BSTRs
and interface pointers VB only initializes the pointer.
HTH,
Daniel