HRESULT return type turns into void when adding class from type library 
Author Message
 HRESULT return type turns into void when adding class from type library

I used the ATL COM Wizard in Visual C++ 6.0 to create a DLL to which I
added a dual interface simple ATL object.

The return types of the methods that I added in the idl file are
HRESULT. And I would like them to be so. But when I go to my application
project and use the ClassWizard to add the ATL object's class using the
generated type library the resulting cpp and header files have void as
method return types insted of HRESULT. What's going on? Is there a bug
in the ClassWizard?

Here is the idl file:

// testobject.idl : IDL source for testobject.dll
//

// This file will be processed by the MIDL tool to
// produce the type library (testobject.tlb) and marshalling code.

import "oaidl.idl";
import "ocidl.idl";
        [
                object,
                uuid(B2F35252-1926-11D3-A87A-00105AC7622F),
                dual,
                helpstring("ITestAtlObject Interface"),
                pointer_default(unique)
        ]
        interface ITestAtlObject : IDispatch
        {
                [id(1), helpstring("method SetupObject")] HRESULT
SetupObject(BSTR name, BSTR number);
                [id(2), helpstring("method LaunchObject")] HRESULT
LaunchObject(BSTR name, BSTR launchPad);
                [id(3), helpstring("method CancelObject")] HRESULT
CancelObject(BSTR name);
                [id(4), helpstring("method GetObjectState")] HRESULT
GetObjectState(BSTR name, LPDWORD state);
        };

[
        uuid(B2F35243-1926-11D3-A87A-00105AC7622F),
        version(1.0),
        helpstring("testobject 1.0 Type Library")
]
library TESTOBJECTLib
{
        importlib("stdole32.tlb");
        importlib("stdole2.tlb");

        [
                uuid(B2F35253-1926-11D3-A87A-00105AC7622F),
                helpstring("TestAtlObject Class")
        ]
        coclass TestAtlObject
        {
                [default] interface ITestAtlObject;
        };

Quote:
};

-------------------------------------------------------------------
And here is the ClassWizard generated header and cpp files (wrappers) in
my application project:

// Machine generated IDispatch wrapper class(es) created with
ClassWizard
////////////////////////////////////////////////////////////////////////
/////
// ITestAtlObject wrapper class

class ITestAtlObject : public COleDispatchDriver
{
public:
        ITestAtlObject() {}             // Calls COleDispatchDriver
default constructor
        ITestAtlObject(LPDISPATCH pDispatch) :
COleDispatchDriver(pDispatch) {}
        ITestAtlObject(const ITestAtlObject& dispatchSrc) :
COleDispatchDriver(dispatchSrc) {}

// Attributes
public:

// Operations
public:
        void SetupObject(LPCTSTR name, LPCTSTR number);
        void LaunchObject(LPCTSTR name, LPCTSTR launchPad);
        void CancelObject(LPCTSTR name);
        void GetObjectState(LPCTSTR name, unsigned long* state);

Quote:
};

---------------

// Machine generated IDispatch wrapper class(es) created with
ClassWizard

#include "stdafx.h"
#include "testobject.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

////////////////////////////////////////////////////////////////////////
/////
// ITestAtlObject properties

////////////////////////////////////////////////////////////////////////
/////
// ITestAtlObject operations

void ITestAtlObject::SetupObject(LPCTSTR name, LPCTSTR number)
{
        static BYTE parms[] =
                VTS_BSTR VTS_BSTR;
        InvokeHelper(0x1, DISPATCH_METHOD, VT_EMPTY, NULL, parms,
                 name, number);

Quote:
}

void ITestAtlObject::LaunchObject(LPCTSTR name, LPCTSTR launchPad)
{
        static BYTE parms[] =
                VTS_BSTR VTS_BSTR;
        InvokeHelper(0x2, DISPATCH_METHOD, VT_EMPTY, NULL, parms,
                 name, launchPad);

Quote:
}

void ITestAtlObject::CancelObject(LPCTSTR name)
{
        static BYTE parms[] =
                VTS_BSTR;
        InvokeHelper(0x3, DISPATCH_METHOD, VT_EMPTY, NULL, parms,
                 name);

Quote:
}

void ITestAtlObject::GetObjectState(LPCTSTR name, unsigned long* state)
{
        static BYTE parms[] =
                VTS_BSTR VTS_PI4;
        InvokeHelper(0x4, DISPATCH_METHOD, VT_EMPTY, NULL, parms,
                 name, state);

Quote:
}

-----------

Notice how all the method return types, defined in idl file as HRESULT,
in the wrapper class magically turned into void!

I greatly appreciate any help,

Paul Litvak

Sent via Deja.com http://www.*-*-*.com/
Share what you know. Learn what you don't.



Sun, 18 Nov 2001 03:00:00 GMT  
 HRESULT return type turns into void when adding class from type library
Hi,

Nope - if u QI for the dual interface's name u will still b able to work
with it.. BUT - wrappers will turn it into a regular IDispatch meaning the
following:
1. Errors will be thrown.
2. return values are the parameter in the IDL which contains the [retval]
attribute.

