-
Metafiles
Hey,
I have the following code.
Code:
#include <stdio.h>
#include <iostream.h>
#include "resource.h"
short ReadMetaInt( istream& is, UINT& ints_read);
int Metas[1] = {JVEST01C};
HRSRC reshandle;
HMODULE hexe;
HGLOBAL hglobal;
int main()
{
printf("1st element: %d\n", Metas[0]);
hexe = GetModuleHandle(NULL);
reshandle = FindResource(hexe, MAKEINTRESOURCE(Metas[0]), "Metafile");
if (reshandle == NULL)
printf("Did not find resource.\n");
else
printf("reshandle: %d\n", reshandle);
hglobal = LoadResource(hexe, reshandle);
if (hglobal == NULL)
printf("Did not load resource\n");
else
printf("hglobal: %d\n", hglobal);
//istream* metastream = (istream*) LockResource(hglobal);
istream *metastream = (istream*) LockResource(hglobal);
if (metastream == NULL)
printf("could not lock resource\n");
UINT ints_read = 0;
int blah = ReadMetaInt(*metastream, ints_read);
cout << blah;
system("PAUSE");
return 100;
}
// ---------------------------------------------------------------------------------------------
// Read an integer from metafile.
short ReadMetaInt( istream& is, UINT& ints_read )
{
unsigned char c1, c2;
is.get( c1 );
is.get( c2 );
ints_read++;
return( c1 + ( c2 << 8 ) );
} // ReadMetaInt
I basically have to open a metafile which is stored as a resource. I have to pass it into the ReadMetaInt function as istream. This used to open the metafile from a physical file on teh hard drive. I want to be able to open them as resources and then pass them into that function.
Right now, I get errors on the is.get(c1) line.
-
Re: Metafiles
You cannot just cast a pointer to a memory area filled more or less with random values to a pointer to a class object and expect it to work. This is not what I meant with writing a streambuffer.
May I recommend the book "Standard C++ IOStreams and Locales" by Langer and Kreft to you?
-
Re: Metafiles
you most certainly can. :)
I really like C++ but man is it a big change from VB.
I guess I should have learned C first, then VB. he he
Any tutorials online that any of you guys know about?
Thanks,
-
Re: Metafiles
Well, I'm writing one, but it's been stalled for a long time, and what's there I think you already know.
See top of the forum.