4

im creating a dll in MS Visual Studio 2010 Express which loads a binary data file (*.mgr extension -> used exclusively in my company's applications) using fstream library in C++. The file is created with an app developed by someone else in my company who is using Delphi. He says the first 15 bytes should be some characters which indicate the date the file was created and some other stuff like version of the app:

"XXXX 2012".

The result after loading with fstream (in binary mode) and writing another file with fstream (string mode) is as follows:

"[] X X X X 2 0 1 2"

The first char is an unknown char (rectangle) then there are spaces between each char. Finally it is 31 bytes wide. 15 for actual chars + 15 for white spaces + 1 for the rect char = 31.

Some other information: I'm using C++, the app developer is using Delphi. Im using fstream. he is using BW.Write() function. (BW == Binary Writer?) He uses Windows 7 whilst i use Windows XP Professional.

Can you make a diagnosis of the problem?

Thanks in advance

First Edit: I'm adding c++ code that loads those first bytes.

Firstly he is using Delphi XE2 from embarcadero Rad Studio XE2.

From what i know PChar is a null-terminated string consisting of widechars (since delphi 2009) which are 2 bytes wide as opposed to normal chars (one byte). So basically he's saving words instead of bytes.

here is the code loading the mgr:

wchar_t header[15];
DXFLIBRARY_API void loadMGR(const char* szFileName, const char* szOutput)
{
fstream file;
file.open( szFileName, ios::binary | ios::in );
if(file.is_open()) 
{
    file.read(reinterpret_cast<char*>(header),sizeof(header));
}
file.close();

//zapis

fstream saveFile;
saveFile.open( szOutput, ios::out );
if(saveFile.is_open())
{
    saveFile.write(reinterpret_cast<const char*>(header),sizeof(header));
}
saveFile.close(); 
}

Header contains 15 wchar_t's so we get 30 bytes. Still after investigating i have no idea how to convert.

4

1 回答 1

5

似乎很清楚,数据在 8 位文本编码和 16 位编码之间被破坏的过程中的某个地方。虚假的第一个字符几乎可以肯定是 UTF-16 BOM。

一种可能的解释是 Delphi 开发人员正在将 UTF-16 编码文本写入文件。并且大概您期望 8 位编码。

另一种解释是 Delphi 代码正确地写出 8 位文本,但是您的代码正在修改它。也许您的读/写代码正在这样做。

在 Delphi 程序的文件输出上使用十六进制编辑器来缩小发生重整的确切位置。

在问题中没有任何代码的情况下,很难比这更具体。

于 2012-10-18T14:29:22.680 回答