Board index » cppbuilder » Why SetEnhMetaFileBits always fail?

Why SetEnhMetaFileBits always fail?


2004-10-27 06:52:08 PM
cppbuilder114
Hi,
In a project, I want to insert a picture into the F1book.
Here is my code:
1 TMemoryStream* wmfStream = new TMemoryStream();
2 wmfStream->LoadFromFile("c:\\tmpwmf.wmf");
3 int size = wmfStream->Size;
4 wmfStream->Position = 0;
5 char* buffer = new char[size];
6 wmfStream->Read((void*)buffer, size);
7 HENHMETAFILE hMf = ::SetEnhMetaFileBits(size, buffer);
8 F1Book1->ObjCreatePicture(col, row, col, row, (unsigned int)hMf, 7,
width, height);
The result of SetEnhMetaFileBits is always NULL. But the wmf file is not
corrupt.
And what is the type of HENHMETAFILE?
BCB tells me that it's "void*"! I think it's not reasonable.
Thanks in advance.
bucher
 
 

Re:Why SetEnhMetaFileBits always fail?

"bucher" < XXXX@XXXXX.COM >wrote in message
Quote
7 HENHMETAFILE hMf = ::SetEnhMetaFileBits(size, buffer);
That won't work. The buffer you supply to SetEnhMetaFileBits() must have
been obtained by calling GetEnhMetaFileBits(). You are currently not doing
that. Use GetEnhMetaFile() before you can call GetEnhMetaFileBits().
Better yet, don't load the meta data manually at all. Use the VCL's
TMetafile class instead. It does all of the work for you, ie:
TMetafile *mf = new TMetafile;
try
{
mf->LoadFromFile("c:\\tmpwmf.wmf");
F1Book1->ObjCreatePicture(col, row, col, row, mf->Handle, 7, width,
height);
}
__finally {
delete mf;
}
Quote
The result of SetEnhMetaFileBits is always NULL.
That is because you did not prepare the buffered data correctly.
Quote
And what is the type of HENHMETAFILE?
BCB tells me that it's "void*"!
All Win32 API handles are void*.
Gambit