Bonjour,

J'essaye actuellement de créer un objet COM avec c++builder2007... et je n'y arrive pas.

C'est un truc tout simple qui doit juste me renvoyer un nombre.

Voici mon interface
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
 
interface ITestServeurCOM: IUnknown
{
  [
  propget, 
  id(0x00000065)
  ]
  HRESULT _stdcall Name([out, retval] float * sName );
};
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
 
coclass TTestServeurCOM
{
  [default] interface ITestServeurCOM;
};
Voila ce que ca me donne en C++
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
 
#ifndef   testServeurCOM_TLBH
#define   testServeurCOM_TLBH
 
#pragma option push -b -w-inl
 
#if !defined(__UTILCLS_H)
#include <utilcls.h>
#endif
#if !defined(__UTILCLS_H_VERSION) || (__UTILCLS_H_VERSION < 0x0700)
//
// The code generated by the TLIBIMP utility or the Import|TypeLibrary
// and Import|ActiveX feature of C++Builder rely on specific versions of
// the header file UTILCLS.H found in the INCLUDE\VCL directory. If an
// older version of the file is detected, you probably need an update/patch.
//
#error "This file requires a newer version of the header UTILCLS.H" \
	   "You need to apply an update/patch to your copy of C++Builder"
#endif
#include <olectl.h>
#include <ocidl.h>
#if defined(USING_ATLVCL) || defined(USING_ATL)
#if !defined(__TLB_NO_EVENT_WRAPPERS)
#include <atl/atlmod.h>
#endif
#endif
 
 
// *********************************************************************//
// Forward reference of some VCL types (to avoid including STDVCL.HPP)    
// *********************************************************************//
namespace Stdvcl {class IStrings; class IStringsDisp;}
using namespace Stdvcl;
typedef TComInterface<IStrings> IStringsPtr;
typedef TComInterface<IStringsDisp> IStringsDispPtr;
 
namespace Testserveurcom_tlb
{
 
// *********************************************************************//
// HelpString: testServeurCOM Library
// Version:    1.0
// *********************************************************************//
 
 
// *********************************************************************//
// GUIDS declared in the TypeLibrary. Following prefixes are used:        
//   Type Libraries     : LIBID_xxxx                                      
//   CoClasses          : CLSID_xxxx                                      
//   DISPInterfaces     : DIID_xxxx
//   Non-DISP interfaces: IID_xxxx                                        
// *********************************************************************//
extern __declspec (package) const GUID LIBID_testServeurCOM;
extern __declspec (package) const GUID IID_ITestServeurCOM;
extern __declspec (package) const GUID CLSID_TTestServeurCOM;
 
// *********************************************************************//
// Forward declaration of types defined in TypeLibrary                    
// *********************************************************************//
interface DECLSPEC_UUID("{758138FD-2BE7-4751-AD81-B19FD6E560FE}") ITestServeurCOM;
typedef TComInterface<ITestServeurCOM, &IID_ITestServeurCOM> ITestServeurCOMPtr;
 
 
// *********************************************************************//
// Declaration of CoClasses defined in Type Library                       
// (NOTE: Here we map each CoClass to its Default Interface)              
//                                                                        
// The LIBID_OF_ macro(s) map a LIBID_OF_CoClassName to the GUID of this
// TypeLibrary. It simplifies the updating of macros when CoClass name    
// change.                                                                
// *********************************************************************//
typedef ITestServeurCOM TTestServeurCOM;
typedef ITestServeurCOMPtr TTestServeurCOMPtr;
 
#define LIBID_OF_TTestServeurCOM (&LIBID_testServeurCOM)
// *********************************************************************//
// Interface: ITestServeurCOM
// Flags:     (320) Dual OleAutomation
// GUID:      {758138FD-2BE7-4751-AD81-B19FD6E560FE}
// *********************************************************************//
interface ITestServeurCOM  : public IUnknown
{
public:
  virtual HRESULT STDMETHODCALLTYPE get_Nombre(float* fNum/*[out,retval]*/) = 0; // [101]
 
#if !defined(__TLB_NO_INTERFACE_WRAPPERS)
 
