crino
Wed Apr 27 13:45:46 CDT 2005
Excuse me Alex
but i can't resize my array with the new length :((
#define MAX_DATA 255
typedef struct {
int g_Length;
WCHAR g_Phone[1][MAX_DATA];
} SETTING_BUFFER;
//here i've to reallocate with the g_Length
??????
//copy each string into the array
for (int n=0; n < pBuffer ->g_Length; n++)
{
lstrcpy(pBuffer ->g_Array[n], aPhone[n]);
}
Can yuo help me on resize :(
"Alex Feinman [MVP]" <public_news@alexfeinman.com> ha scritto nel messaggio
news:OmuE$F1SFHA.3464@tk2msftngp13.phx.gbl...
> 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@n0spam.aditusnet.it> wrote in message
> news:6ZPbe.1299251$35.48196172@news4.tin.it...
>>
>> "Alex Feinman [MVP]" <public_news@alexfeinman.com> ha scritto nel
>> messaggio news:ubUOow0SFHA.3620@TK2MSFTNGP09.phx.gbl...
>>> 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@n0spam.aditusnet.it> wrote in message
>>> news:mIObe.1298770$35.48175235@news4.tin.it...
>>>> 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 :((
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>
>>
>