Issue reading WMF header

25 views
Skip to first unread message

deostroll

unread,
May 7, 2010, 2:47:54 AM5/7/10
to
I am not sure if I am doing this correctly. I am trying to read the
header information of a wmf file. But however I do it I end up with
incorrect data. But, how do I know its incorrect?!! I've copied the
structure definitions for the header from here:

http://www.fileformat.info/format/wmf/egff.htm

They specifically mention that the HeaderSize field should have the
value 9. But while I try reading it I am getting some other value.
Don't know why it is so. Similarly all the other fields are
inconsistent with respect to the documentation mentioned in the web
page. Here is the code I've used.
<code>
CFile file;
CFileException fexp;
cout << "Opening file...\n";
//char* filepath = "C:\\Program Files\\Microsoft Office\\Office12\
\BITMAPS\\STYLES\\GLOBE.WMF";

if( !file.Open( _T("C:\\Program Files\\Microsoft Office\\Office12\
\BITMAPS\\STYLES\\GLOBE.WMF"), CFile::modeRead, &fexp) )
{
fexp.ReportError();
return 1;
}
cout << "Reading information...\n" ;
WMFHEAD* head = new _WindowsMetaHeader;

//reading 18 bytes
file.Read((void*) head, 18);
cout << "head->FileType : " << head->FileType << '\n' <<
"head->HeaderSize : " << head->HeaderSize << '\n' <<
"head->Version : " << head->Version << '\n' <<
"head->FileSize : " << head->FileSize << '\n' <<
"head->NumOfObjects : " << head->NumOfObjects << '\n' <<
"head->MaxRecordSize : " << head->MaxRecordSize << '\n' <<
"head->NoParameters : " << head->NoParameters << '\n';


delete head;
cout <<"Closing file...\n";
file.Close();
</code>

Hope someone can guide me on this...

--deostroll

John H.

unread,
May 7, 2010, 11:37:14 AM5/7/10
to
deostroll wrote:
> I am not sure if I am doing this correctly. I am trying to read the
> header information of a wmf file. But however I do it I end up with
> incorrect data.

Could it be that your wmf file has a portability header prepended?
See the "Porting WMF Files Between Applications" of your link for more
info.

deostroll

unread,
May 11, 2010, 4:41:35 AM5/11/10
to
> Could it be that your wmf file has a portability header prepended?
> See the "Porting WMF Files Between Applications" of your link for more
> info.
Yes, there was a portability header prepended. I'm still a little
doubtful of the values printed onto my screen. Plus, I have the doubt
'what comes next'? So after this portability header is read, should I
expect a WMFRECORD or the actual WMFHEADER?

Here is what I got as output:

pmh->Key = 2596720087
pmh->Handle = 0
pmh->Left = -1458
pmh->Top = -666
pmh->Right = 1458
pmh->Bottom = 1344
pmh->Inch = 576
pmh->Reserved = 0
pmh->Checksum = 21131

Not sure if pmh->Left and pmh->Right are showing the correct values?

--deostroll

John H.

unread,
May 11, 2010, 12:46:14 PM5/11/10
to
deostroll wrote:
> I'm still a little
> doubtful of the values printed onto my screen.
>
> Here is what I got as output:
>
> pmh->Key = 2596720087
> pmh->Handle = 0
> pmh->Left = -1458
> pmh->Top = -666
> pmh->Right = 1458
> pmh->Bottom = 1344
> pmh->Inch = 576
> pmh->Reserved = 0
> pmh->Checksum = 21131
>
> Not sure if pmh->Left and pmh->Right are showing the correct values?

Well Key, Handle, and Reserved are the exact values they should be, so
that makes me think you are reading it ok. Inch looks reasonable.
The Checksum is correct for the values listed. As for left, top,
right, bottom... not really sure.

> Plus, I have the doubt
> 'what comes next'? So after this portability header is read, should I
> expect a WMFRECORD or the actual WMFHEADER?

I suspect WMFHEADER is next.

deostroll

unread,
May 12, 2010, 12:23:18 AM5/12/10
to
> The Checksum is correct for the values listed.
How was this verified?

--deostroll

John H.

unread,
May 12, 2010, 12:58:08 PM5/12/10
to
deostroll wrote:
> > The Checksum is correct for the values listed.
> How was this verified?

The process is described in your link. Checksum contains a checksum
value for the previous 10 WORDs in the header, calculated by XORing
each WORD value to 0. i.e.
WORD checksum = 0;
checksum ^= 2596720087;
checksum ^= 0;
checksum ^= -1458;
etc.

John H.

unread,
May 12, 2010, 2:10:02 PM5/12/10
to
John H. wrote:
> The process is described in your link. Checksum contains a checksum
> value for the previous 10 WORDs in the header, calculated by XORing
> each WORD value to 0. i.e.
> WORD checksum = 0;
> checksum ^= 2596720087;
> checksum ^= 0;
> checksum ^= -1458;
> etc.

More precisely:

#include <iostream>
int main()
{
unsigned short s = 0u;
s ^= 2596720087L & 0x0000FFFFL;
s ^= (2596720087L & 0xFFFF0000L) >> 16;
s ^= 0;
s ^= -1458;
s ^= -666;
s ^= 1458;
s ^= 1344;
s ^= 576;
s ^= 0;
std::cout << s << std::endl;
return 0;
}

Reply all
Reply to author
Forward
0 new messages