Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions MyClientCpp/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ int main() {
double pi = cruncher->ComputePi();
std::wcout << L"pi = " << pi << std::endl;

CComSafeArray<BYTE> arr;
arr.Attach(cruncher->ComputeValues(4));
std::wcout << L"array: [";
for (unsigned int i = 0; i < arr.GetCount(); ++i)
std::wcout << (int)arr[(LONG)i] << L", ";
std::wcout << L"]\n";

auto callback = CreateLocalInstance<MyClient>();
server->Subscribe(callback);

Expand Down
3 changes: 3 additions & 0 deletions MyClientCs/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ static void CommunicateWithServer()
double pi = cruncher.ComputePi();
Console.WriteLine($"pi = {pi}");

byte[] values = cruncher.ComputeValues(4);
Console.WriteLine("ComputeValues: ["+ string.Join(", ", values) + "]");

// release reference to help GC clean up (not strctly needed)
cruncher = null;
}
Expand Down
14 changes: 14 additions & 0 deletions MyExeServerCpp/MyServerImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ class ATL_NO_VTABLE NumberCruncher :
return S_OK;
}

HRESULT STDMETHODCALLTYPE raw_ComputeValues(unsigned int count, /*out*/SAFEARRAY** vals) override {
if (!vals)
return E_INVALIDARG;

// populate array with values
CComSafeArray<BYTE> tmp(count);
for (unsigned int i = 0; i < count; ++i)
tmp[(LONG)i] = (BYTE)i;

*vals = tmp.Detach();
return S_OK;
}


BEGIN_COM_MAP(NumberCruncher)
COM_INTERFACE_ENTRY(INumberCruncher)
END_COM_MAP()
Expand Down
9 changes: 9 additions & 0 deletions MyExeServerCs/MyServerImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,14 @@ public double ComputePi ()
{
return Math.PI;
}

public byte[] ComputeValues(uint count)
{
byte[] values = new byte[count];
for (uint i = 0; i < count; i++)
values[i] = (byte)i;

return values;
}
}
}
3 changes: 3 additions & 0 deletions MyInterfaces/MyInterfaces.idl
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ interface IMyClient : IUnknown {
interface INumberCruncher : IUnknown {
[helpstring("Compute the value of pi")]
HRESULT ComputePi([out, retval] double *ret);

[helpstring("Get an array with magic values.")]
HRESULT ComputeValues([in] unsigned int count, [out, retval] SAFEARRAY(BYTE)* vals);
};

[object,
Expand Down