--
Shahar Prish
Development Team Leader
Maximal Innovative Intelligence (http://www.maxsw.com)

Quote:

>I used the ATL COM Wizard in Visual C++ 6.0 to create a DLL to which I
>added a dual interface simple ATL object.

>The return types of the methods that I added in the idl file are
>HRESULT. And I would like them to be so. But when I go to my application
>project and use the ClassWizard to add the ATL object's class using the
>generated type library the resulting cpp and header files have void as
>method return types insted of HRESULT. What's going on? Is there a bug
>in the ClassWizard?

>Here is the idl file:

>// testobject.idl : IDL source for testobject.dll
>//

>// This file will be processed by the MIDL tool to
>// produce the type library (testobject.tlb) and marshalling code.

>import "oaidl.idl";
>import "ocidl.idl";
> [
> object,
> uuid(B2F35252-1926-11D3-A87A-00105AC7622F),
> dual,
> helpstring("ITestAtlObject Interface"),
> pointer_default(unique)
> ]
> interface ITestAtlObject : IDispatch
> {
> [id(1), helpstring("method SetupObject")] HRESULT
>SetupObject(BSTR name, BSTR number);
> [id(2), helpstring("method LaunchObject")] HRESULT
>LaunchObject(BSTR name, BSTR launchPad);
> [id(3), helpstring("method CancelObject")] HRESULT
>CancelObject(BSTR name);
> [id(4), helpstring("method GetObjectState")] HRESULT
>GetObjectState(BSTR name, LPDWORD state);
> };

>[
> uuid(B2F35243-1926-11D3-A87A-00105AC7622F),
> version(1.0),
> helpstring("testobject 1.0 Type Library")
>]
>library TESTOBJECTLib
>{
> importlib("stdole32.tlb");
> importlib("stdole2.tlb");

> [
> uuid(B2F35253-1926-11D3-A87A-00105AC7622F),
> helpstring("TestAtlObject Class")
> ]
> coclass TestAtlObject
> {
> [default] interface ITestAtlObject;
> };
>};
>-------------------------------------------------------------------
>And here is the ClassWizard generated header and cpp files (wrappers) in
>my application project:

>// Machine generated IDispatch wrapper class(es) created with
>ClassWizard
>////////////////////////////////////////////////////////////////////////
>/////
>// ITestAtlObject wrapper class

>class ITestAtlObject : public COleDispatchDriver
>{
>public:
> ITestAtlObject() {} // Calls COleDispatchDriver
>default constructor
> ITestAtlObject(LPDISPATCH pDispatch) :
>COleDispatchDriver(pDispatch) {}
> ITestAtlObject(const ITestAtlObject& dispatchSrc) :
>COleDispatchDriver(dispatchSrc) {}

>// Attributes
>public:

>// Operations
>public:
> void SetupObject(LPCTSTR name, LPCTSTR number);
> void LaunchObject(LPCTSTR name, LPCTSTR launchPad);
> void CancelObject(LPCTSTR name);
> void GetObjectState(LPCTSTR name, unsigned long* state);
>};

>---------------

>// Machine generated IDispatch wrapper class(es) created with
>ClassWizard

>#include "stdafx.h"
>#include "testobject.h"

>#ifdef _DEBUG
>#define new DEBUG_NEW
>#undef THIS_FILE
>static char THIS_FILE[] = __FILE__;
>#endif

>////////////////////////////////////////////////////////////////////////
>/////
>// ITestAtlObject properties

>////////////////////////////////////////////////////////////////////////
>/////
>// ITestAtlObject operations

>void ITestAtlObject::SetupObject(LPCTSTR name, LPCTSTR number)
>{
> static BYTE parms[] =
> VTS_BSTR VTS_BSTR;
> InvokeHelper(0x1, DISPATCH_METHOD, VT_EMPTY, NULL, parms,
> name, number);
>}

>void ITestAtlObject::LaunchObject(LPCTSTR name, LPCTSTR launchPad)
>{
> static BYTE parms[] =
> VTS_BSTR VTS_BSTR;
> InvokeHelper(0x2, DISPATCH_METHOD, VT_EMPTY, NULL, parms,
> name, launchPad);
>}

>void ITestAtlObject::CancelObject(LPCTSTR name)
>{
> static BYTE parms[] =
> VTS_BSTR;
> InvokeHelper(0x3, DISPATCH_METHOD, VT_EMPTY, NULL, parms,
> name);
>}

>void ITestAtlObject::GetObjectState(LPCTSTR name, unsigned long* state)
>{
> static BYTE parms[] =
> VTS_BSTR VTS_PI4;
> InvokeHelper(0x4, DISPATCH_METHOD, VT_EMPTY, NULL, parms,
> name, state);
>}

>-----------

>Notice how all the method return types, defined in idl file as HRESULT,
>in the wrapper class magically turned into void!

>I greatly appreciate any help,

>Paul Litvak

>Sent via Deja.com http://www.deja.com/
>Share what you know. Learn what you don't.



Thu, 22 Nov 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. void return type

2. calling a function w/ void return type in c#

3. adding with void type problem

4. Help with: C2392 - covariant returns types are not supported in managed types

5. undefined type in arg list vs. return type

6. void pointer (void *) : how to determine type?

7. MessengerAPI type library - IDispatch enum type problem

8. Add Version Info to a Type Library?

9. add type library to dll as resource

10. add type library to dll as resource

11. Covariant return type in managed class workaround?

12. How do I add member variables of type MyClass to a Dialog Class

 

 
Powered by phpBB® Forum Software