Click here to Skip to main content
14,841,162 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow to determine file offset of each section using RVA in pe file ? Pin
Member 1254265131-May-16 1:26
MemberMember 1254265131-May-16 1:26 
AnswerRe: How to determine file offset of each section using RVA in pe file ? Pin
Richard MacCutchan31-May-16 2:00
mveRichard MacCutchan31-May-16 2:00 
AnswerRe: How to determine file offset of each section using RVA in pe file ? Pin
Bram van Kampen1-Jun-16 15:11
MemberBram van Kampen1-Jun-16 15:11 
QuestionCopy certain member variable data of a structure Pin
manoharbalu30-May-16 23:45
Membermanoharbalu30-May-16 23:45 
AnswerRe: Copy certain member variable data of a structure Pin
Richard MacCutchan31-May-16 0:31
mveRichard MacCutchan31-May-16 0:31 
GeneralRe: Copy certain member variable data of a structure Pin
manoharbalu31-May-16 0:40
Membermanoharbalu31-May-16 0:40 
GeneralRe: Copy certain member variable data of a structure Pin
Richard MacCutchan31-May-16 0:47
mveRichard MacCutchan31-May-16 0:47 
AnswerRe: Copy certain member variable data of a structure Pin
Jochen Arndt31-May-16 1:43
professionalJochen Arndt31-May-16 1:43 
Define your own protocol to be used with the socket communication. Then send a packet when data has been updated by a calculation. The protocol should be able handle the possible amount of data that is updated by your calculations.

A possible protocol structure may be:
typedef struct
{
    int updateType; // Identifies the struct member that is updated
    //int dataType;   // Optional: Data type of struct member (float, char)
    int firstNdx;   // First index for array data types
    int lastNdx;    // Optional: Last index (when multiple elements must be updated)
    int dataLen;    // Optional: Size of following data ((lastNdx - firstNdx) + 1)
                    // Multiply with size of data type for byte count 
    char data[1];   // Payload placeholder
} MyUpdateProtocol;

The updateType may be an enum instead of an <code>int:
enum MyDataMembers
{
    IVKK,
    FIL,
    FDDD,
    FCDCP,
    // ...
};

To create a protocol block calculate the amount of data bytes, allocate memory, cast it, fill it, and send it. Example:
int firstNdx = 0;
int lastNdx = 10;
int dataSize = ((lastNdx - firstNdx) + 1) * sizeof(float);
// Allocate buffer for protocol header and payload.
// Using a buffer on the stack here would be faster but
//  requires the size to be known during compilation time.
//char buf[sizeof(MyUpdateProtocol) - 1 + sizeof(float) * MAX_ELEMS_TO_BE_SEND];
char *buf = new char[dataSize + sizeof(MyUpdateProtocol) - 1];
// Cast buf to a protocol type pointer.
MyUpdateProtocol *pProto = (MyUpdateProtocol *)buf;
// Initialise the protocol header fields.
pProto->updateType = IVKK;
//pProto->dataType = MUP_FLOAT;
pProto->firstNdx = firstNdx;
pProto->lastNdx = lastNdx;
pProto->dataLen = dataSize;
// Copy the payload (pModDB is a pointer to the shared data).
memcpy(pProto->data, &pModDB->IVKK[firstNdx], dataSize);
// Send it.
// Use the real size here (subtract one byte for the data[1] member).
sendData(buf, dataSize + sizeof(MyUpdateProtocol) - 1);
delete [] buf;

On the receiving side copy the data according to the protocol header fields:
// Assuming received data has been copied to char *buf
MyUpdateProtocol *pProto = (MyUpdateProtocol *)buf;
void *dest = NULL;
switch (pProto->updateType)
{
    case IVKK : dest = &pModDb->IVKK[pProto->firstNdx]; break;
    case FIL : dest = &pModDb->FIL[pProto->firstNdx]; break;
    // ...
}
memcpy(dest, pProto->data, pProto->dataLen);

AnswerRe: Copy certain member variable data of a structure Pin
leon de boer31-May-16 3:59
Memberleon de boer31-May-16 3:59 
GeneralRe: Copy certain member variable data of a structure Pin
manoharbalu1-Jun-16 2:25
Membermanoharbalu1-Jun-16 2:25 
GeneralRe: Copy certain member variable data of a structure Pin
Bram van Kampen1-Jun-16 15:51
MemberBram van Kampen1-Jun-16 15:51 
GeneralRe: Copy certain member variable data of a structure Pin
manoharbalu1-Jun-16 20:02
Membermanoharbalu1-Jun-16 20:02 
GeneralRe: Copy certain member variable data of a structure Pin
leon de boer1-Jun-16 20:18
Memberleon de boer1-Jun-16 20:18 
GeneralRe: Copy certain member variable data of a structure Pin
leon de boer2-Jun-16 19:31
Memberleon de boer2-Jun-16 19:31 
QuestionRe: Copy certain member variable data of a structure Pin
David Crow31-May-16 5:07
MemberDavid Crow31-May-16 5:07 
QuestionC++ Smartphone application, get data from MySQL Pin
PonSvens29-May-16 10:04
MemberPonSvens29-May-16 10:04 
AnswerRe: C++ Smartphone application, get data from MySQL Pin
CPallini29-May-16 20:58
mveCPallini29-May-16 20:58 
AnswerRe: C++ Smartphone application, get data from MySQL Pin
leon de boer29-May-16 22:53
Memberleon de boer29-May-16 22:53 
AnswerRe: C++ Smartphone application, get data from MySQL Pin
Richard MacCutchan30-May-16 1:16
mveRichard MacCutchan30-May-16 1:16 
GeneralRe: C++ Smartphone application, get data from MySQL Pin
leon de boer30-May-16 2:43
Memberleon de boer30-May-16 2:43 
GeneralRe: C++ Smartphone application, get data from MySQL Pin
Richard MacCutchan30-May-16 3:02
mveRichard MacCutchan30-May-16 3:02 
GeneralRe: C++ Smartphone application, get data from MySQL Pin
David Crow30-May-16 5:04
MemberDavid Crow30-May-16 5:04 
Question8Puzzle game Pin
Abdulrahman Mostafa24-May-16 16:31
MemberAbdulrahman Mostafa24-May-16 16:31 
AnswerRe: 8Puzzle game Pin
Richard MacCutchan24-May-16 21:56
mveRichard MacCutchan24-May-16 21:56 
QuestionRe: 8Puzzle game Pin
David Crow25-May-16 4:34
MemberDavid Crow25-May-16 4:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.