CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Threaded View

  1. #1
    Join Date
    Mar 2007
    Posts
    22

    Program crashes, oleaut32.dll fault.

    So heres the code. Just a simple test to load a JPG file and bitblt it to the screen, no errors, program just crashes. I am using the LoadAnImage function found here
    http://www.codeguru.com/cpp/g-m/bitm...cle.php/c4935/ . I am almost certain that it is the way I am using the LoadAnImage func that is causing the problem but I don't know how else it would be done.

    Code:
    #include <cstdlib>
    #include <iostream>
    #include <olectl.h> 
    #include <ole2.h> 
    
    /*
    ../../Dev-Cpp/lib/libgdi32.a
    ../../Dev-Cpp/lib/libuser32.a
    ../../Dev-Cpp/lib/libolepro32.a
    ../../Dev-Cpp/lib/libuuid.a
    ../../Dev-Cpp/lib/liboleaut32.a
    */
    
    
    using namespace std;
    
    HBITMAP LoadAnImage(char* FileName)
       {
       // Use IPicture stuff to use JPG / GIF files
       IPicture* p;
       IStream* s;
       IPersistStream* ps;
       HGLOBAL hG;
       void* pp;
       FILE* fp;
    
    
       // Read file in memory
       fp = fopen(FileName,"rb");
       if (!fp)
       return NULL;
    
       fseek(fp,0,SEEK_END);
       int fs = ftell(fp);
       fseek(fp,0,SEEK_SET);
       hG = GlobalAlloc(GPTR,fs);
       if (!hG)
          {
          fclose(fp);
          return NULL;
          }
       pp = (void*)hG;
       fread(pp,1,fs,fp);
       fclose(fp);
    
       // Create an IStream so IPicture can
       // CreateStreamOnHGlobal(hG,false,&s);
       if (!s)
          {
          GlobalFree(hG);
          return NULL;
          }
    
       OleLoadPicture(s,0,false,IID_IPicture,(void**)&p);
    
       if (!p)
          {
          s->Release();
          GlobalFree(hG);
          return NULL;
          }
       s->Release();
       GlobalFree(hG);
    
       HBITMAP hB = 0;
       p->get_Handle((unsigned int*)&hB);
    
       // Copy the image. Necessary, because upon p's release,
       // the handle is destroyed.
       HBITMAP hBB = (HBITMAP)CopyImage(hB,IMAGE_BITMAP,0,0,
                                        LR_COPYRETURNORG);
    
       p->Release();
       return hBB;
       }
    
    
    int main(int argc, char *argv[])
    {
        HBITMAP newimage = LoadAnImage("omg.jpg");
        HDC dcmem;
        SelectObject(dcmem, newimage);
        BitBlt(GetDC(0),0,0,500,500,dcmem,0,0,SRCPAINT); 
        DeleteDC(dcmem);
        DeleteObject(newimage);
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    I am using Dev-C++ if that matters.
    Last edited by pirateninja; March 24th, 2007 at 10:06 PM.

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

Featured