Results 1 to 4 of 4

Thread: Metafiles

  1. #1

    Thread Starter
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950

    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.
    Don't anthropomorphize computers -- they hate it

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    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?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950

    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,
    Don't anthropomorphize computers -- they hate it

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    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.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width