Returning a value from a VC++ COM to VB 
Author Message
 Returning a value from a VC++ COM to VB

I have to make a COM DLL with VC++ to be used in Visual Basic and ASP
page.

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??

Need your help guys...

Sent via Deja.com
http://www.*-*-*.com/



Sun, 13 Jul 2003 02:17:43 GMT  
 Returning a value from a VC++ COM to VB
Define one of your function's paramters as [out, retval]
Quote:

> I have to make a COM DLL with VC++ to be used in Visual Basic and ASP
> page.

> 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??

> Need your help guys...

> Sent via Deja.com
> http://www.deja.com/



Sun, 13 Jul 2003 03:05:59 GMT  
 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



Sun, 13 Jul 2003 03:06:06 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Returning a variant value from VC++ to VB

2. Return values from VB CallBack Function to VC Dll

3. Problem calling VB COM dll from VC++ multithreaded COM EXE client

4. VB COM MIGRATION TO ATL VC COM

5. VC++ COM or VB COM - Which is better?

6. Problem with scripting context when using VB com object inside VC com object

7. problems passing ADO Recordset from VB-COM client to VC-COM-Server dll

8. Property return to default value at run-time in VB

9. Get return value from VB?

10. atl return value to vb?

11. Help - Calling ActiveX DLL function from VB and C++ returns different values

12. Get return value from VB?

 

 
Powered by phpBB® Forum Software