  float __fastcall get_Nombre(void)
  {
    float fNum;
    OLECHECK(this->get_Nombre((float*)&fNum));
	return fNum;
  }
 
 
  __property   float           Nombre = {read = get_Nombre};
 
#endif //   __TLB_NO_INTERFACE_WRAPPERS
 
};
 
#if !defined(__TLB_NO_INTERFACE_WRAPPERS)
// *********************************************************************//
// SmartIntf: TCOMITestServeurCOM
// Interface: ITestServeurCOM
// *********************************************************************//
template <class T /* ITestServeurCOM */ >
class TCOMITestServeurCOMT : public TComInterface<ITestServeurCOM>, public TComInterfaceBase<IUnknown>
{
public:
  TCOMITestServeurCOMT() {}
  TCOMITestServeurCOMT(ITestServeurCOM *intf, bool addRef = false) : TComInterface<ITestServeurCOM>(intf, addRef) {}
  TCOMITestServeurCOMT(const TCOMITestServeurCOMT& src) : TComInterface<ITestServeurCOM>(src) {}
  TCOMITestServeurCOMT& operator=(const TCOMITestServeurCOMT& src) { Bind(src, true); return *this;}
 
  HRESULT         __fastcall get_Nombre(float* fNum/*[out,retval]*/);
  float           __fastcall get_Nombre(void);
 
  __property   float           Nombre = {read = get_Nombre};
};
typedef TCOMITestServeurCOMT<ITestServeurCOM> TCOMITestServeurCOM;
 
// *********************************************************************//
// DispIntf:  ITestServeurCOM
// Flags:     (320) Dual OleAutomation
// GUID:      {758138FD-2BE7-4751-AD81-B19FD6E560FE}
// *********************************************************************//
template<class T>
class ITestServeurCOMDispT : public TAutoDriver<ITestServeurCOM>
{
public:
  ITestServeurCOMDispT(){}
 
  ITestServeurCOMDispT(ITestServeurCOM *pintf)
  {
    TAutoDriver<ITestServeurCOM>::Bind(pintf, false);
  }
 
  ITestServeurCOMDispT(ITestServeurCOMPtr pintf)
  {
    TAutoDriver<ITestServeurCOM>::Bind(pintf, true);
  }
 
  ITestServeurCOMDispT& operator=(ITestServeurCOM *pintf)
  {
	TAutoDriver<ITestServeurCOM>::Bind(pintf, false);
    return *this;
  }
 
  ITestServeurCOMDispT& operator=(ITestServeurCOMPtr pintf)
  {
	TAutoDriver<ITestServeurCOM>::Bind(pintf, true);
    return *this;
  }
 
  HRESULT BindDefault()
  {
	return OLECHECK(Bind(CLSID_TTestServeurCOM));
  }
 
  HRESULT BindRunning()
  {
    return BindToActive(CLSID_TTestServeurCOM);
  }
 
  HRESULT         __fastcall get_Nombre(float* fNum/*[out,retval]*/);
  float           __fastcall get_Nombre(void);
 
