Re: CreateMapFile e LPCWSTR
- From: "Alex Feinman [MVP]" <public_news@xxxxxxxxxxxxxxx>
- Date: Wed, 27 Apr 2005 10:50:00 -0700
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@xxxxxxxxxxxxxxxxxxxxxxxIf 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
[0] compile returns: warning C4200: nonstandard extension used : zero-sized array in struct/union
typedef struct { int nCount; WCHAR g_Array[0][MAX_DATA];
} SETTING_BUFFER; typedef SETTING_BUFFER *PSETTING_BUFFER;
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 onei'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@xxxxxxxxxxxxxxxHi,
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 :((
.
- Follow-Ups:
- Re: CreateMapFile e LPCWSTR
- From: crino
- Re: CreateMapFile e LPCWSTR
- From: crino
- Re: CreateMapFile e LPCWSTR
- References:
- CreateMapFile e LPCWSTR
- From: crino
- Re: CreateMapFile e LPCWSTR
- From: Alex Feinman [MVP]
- Re: CreateMapFile e LPCWSTR
- From: crino
- CreateMapFile e LPCWSTR
- Prev by Date: Re: CreateMapFile e LPCWSTR
- Next by Date: Re: Accessing virtual serial port (COM8) of a bluetooth connected GPS receiver
- Previous by thread: Re: CreateMapFile e LPCWSTR
- Next by thread: Re: CreateMapFile e LPCWSTR
- Index(es):
Relevant Pages
|