開發平台(Platform): (Ex: Win10, Linux, ...)
Win10
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
Visual Studio2015
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
MFC
問題(Question):
小弟我目前要在64位元程式接收32位元程式產出的檔案
64及32程式都使用同一個dll(不過一個是32位元 一個是64位元)
https://imgur.com/a/bzvtkOb (sgFloat看做double)
在32位元程式寫入檔案
CFile fp;
fp.Open(sPath,CFile::modeCreate|CFile::modeWrite|CFile::typeBinary);
CArchive ar(&fp, CArchive::store);
CRule* pData = new CRule();
sgCMatrix* psgTemp;
psgTemp = new sgCMatrix();
psgTemp->SetMatrix(&g_tMatrix); //sgCMatrix g_tMatrix 宣告在其他cpp上、運算
pData->m_tMatrix = (void*) psgTemp; //void* m_tMatrix 宣告在CRule
ar.Write(pData->m_tMatrix, sizeof(sgCMatrix)); //sizeof(sgMatrix) 為132byte
在64位元程式讀檔
CFile fp;
fp.Open(sPath,CFile::modeRead|CFile::typeBinary);
CArchive ar(&fp, CArchive::load);
CRule* pData = new CRule();
sgCMatrix* psgTemp;
psgTemp = new sgCMatrix();
ar.Read((void*) psgTemp, sizeof(sgCMatrix)); //sizeof(sgMatrix) 為136byte
pData->m_tMatrix = (void*) psgTemp;
因為指標的差異所以記憶體上大小有差所以資料會錯誤
目前有兩個做法
1.把讀檔的sizeof(sgMatrix )直接改成132
讀資料時不會錯誤,但psgTemp裡該寫入136只寫132 後續是否產生錯誤
2.把32位元的程式升級到64位元
需將之前建好的檔案重建,但32位元建檔步驟很多,全部重建需花很多時間
3.在32位元程式寫檔時寫入136byte
不過sgMatrix 不是自己寫, 所以結構無法改
請各位前輩賜教
餵入的資料(Input):
預期的正確結果(Expected Output):
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版,禁止使用圖檔)
補充說明(Supplement):