  __property   float           Nombre = {read = get_Nombre};
};
typedef ITestServeurCOMDispT<ITestServeurCOM> ITestServeurCOMDisp;
 
// *********************************************************************//
// SmartIntf: TCOMITestServeurCOM
// Interface: ITestServeurCOM
// *********************************************************************//
template <class T> HRESULT __fastcall
TCOMITestServeurCOMT<T>::get_Nombre(float* fNum/*[out,retval]*/)
{
  return (*this)->get_Nombre(fNum);
}
 
template <class T> float __fastcall
TCOMITestServeurCOMT<T>::get_Nombre(void)
{
  float fNum;
  OLECHECK(this->get_Nombre((float*)&fNum));
  return fNum;
}
 
// *********************************************************************//
// DispIntf:  ITestServeurCOM
// Flags:     (320) Dual OleAutomation
// GUID:      {758138FD-2BE7-4751-AD81-B19FD6E560FE}
// *********************************************************************//
template <class T> HRESULT __fastcall
ITestServeurCOMDispT<T>::get_Nombre(float* fNum/*[out,retval]*/)
{
  _TDispID _dispid(*this, OLETEXT("Nombre"), DISPID(101));
  TAutoArgs<0> _args;
  return OutRetValSetterPtr(fNum /*[VT_R4:1]*/, _args, OlePropertyGet(_dispid, _args));
}
 
template <class T> float __fastcall
ITestServeurCOMDispT<T>::get_Nombre(void)
{
  float fNum;
  this->get_Nombre((float*)&fNum);
  return fNum;
}
 
// *********************************************************************//
// The following typedefs expose classes (named CoCoClassName) that       
// provide static Create() and CreateRemote(LPWSTR machineName) methods   
// for creating an instance of an exposed object. These functions can     
// be used by client wishing to automate CoClasses exposed by this        
// typelibrary.                                                           
// *********************************************************************//
 
// *********************************************************************//
// COCLASS DEFAULT INTERFACE CREATOR
// CoClass  : TTestServeurCOM
// Interface: TCOMITestServeurCOM
// *********************************************************************//
typedef TCoClassCreatorT<TCOMITestServeurCOM, ITestServeurCOM, &CLSID_TTestServeurCOM, &IID_ITestServeurCOM> CoTTestServeurCOM;
#endif  //   __TLB_NO_INTERFACE_WRAPPERS
 
 
};     // namespace Testserveurcom_tlb
 
#if !defined(NO_IMPLICIT_NAMESPACE_USE)
using  namespace Testserveurcom_tlb;
#endif
 
#pragma option pop
 
#endif // testServeurCOM_TLBH
Derriere ca, je crée une classe qui implemente la fonction get_Nombre:
.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
 
/---------------------------------------------------------------------------
 
#ifndef testServeurH
#define testServeurH
//---------------------------------------------------------------------------
 
#include <string>
#include "testServeurCOM_TLB.h"
 
class ATL_NO_VTABLE testServeur :
  public CComObjectRootEx<CComSingleThreadModel>,
  public CComCoClass<TTestServeurCOM, &CLSID_TTestServeurCOM>,
  public ITestServeurCOM
  {
public:
	testServeur(){}
 
	// Data used when registering Object
	DECLARE_THREADING_MODEL(otApartment);
	DECLARE_PROGID("testServerCOM.TTestServerCOM");
	DECLARE_DESCRIPTION("The testServeur object");
 
	// Function invoked to (un)register object
	static HRESULT WINAPI UpdateRegistry(BOOL bRegister)
	{
		TTypedComServerRegistrarT<testServeur>
		regObj(GetObjectCLSID(), GetProgID(), GetDescription());
		return regObj.UpdateRegistry(bRegister);
	}
 
	BEGIN_COM_MAP(testServeur)
		COM_INTERFACE_ENTRY(ITestServeurCOM)
	END_COM_MAP()
 
public:
	STDMETHOD (get_Nombre(float*));
};
 
#endif
.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 
//---------------------------------------------------------------------------
 
 
#pragma hdrstop
 
#include "testServeur.h"
 
//---------------------------------------------------------------------------
 
#pragma package(smart_init)
 
STDMETHODIMP testServeur::get_Nombre(float* fNum){
	*sNun = 8.1;
}
J'avoue ne pas tout (rien) comprendre à ce qu'il y a dans le code. Il a été générer automatiquement.

Quand j'essaye de compiler, j'ai une erreur:
[BCC32 Erreur] atlcom.h(1879): E2352 Impossible de créer une instance de la classe abstraite 'CComObject<ITestServeurCOM>'
[BCC32 Erreur] atlcom.h(1879): E2353 La classe 'CComObject<ITestServeurCOM>' est abstraite parce que '__stdcall ITestServeurCOM::get_Nombre(float *) = 0'

Il me semble bien l'avoir défini cette methode get_Nombre.

Quelqu'un aurait-il une idée?