File tree Expand file tree Collapse file tree 5 files changed +36
-0
lines changed
Expand file tree Collapse file tree 5 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -75,6 +75,13 @@ int main() {
7575 double pi = cruncher->ComputePi ();
7676 std::wcout << L" pi = " << pi << std::endl;
7777
78+ CComSafeArray<BYTE> arr;
79+ arr.Attach (cruncher->ComputeValues (4 ));
80+ std::wcout << L" array: [" ;
81+ for (unsigned int i = 0 ; i < arr.GetCount (); ++i)
82+ std::wcout << (int )arr[(LONG)i] << L" , " ;
83+ std::wcout << L" ]\n " ;
84+
7885 auto callback = CreateLocalInstance<MyClient>();
7986 server->Subscribe (callback);
8087
Original file line number Diff line number Diff line change @@ -16,6 +16,9 @@ static void CommunicateWithServer()
1616 double pi = cruncher . ComputePi ( ) ;
1717 Console . WriteLine ( $ "pi = { pi } ") ;
1818
19+ byte [ ] values = cruncher . ComputeValues ( 4 ) ;
20+ Console . WriteLine ( "ComputeValues: [" + string . Join ( ", " , values ) + "]" ) ;
21+
1922 // release reference to help GC clean up (not strctly needed)
2023 cruncher = null ;
2124 }
Original file line number Diff line number Diff line change @@ -88,6 +88,9 @@ interface IMyClient : IUnknown {
8888interface INumberCruncher : IUnknown {
8989 [helpstring("Compute the value of pi")]
9090 HRESULT ComputePi([out, retval] double *ret);
91+
92+ [helpstring("Get an array with magic values.")]
93+ HRESULT ComputeValues([in] unsigned int count, [out, retval] SAFEARRAY(BYTE)* vals);
9194};
9295
9396[object,
Original file line number Diff line number Diff line change @@ -37,6 +37,20 @@ class ATL_NO_VTABLE NumberCruncher :
3737 return S_OK;
3838 }
3939
40+ HRESULT STDMETHODCALLTYPE raw_ComputeValues (unsigned int count, /* out*/ SAFEARRAY** vals) override {
41+ if (!vals)
42+ return E_INVALIDARG;
43+
44+ // populate array with values
45+ CComSafeArray<BYTE> tmp (count);
46+ for (unsigned int i = 0 ; i < count; ++i)
47+ tmp[(LONG)i] = (BYTE)i;
48+
49+ *vals = tmp.Detach ();
50+ return S_OK;
51+ }
52+
53+
4054 BEGIN_COM_MAP (NumberCruncher)
4155 COM_INTERFACE_ENTRY (INumberCruncher)
4256 END_COM_MAP ()
Original file line number Diff line number Diff line change @@ -142,5 +142,14 @@ public double ComputePi ()
142142 {
143143 return Math . PI ;
144144 }
145+
146+ public byte [ ] ComputeValues ( uint count )
147+ {
148+ byte [ ] values = new byte [ count ] ;
149+ for ( uint i = 0 ; i < count ; i ++ )
150+ values [ i ] = ( byte ) i ;
151+
152+ return values ;
153+ }
145154 }
146155}
You can’t perform that action at this time.
0 commit comments