排版不好,我在贴一份 //get the file sizeof the file in bytes
//struct stat sbuf;
        // fstat((int)stream,&sbuf);
        //int length = _filelength((int)stream); 
fseek(stream, 0L, SEEK_END);
int filelength =ftell(stream);
        fseek(stream,0L,SEEK_SET);  
        
        //create a heap for the model 
t3dmodel.hHeapHandle  = HeapCreate(NULL,filelength*2,0);
        if(t3dmodel.hHeapHandle == NULL)
{
SetLastError(8);
return false;
} if(stream == NULL)
{
//set the error that ERROR_PATH_NOT_FOUND
SetLastError(2);
return false;
}

//specify whether it's the correct format
int format = 0;
read+=4*fread(&format,sizeof(int),1,stream);
if(format != 4520)
{
            //An attempt was made to load a program with an incorrect forma
SetLastError(11);
fclose(stream);
return false;
}//#ifdef _debug
HANDLE hHeap[25];
DWORD dwNumHeaps = GetProcessHeaps(25,hHeap);
//#endif 
//Now load the file's object

read += 4*fread(&t3dmodel.numOfObjects ,sizeof(int),1,stream);


for(int i = 0; i < t3dmodel.numOfObjects  ;i++)
{   //specify the memory to be alloc
int len = 0;
t3DObject t3dobject;
read += 4*fread(&t3dobject.numOfVerts,sizeof(int),1,stream);
read += 4*fread(&t3dobject.numOfFaces,sizeof(int),1,stream);
read += 4*fread(&t3dobject.numTexVertex,sizeof(int),1,stream);
read += 4*fread(&t3dobject.materialID,sizeof(int),1,stream);
read += sizeof(bool)*fread(&t3dobject.bHasTexture,sizeof(bool),1,stream);
read += sizeof(char)*fread(t3dobject.strName,sizeof(char),255,stream);

//alloc the memory for the pVerts
//t3dobject.pVerts = new tVector3[t3dobject.numOfVerts];

if(t3dobject.numOfVerts >0)
{
len = sizeof(tVector3)*t3dobject.numOfVerts;
t3dobject.pVerts =(tVector3 *)HeapAlloc(t3dmodel.hHeapHandle,HEAP_ZERO_MEMORY|HEAP_GENERATE_EXCEPTIONS,len);
if(t3dobject.pVerts == NULL) goto END;
read += sizeof(tVector3)*fread(t3dobject.pVerts,sizeof(tVector3),t3dobject.numOfVerts,stream);
}
//alloc the memory for the pNormals
//t3dobject.pNormals = new tVector3[t3dobject.numOfFaces];
if(t3dobject.numOfFaces >0)
{
len = sizeof(tVector3)*t3dobject.numOfFaces;
t3dobject.pNormals = (tVector3 *)HeapAlloc(t3dmodel.hHeapHandle,HEAP_ZERO_MEMORY,len);
if(t3dobject.pNormals ==NULL) goto END;
//memset(t3dobject.pNormals,0,sizeof(tVector3)*t3dobject.numOfFaces);
read += sizeof(tVector3)*fread(t3dobject.pNormals,sizeof(tVector3),t3dobject.numOfFaces,stream);
}
//allox the memory for teh pTexVerts
//t3dobject.pTexVerts = new tVector2[t3dobject.numTexVertex];
if(t3dobject.numTexVertex>0)
{
len = sizeof(tVector2)*t3dobject.numTexVertex;
t3dobject.pTexVerts  = (tVector2 *)HeapAlloc(t3dmodel.hHeapHandle,HEAP_ZERO_MEMORY,len);
if(t3dobject.pTexVerts == NULL) goto END;
read += sizeof(tVector2)*fread(t3dobject.pTexVerts,sizeof(tVector2),t3dobject.numTexVertex,stream);
}
//alloc the memory for the pFace
//t3dobject.pFaces = new tFace[t3dobject.numOfFaces];
if(t3dobject.numOfFaces > 0)
{
len = sizeof(tVector2)*t3dobject.numOfFaces;
t3dobject.pFaces  = (tFace *)HeapAlloc(t3dmodel.hHeapHandle,HEAP_ZERO_MEMORY,len);
if(t3dobject.pFaces == NULL) goto END;
read += sizeof(tFace)*fread(t3dobject.pFaces,sizeof(tFace),t3dobject.numOfFaces,stream);
}
ATLTRACE2("  read value:   %f\n",read);
//push the object to the vecot
t3dmodel.pObject.push_back(t3dobject);
}