   WriteFile and ReadFile
  Hello.I'm using CreateFile to export some data but I seem to fail even with a simple example.In the first file that is actually a plugin in a 3d modeling softwarebinFile = CreateFile(L"C:\\model.vvv", GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL); int vertices_count = 114;WriteFile(binFile,&vertices_count,sizeof(vertices_count) ,&wmWritten,NULL);CloseHandle(binFile);// wmWritten are 4 (actually an INT)In the second file that loads the modelbinFile = CreateFile(L"C:\\model.vvv", GENERIC_READ,  FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); //the file loads withoyt any errors; int number_of_v; SetFilePointer( binFile, 0, NULL, FILE_BEGIN );  ReadFile(binFile,&number_of_v,sizeof(number_of_v),NULL,NULL); CloseHandle(binFile);//it crashes at ReadFile.. line EVEN if in the debug sesion in the AUTOS section I see that the variable value is corect (114 from the previos saved file). But I still get the crash and I dont know why.
  You need to pass a pointer for the number of bytes read in ReadFile (lpNumberOfBytesRead). As stated in the remarks of MSDN:This parameter can be NULL only when the lpOverlapped parameter is not NULL.;  Thank you very much. It worksNow another problem that I cant fix.In the plugin exporter program is the next code:binFile = CreateFile(L"C:\\model.vvv", GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL); struct SimpleVertex {D3DXVECTOR3 Pos; D3DXVECTOR4 Color; }; //code that initializes maya and iterrates thoru the scene and if it find a mesh object it executes:fMesh->getPoints(fVertexArray, MSpace::kWorld); DWORD vertices_count = fVertexArray.length();SimpleVertex *vertices;vertices = new SimpleVertex[vertices_count];for (int i=0;i<vertices_count;i++) {vertices.Pos.x = fVertexArray.x;vertices.Pos.y = fVertexArray.y;vertices.Pos.z = fVertexArray.z;vertices.Color = D3DXVECTOR4( 1.0f, 1.0f, 1.0f, 0.5f );}DWORD wmWritten; DWORD wmWritten2; WriteFile(binFile,&vertices_count,sizeof(DWORD) ,&wmWritten,NULL);cout << "BYTES WRITTEN FOR VERTICES NUMBER = " <<wmWritten<<endl;WriteFile(binFile,&vertices,sizeof(SimpleVertex) * vertices_count ,&wmWritten2,NULL);//I used a debug text file to output the vertices and they seem to be acordingly to the scene. Also the vertice_count is corect. So far so good..The problem seems to be when I import the file to another project:binFileX = CreateFile(L"C:\\model.vvv", GENERIC_READ, FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);  DWORD number_of_v; DWORD wmWritten; DWORD wmWritten2; ReadFile(binFileX,&number_of_v,sizeof(DWORD),&wmWritten,NULL); //Here everything is ok , the read are ok, the variable number_of_v is actually the corect number of vertices from the file   SimpleVertex *binVerts;    binVerts = new SimpleVertex[number_of_v];    ReadFile(binFileX,&binVerts,sizeof(SimpleVertex)* number_of_v, &wmWritten2,NULL);    //HERE IS THE PROBLEM.. i DONT GET A CRASH BUT I DONT GET THE CORECT DATA FROM THE FILE    //every vertex has the same value ( random number) and the GetLastError gives me error 998 - Invalid access to memory location.What Im doing wrong ?    CloseHandle(binFileX);I,ve noted the problem in the code.   ;Quote:WriteFile(binFile,&vertices,sizeof(SimpleVertex) * vertices_count ,&wmWritten2,NULL);WriteFile needs a pointer to the data, not the address of a pointer.This should be:WriteFile(binFile,vertices,sizeof(SimpleVertex) * vertices_count ,&wmWritten2,NULL);vertices is a pointer. &vertices is the address where the pointer is stored, not where the array is stored.;  Thank you very much. It worked.   