What I am trying to achieve is this - C++ DLL searches for bluetooth devices, on finding one instantiates a class and fills the new object. This needs to be serialized, sent over the named pipe to a calling C# DLL that has a thread that reads from the pipe and updates the UI. Sending a string over the pipe works fine eg SendDataToPipe(_T("Phone\n")); but I will need to change parameter type to handle a class. Not sure how to get the serialization and sending the result over the pipe. This link Serialize in C++ then deserialize in C# looks good for the last piece of my puzzle. Moderators if this is to plain and not clear please just lock it and I will try again. Thanks.
UINT SendDataToPipe(LPTSTR data)
{
DWORD numBytesWritten = 0;
BOOL result = WriteFile(pipe, data, _tcslen(data) * sizeof(TCHAR), &numBytesWritten, NULL);
if (result)
return numBytesWritten;
else
return -1;
}
In header file
class CFoundDevice : public CObject
{
public:
CFoundDevice();
~CFoundDevice();
DECLARE_SERIAL(CFoundDevice);
public:
CString fdtype;
CString fdname;
protected:
public:
virtual void Serialize(CArchive& ar);
protected:
};
In cpp file
#include "stdafx.h"
#include "FoundDevice.h"
IMPLEMENT_SERIAL(CFoundDevice, CObject, 1)
CFoundDevice::CFoundDevice()
{
fdtype = "";
fdname = "";
}
CFoundDevice::~CFoundDevice()
{
}
void CFoundDevice::Serialize(CArchive& ar)
{
DWORD dwVersion = 0x00000000;
if (ar.IsStoring())
{
ar << dwVersion;
ar << fdtype;
ar << fdname;
}
else
{
ar >> dwVersion;
ar >> fdtype;
ar >> fdname;
}
}
User contributions licensed under CC BY-SA 3.0