Re: CreateMapFile e LPCWSTR



MAX_DATA is something you need to figure out on your own. E.g. if those are phone numbers, using 255 seems like a safe number, provided you do check every string when copying to the buffer. An alternative is to calculate the size of each string and then allocate enough memory for those strings + 2-4 bytes for a counter preceding each string. This would be some sort of serialization

--
Alex Feinman
---
Visit http://www.opennetcf.org
"crino" <cseverini@xxxxxxxxxxxxxxxxxxx> wrote in message news:6ZPbe.1299251$35.48196172@xxxxxxxxxxxxxxx

"Alex Feinman [MVP]" <public_news@xxxxxxxxxxxxxxx> ha scritto nel messaggio news:ubUOow0SFHA.3620@xxxxxxxxxxxxxxxxxxxxxxx
If you store pointer inside file mapping it does not mean the objects pointed to by it are in shared memory as well.
Normally you design your shared data section layout so as to hold all the data as embedded arrays:
yes....this is my  thought


typedef struct { int nCount; WCHAR g_Array[0][MAX_DATA];

} SETTING_BUFFER;
typedef SETTING_BUFFER *PSETTING_BUFFER;

[0] compile returns: warning C4200: nonstandard extension used : zero-sized array in struct/union
so i set:
typedef struct {
int nCount;
WCHAR g_Array[1][MAX_DATA];
} SETTING_BUFFER;
typedef SETTING_BUFFER *PSETTING_BUFFER;


Essentially you flatten your data by allocating MAX_DATA character to each string and placing them in an array, one by one

i'm missing this step MAX_DATA should be 255 like WCHAR mystring[255] ... rigth?
but then how i can reallocate the new length of my array??



To access data use (LPWSTR)(pBuffer->g_Array[i])
ok ;)

Thanx Alex


--
Alex Feinman
---
Visit http://www.opennetcf.org
"crino" <cseverini@xxxxxxxxxxxxxxxxxxx> wrote in message news:mIObe.1298770$35.48175235@xxxxxxxxxxxxxxx
Hi,
i create call CreateFileMapping and set a pointer to my structure by MapViewOfFile.
This is my structure:


typedef struct {
int g_Length;
LPCWSTR* g_Array;
} SETTING_BUFFER;
typedef SETTING_BUFFER *PSETTING_BUFFER;

from the same pointer i can read the values stored.
From another function, lauched in a second moment, i call CreateFileMapping and set another pointer to my structure by MapViewOfFile,
but g_Length is read correctly while g_Array crashs my dll or it's empty.


this is the code which set the structure

g_hCFMObj = CreateFileMapping((HANDLE)-1, NULL, PAGE_READWRITE, 0, 1024, TEXT("SettingBuffer"));
g_pClientSettingBuffer = (PSETTING_BUFFER)MapViewOfFile(g_hCFMObj, FILE_MAP_WRITE, 0, 0, 0);


g_pClientSettingBuffer->g_Length = aLength;
g_pClientSettingBuffer->g_Array = (LPCWSTR*) malloc(aLength*sizeof(LPCWSTR));
for (int n=0; n < g_pClientSettingBuffer->g_Length; n++)
{
g_pClientSettingBuffer->g_Array[n] = aArray[n]; //aArray is declare like: LPCWSTR aArray[]
}


from the other function:
g_hSCFMObj = CreateFileMapping((HANDLE)-1, NULL, PAGE_READWRITE, 0, 1024, TEXT("SettingBuffer"));
g_pSettingBuffer = (PSETTING_BUFFER)MapViewOfFile(g_hSCFMObj, FILE_MAP_WRITE, 0, 0, 0);
for(n=0; n < g_pSettingBuffer->g_Length; n++)
{
MessageBox(0, g_pSettingBuffer->g_Array[n], L"Array values",0); //here crashes or shows empty string!??!
}


i've tried to change my structure like this:

typedef struct {
int g_Length;
WCHAR g_Array[255];
} SETTING_BUFFER;
typedef SETTING_BUFFER *PSETTING_BUFFER;

and i set the values:
lstrcpy(g_pClientSettingBuffer->g_Array, (WCHAR*)aArray[0]);

this works propertly but i can set only a value while i've an array of strings to store :(

Thanx in advance and sorry but array in c++ aren't my power :((









.



Relevant Pages

  • Re: CreateMapFile e LPCWSTR
    ... Excuse me Alex ... but i can't resize my array with the new length:(( ... > check every string when copying to the buffer. ... >>> typedef struct { ...
    (microsoft.public.pocketpc.developer)
  • Re: CreateMapFile e LPCWSTR
    ... > check every string when copying to the buffer. ... >>> typedef struct { ... >> but then how i can reallocate the new length of my array?? ... >>> Alex Feinman ...
    (microsoft.public.pocketpc.developer)
  • NEWBIE: malloc an array????
    ... I am having problems properly malloc'ing an array. ... typedef struct arrays ... "word" structure contains an array of "chars" i.e. a string. ...
    (comp.lang.c)
  • Re: HELP, INFINIT LOOP... simple LINKED LIST
    ... > typedef struct node ... > void AddNode(List *L, String item) ... which is what gives you undefined behaviour in the above code). ... Danger of buffer overrun attack by careless or malicious user. ...
    (comp.lang.c)
  • Multiple Double Linked Lists
    ... string is a string of characters representing the identifier itself. ... typedef struct Names DLList; ... typedef struct header *headerpt; ...
    (comp.lang.c)