"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
See below...
On Thu, 3 Jul 2008 09:50:06 -0700, "Nick Schultz" <nick.schultz@flir.com>
wrote:
so i have classes A and B with the following definitions:
class A{
unsigned char m_priority;
std::vector<char> m_data;
std::vector<B> m_rawPackets;
}
****
Absolutely not. std::vector puts the actual contents somewhere else, so
what the
receiving process would get is
[P] [yyyy] [zzzz]
where [P] is m_priority, [yyyy] is a pointer to the vector contents, and
[zzzz] is a
pointer to the vector contents. I would do this as I described earlier:
class A {
DWORD m_len; // total length of this structure
BYTE m_priority;
DWORD m_data;
DWORD m_packets;
BYTE info[1];
}
where m_data is the offset into the data array where the assembled data is
found
(typically 0) and m_packets is the offset into the data array where the
raw packets are
found. THus, what I would send is
[LLLL][P][...][0000][0079][D0D1D2D3...D78][R0..R7][R0..R7]...
where LLLL is the total length of the structure, which is
sizeof(A) + data.size + rawPackets.size * sizeof(B);
Assuming you have std::vector<BYTE>m_data and std::vector<B> rawpackets,
you would do
(using char instead of BYTE is often an error; for raw data use BYTE
unless the values are
8-bit signed values; you will have fewer errors)
A * ptr = (A*)new BYTE[sizeof(A) + data.size + rawPackets.size *
sizeof(B)];
then you would do
memcpy(A->info, data.size, data.whatever());
(I forget the method of std::vector that gives you the address of the
elements, you;ll
have to see what is used for 'whatever')
A->m_data = 0;
A->m_packets = data.size;
memcpy(&A->info[A-m_packets], sizeof(B)*rawPackets.size,
rawpackets.whatever());
Now THIS you can send with WM_COPYDATA!
joe
****
class B{
long m_id;
unsigned int m_flags;
unsigned char m_data[8];
unsigned long m_time;
}
Would I be able to send an instance of class A from process 1 to process 2
using WM_COPYDATA, by simply filling the COPYDATASTRUCT in process 1, copy
the struct to local memory in process 2, and cast COPYDATASTRUCT.lpData as
class A?
Is that how I would do it? or would having a vector complicate things?
Nick
"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
news:mfmp64le6gspkmnq6m610398u210aditt1@4ax.com...
Certainly NOT the clipboard. It doesn't really matter. But a copy is
made, temporarily
mapped into the recipient's address space, and deleted when you return
from handling the
CopyData call.
joe
On Thu, 3 Jul 2008 10:26:48 +0200, Kerem G?mr?kc?
<kareem114@hotmail.com>
wrote:
Hi Doug,
Yes, a copy will be made to memory the target process can read. If you
want
to avoid this, use memory mapped files.
thanks for your answer. One more Question: Where is the copy
holdet, in Clipboard or some other locked memory?
Regards
Kerem
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm