Click here to Skip to main content
15,881,882 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Modeless Onscreen Keyboard Pin
Rajesh R Subramanian21-Jun-11 9:40
professionalRajesh R Subramanian21-Jun-11 9:40 
GeneralRe: Modeless Onscreen Keyboard Pin
Chris Meech21-Jun-11 9:48
Chris Meech21-Jun-11 9:48 
GeneralRe: Modeless Onscreen Keyboard Pin
Rajesh R Subramanian21-Jun-11 9:53
professionalRajesh R Subramanian21-Jun-11 9:53 
AnswerRe: Modeless Onscreen Keyboard Pin
Rajesh R Subramanian21-Jun-11 9:52
professionalRajesh R Subramanian21-Jun-11 9:52 
QuestionRegarding Memory Mapped Pin
manju 321-Jun-11 2:52
manju 321-Jun-11 2:52 
AnswerRe: Regarding Memory Mapped Pin
«_Superman_»21-Jun-11 6:17
professional«_Superman_»21-Jun-11 6:17 
GeneralRe: Regarding Memory Mapped Pin
manju 323-Jun-11 2:39
manju 323-Jun-11 2:39 
GeneralRe: Regarding Memory Mapped Pin
enhzflep23-Jun-11 11:06
enhzflep23-Jun-11 11:06 
Let's just pause for a second, and think about it..

Your first process takes some data (in this case, a character based string) and copies it into a buffer.

Your second process reads from that buffer and displays this info as a string. The second process has no inherent knowledge of the data structure of the shared memory.

This much is no different to any normal file - it is up to the definer of the data to decide how it will be stored, and as a consequence, how it will be retrieved.

So, instead of blindly copying the message to the buffer, you may decide to use the first 4 bytes (for example) of the buffer to store the number of messages being passed. You may then write your messages 1 after another - remembering to make sure you have a null terminator between each string.


Here's some code that will demonstrate the concept:
#include <stdio.h>
#include <stdlib.h>

#define buffSize 2048
char buffer[buffSize];

void initBuffer()
{
    memset((PVOID)buffer, 0, sizeof(char) * buffSize);
}

// returns number of messages in buffer
// -1 if failed
int addMsg(char *msg)
{
    long msgCount, curMsgIndex, curMsgLen;
    char *newStrPos;

    memcpy((PVOID)&msgCount, buffer, sizeof(long));

    newStrPos = (char*) (long)&buffer + sizeof(long);

    for (curMsgIndex=0; curMsgIndex<msgCount; curMsgIndex++)
    {
        curMsgLen = strlen(newStrPos);
        newStrPos += curMsgLen + 1;
    }

    // don't forget to check that this message won't overflow the buffer!!!
    // I didn't bother for this simple example
    //if ( ((newStrPos-buffer)+strlen(msg)+1) < buffSize)
    {
        printf("adding message\n");
        strcpy(newStrPos, msg);
        msgCount++;
        memcpy((PVOID)buffer, &msgCount, sizeof(long));
    }
    //else
    //    printf("unable to add message\n");

}

void printMessages()
{
    long msgCount, curMsgNum;
    char *curMsg;

    memcpy(&msgCount, buffer, sizeof(long));
    curMsg = (char*)(long)&buffer + sizeof(long);
    for (curMsgNum=0; curMsgNum<msgCount;curMsgNum++)
    {
            printf("%s\n", curMsg);
            curMsg += strlen(curMsg) + 1;
    }
}

int main()
{
    initBuffer();
    addMsg("This is msg 1");
    addMsg("This is msg 2");
    printMessages();
    return 0;
}


S.
GeneralRe: Regarding Memory Mapped Pin
manju 323-Jun-11 20:25
manju 323-Jun-11 20:25 
GeneralRe: Regarding Memory Mapped Pin
enhzflep23-Jun-11 21:12
enhzflep23-Jun-11 21:12 
GeneralRe: Regarding Memory Mapped Pin
manju 323-Jun-11 22:19
manju 323-Jun-11 22:19 
GeneralRe: Regarding Memory Mapped Pin
enhzflep24-Jun-11 0:12
enhzflep24-Jun-11 0:12 
GeneralRe: Regarding Memory Mapped Pin
manju 324-Jun-11 2:07
manju 324-Jun-11 2:07 
GeneralRe: Regarding Memory Mapped Pin
manju 32-Aug-11 19:49
manju 32-Aug-11 19:49 
Questionfp:precise vs. fp:strict performance Pin
Alex_GR21-Jun-11 2:37
Alex_GR21-Jun-11 2:37 
QuestionReceive a client event when file on web server is modified Pin
pscholl21-Jun-11 0:54
pscholl21-Jun-11 0:54 
AnswerRe: Receive a client event when file on web server is modified Pin
Mark Salsbery21-Jun-11 8:18
Mark Salsbery21-Jun-11 8:18 
GeneralRe: Receive a client event when file on web server is modified Pin
pscholl22-Jun-11 1:34
pscholl22-Jun-11 1:34 
GeneralRe: Receive a client event when file on web server is modified Pin
Mark Salsbery22-Jun-11 7:55
Mark Salsbery22-Jun-11 7:55 
QuestionSort the list of files available in a folder. Pin
lucky_122120-Jun-11 23:02
lucky_122120-Jun-11 23:02 
AnswerRe: Sort the list of files available in a folder. Pin
Cedric Moonen21-Jun-11 0:14
Cedric Moonen21-Jun-11 0:14 
AnswerRe: Sort the list of files available in a folder. Pin
Richard MacCutchan21-Jun-11 2:03
mveRichard MacCutchan21-Jun-11 2:03 
GeneralRe: Sort the list of files available in a folder. Pin
lucky_122121-Jun-11 2:10
lucky_122121-Jun-11 2:10 
GeneralRe: Sort the list of files available in a folder. Pin
Richard MacCutchan21-Jun-11 2:59
mveRichard MacCutchan21-Jun-11 2:59 
AnswerRe: Sort the list of files available in a folder. Pin
వేంకటనారాయణ(venkatmakam)21-Jun-11 3:05
వేంకటనారాయణ(venkatmakam)21-Jun-11 3:05 

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.