Click here to Skip to main content
15,894,362 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: template problems Pin
Joaquín M López Muñoz7-Oct-04 2:38
Joaquín M López Muñoz7-Oct-04 2:38 
GeneralRe: template problems Pin
pankajdaga7-Oct-04 10:44
pankajdaga7-Oct-04 10:44 
GeneralDebugging DLL project in VC++ 6.0 Pin
Neeranjan7-Oct-04 1:51
Neeranjan7-Oct-04 1:51 
GeneralRe: Debugging DLL project in VC++ 6.0 Pin
Roger Allen7-Oct-04 7:13
Roger Allen7-Oct-04 7:13 
GeneralWriting/Reading binaric objects to/from a file Pin
impeham7-Oct-04 1:46
impeham7-Oct-04 1:46 
GeneralRe: Writing/Reading binaric objects to/from a file Pin
Cedric Moonen7-Oct-04 2:19
Cedric Moonen7-Oct-04 2:19 
GeneralRe: Writing/Reading binaric objects to/from a file Pin
impeham7-Oct-04 2:45
impeham7-Oct-04 2:45 
GeneralRe: Writing/Reading binaric objects to/from a file Pin
Cedric Moonen7-Oct-04 3:03
Cedric Moonen7-Oct-04 3:03 
Of course, you cannot use this when your structure hold pointers !!! WTF | :WTF:

What is a pointer ? A pointer is just a 32 bits variable that holds an adress (at this adress, the data is stored). So, when you write the pointer to the file, it just stores the adress and not the data.

If you want to save your structure, it would be a better idea to encapsulate the save/load functions inside your structure (if you don't use the MFC and/or don't want to use serialisation, you can do it yourself):

typedef struct
{
   int DataCount;
   int* pSomeData;

   void SaveData(HANDLE* hFile)
   {
      DWORD NumberOfBytesWritten;
      WriteFile(hFile, &DataCount, sizeof(int), &NumberOfBytesWritten, NULL);
      WriteFile(hFile, pSomeData, sizeof(int)*DataCount, &NumberOfBytesWritten, NULL);
   }

   void LoadData(HANDLE* hFile)
   {
      DWORD NumberOfBytesRead;
      ReadFile(hFile, &DataCount, sizeof(int), &NumberOfBytesRead, NULL);
      pSomeData = new int[DataCount];
      ReadFile(hFile, pSomeData, sizeof(int))*DataCount, &NumberOfBytesRead, NULL);
   }
} YourStruct;


And from the outside it will look like:
YourStruct* pStruct = new YourStruct;
//Do something with pStruct
//..
//..
pStruct->SaveData(hFile);


Or for loading:
YourStruct* pStruct = new YourStruct;
pStruct->LoadData(hFile);
//Do something with pStruct
//..
//..


Hope this helps
GeneralRe: Writing/Reading binaric objects to/from a file Pin
Ravi Bhavnani7-Oct-04 2:23
professionalRavi Bhavnani7-Oct-04 2:23 
GeneralData Sharing Pin
shiraztk7-Oct-04 0:49
shiraztk7-Oct-04 0:49 
GeneralRe: Data Sharing Pin
Cedric Moonen7-Oct-04 1:12
Cedric Moonen7-Oct-04 1:12 
GeneralRe: Data Sharing Pin
Blake Miller7-Oct-04 11:07
Blake Miller7-Oct-04 11:07 
GeneralRe: Data Sharing Pin
jan larsen7-Oct-04 1:22
jan larsen7-Oct-04 1:22 
GeneralRe: Data Sharing Pin
shiraztk7-Oct-04 19:40
shiraztk7-Oct-04 19:40 
GeneralConverting CString Pin
Franz Klein7-Oct-04 0:07
Franz Klein7-Oct-04 0:07 
GeneralRe: Converting CString Pin
Joaquín M López Muñoz7-Oct-04 2:40
Joaquín M López Muñoz7-Oct-04 2:40 
GeneralSocket Programming using threads Pin
Ajoy6-Oct-04 23:29
Ajoy6-Oct-04 23:29 
GeneralRe: Socket Programming using threads Pin
Sujan Christo7-Oct-04 0:49
Sujan Christo7-Oct-04 0:49 
GeneralRe: Socket Programming using threads Pin
Bob Stanneveld7-Oct-04 2:46
Bob Stanneveld7-Oct-04 2:46 
GeneralRe: Socket Programming using threads Pin
vcplusplus7-Oct-04 3:02
vcplusplus7-Oct-04 3:02 
GeneralRe: Socket Programming using threads Pin
Bob Stanneveld7-Oct-04 3:11
Bob Stanneveld7-Oct-04 3:11 
GeneralDIID_HTMLElementEvents2 Pin
george ivanov6-Oct-04 22:50
george ivanov6-Oct-04 22:50 
GeneralVC and Crystal Report Pin
TrungHuynh6-Oct-04 22:27
TrungHuynh6-Oct-04 22:27 
GeneralRe: VC and Crystal Report Pin
Member 14198776-Oct-04 23:43
Member 14198776-Oct-04 23:43 
GeneralRe: VC and Crystal Report Pin
Jose Cezar S. Ynion7-Oct-04 1:47
Jose Cezar S. Ynion7-Oct-04 1:47 

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.