union or marshaling problem(s) 
Author Message
 union or marshaling problem(s)

Dear sir(s);

As following sample, I cannot create the interface from another application
with union definition, why ?  When I reject/delete union definition or
delete property of the interface which using ChSmiValue definition then
everything works, otherwise getting E_NOINTERFACE when I try to create the
interface.

----------------------------------
COM/Interface definition :
----------------------------------

typedef [unique] struct _wireChSmiValue* wireChSmiValue;

struct tagChSmiValue
{
    int Syntax;
    union
 {
        int  iNumber;
  long lNumber;
    } Value;

Quote:
};

[ export, wire_marshal(wireChSmiValue) ]
typedef struct tagChSmiValue ChSmiValue;

[ export ]
struct _wireChSmiValue {
 int Syntax;

 [ switch_type(int), switch_is(Syntax) ]
 union Value
 {
  [ case(1) ]
   int  iNumber;

  [ case(2) ]
   long lNumber;
 };

Quote:
};

// IChIntA
[
 object,
 uuid("55888910-EC12-48D4-864D-E93223315E17"),
 dual, helpstring("IChIntA Interface"),
 pointer_default(unique)
]
__interface IChIntA : IDispatch
{
 [propget, id(1), helpstring("property Test")] HRESULT Test([out, retval]
ChSmiValue* pVal);
 [propput, id(1), helpstring("property Test")] HRESULT Test([in] ChSmiValue
newVal);

Quote:
};

// CChIntA

[
 coclass,
 threading("neutral"),
 vi_progid("ChTest.ChIntA"),
 progid("ChTest.ChIntA.1"),
 version(1.0),
 uuid("3B7C2A6E-69B7-4302-91C5-EEA0442BB700"),
 helpstring("ChIntA Class")
]
class ATL_NO_VTABLE CChIntA :
 public IChIntA
{
public:
 CChIntA()
 {
 }

 DECLARE_PROTECT_FINAL_CONSTRUCT()

 HRESULT FinalConstruct()
 {
  return S_OK;
 }

 void FinalRelease()
 {
 }

public:

 STDMETHOD(get_Test)(ChSmiValue* pVal)
 {
  return S_OK;
 }

 STDMETHOD(put_Test)(ChSmiValue newVal)
 {
  return S_OK;
 }

Quote:
};

----------------------------------
Application :
----------------------------------

#include "stdafx.h"
#import "_ChTest.tlb"

int _tmain(int argc, _TCHAR* argv[])
{
 ::CoInitialize(NULL);

 CComPtr<ChTestLib::IChIntA> o;
 HRESULT      hResult;

 hResult = o.CoCreateInstance(__uuidof(ChTestLib::CChIntA)); // Error !!
Result is E_NOINTERFACE

 ::CoUninitialize();
 return 0;

Quote:
}

Who will help me, I will regard.

--
Devinim T?LEN

IS Technology Services Manager

Global Bilgi Paz., Dan. ve ?aery Servisi Hiz. A.T.

Fatih C. Dereboyu S. No:8 34660  Halkaly-Ystanbul/Trkiye

GSM : +90 (532) 555 5500
Tel : +90 (212) 473 2020
Fax : +90 (533) 981 4683



Wed, 23 Feb 2005 04:33:18 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Marshal..marshaling..

2. Power of Unions ( surely union in C )

3. Conversion / marshaling problem

4. Conversion/marshaling problem

5. Marshal problem with pointers to structures

6. Marshal Ptr Problem

7. problem with Marshal.SizeOf()

8. Marshaling problem using WM_COPYDATA and byte[]

9. Problem using Marshal.PtrToStructure

10. Marshaling problems

11. COM+ marshaling problem

12. Problems using marshaled interface

 

 
Powered by phpBB® Forum Software