Errors in code
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 3 123 LastLast
Results 1 to 15 of 35

Thread: Errors in code

  1. #1
    Join Date
    May 2014
    Posts
    149

    Errors in code

    Hi, can you help me to fix these errors in code?

    Please see post #7 http://forums.codeguru.com/showthrea...11#post2154011

    I cannot run the function GdipCreateBitmapFromHBITMAP because of error
    error C3861: 'GdipCreateBitmapFromHBITMAP': identifier not found

    Code is in post #7 http://forums.codeguru.com/showthrea...11#post2154011
    Last edited by crazy boy; May 3rd, 2014 at 04:04 PM.

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,228

    Re: Errors in code

    if (!PrintWindow(HCapture, HDC, PW_CLIENTONLY)) return 2;

    You're using the type as an argument instead of an instance of it. I would imagine you meant to pass device instead.

  3. #3
    Join Date
    May 2014
    Posts
    149

    Re: Errors in code

    Oh, I confuse this still often. Thanks. And this one:
    Code:
    HBitmap = GdipCreateBitmapFromHBITMAP(HBitmap, 0, pBitmap);
    error C3861: 'GdipCreateBitmapFromHBITMAP': identifier not found
    Is it because I miss include of GDI plus?

    My headers:
    Code:
    #include "targetver.h"
    #include <stdio.h>
    #include <tchar.h>
    #include <windows.h>
    #include <fstream>
    #include <stdio.h>
    #include <wingdi.h>
    #include <ostream>
    After
    #include <gdiplus.h>
    still the same error
    Last edited by crazy boy; May 3rd, 2014 at 10:19 AM.

  4. #4
    Join Date
    May 2014
    Posts
    149

    Re: Errors in code

    I also get 'GdiPlus' : is not a class or namespace name
    if I try to access the function through GdiPlus::, if I try define namespace, it occurs same error

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,479

    Re: Errors in code

    What is HBitmap? Is it a type? Or a variable?

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,605

    Re: Errors in code

    Quote Originally Posted by crazy boy View Post
    I also get 'GdiPlus' : is not a class or namespace name
    if I try to access the function through GdiPlus::, if I try define namespace, it occurs same error
    And how does now your code look like?
    Victor Nijegorodov

  7. #7
    Join Date
    May 2014
    Posts
    149

    Re: Errors in code

    Quote Originally Posted by Arjay View Post
    What is HBitmap? Is it a type? Or a variable?
    Code:
    HBITMAP HBitmap = 0;
    This should not be problem. My problem is I really cannot find out why the function GdipCreateBitmapFromHBITMAP is to be undefined identifier - the error report say "identifier not found".

    But I have included GDI and GDIPlus. When I try use namespace it also says the same error report for these commands:
    using namespace Gdiplus;
    or
    using namespace GdiPlus;

    Here I give complete code:

    stdafx.h
    Code:
    #pragma once
    #include "targetver.h"
    #include <stdio.h>
    #include <tchar.h>
    #include <windows.h>
    #include <fstream>
    #include <stdio.h>
    #include <wingdi.h>
    // GDI Plus
    #include <gdiplus.h>
    #include <Gdiplusflat.h> // Gdiplusflat.h // do I need it?
    #include <ostream>
    capture.cpp
    Code:
    /*Window capture example*/
    //using namespace Gdiplus;
    //using namespace GdiPlus; 
    
    #include "stdafx.h"
    #define SCREENWIDTH GetSystemMetrics(SM_CXSCREEN)
    #define SCREENHEIGHT GetSystemMetrics(SM_CYSCREEN)
    
    // HBITMAP g_hDeskBmp;
    HDC g_hMemDC;
    int g_nDCdata;
    
    int main()
    {
     // get desktop window handle (but can be handle of any window)
     HWND HCapture = FindWindow(NULL, _T("Map Viewer") );
    //	HWND HCapture = GetDesktopWindow();
     if(!IsWindow(HCapture)) return 1;
    
    /*
     BOOL PrintWindow(
      HWND hwnd, // A handle to the window that will be copied.
      HDC hdcBlt, // A handle to the device context.
      UINT nFlags // The drawing options: PW_CLIENTONLY
                            //     Only the client area of the window is copied to hdcBlt. By default, the entire window is copied.
    );
    */
    
     // get window dimensions
     RECT rect;
     GetWindowRect(HCapture, &rect);
    
     size_t dx = rect.right - rect.left;
     size_t dy = rect.bottom - rect.top;
    
     // create BITMAPINFO structure
     // used by CreateDIBSection
     BITMAPINFO info;
     info.bmiHeader.biSize          = sizeof(BITMAPINFOHEADER);
     info.bmiHeader.biWidth         = dx;
     info.bmiHeader.biHeight        = dy;
     info.bmiHeader.biPlanes        = 1;
     info.bmiHeader.biBitCount      = 24;
     info.bmiHeader.biCompression   = BI_RGB;
     info.bmiHeader.biSizeImage     = 0;
     info.bmiHeader.biXPelsPerMeter = 0;
     info.bmiHeader.biYPelsPerMeter = 0;
     info.bmiHeader.biClrUsed       = 0;
     info.bmiHeader.biClrImportant  = 0;
    
     // a bitmap handle and a pointer its bit data
     HBITMAP HBitmap = 0;
     BYTE*   memory = 0;
    
     /** We should create Bitmap first and then Device Context,
         however when I want to create snapshot of window, I need to use
    	 fnc PrintWindow to copy the visual window to Device Context.
    	 So I need to create DC first. The DC will be compatible with
    	 current screen.
     */
     
     // 1. FIRST we need to Create DC for PrintWindow function
     // HDC device = GetDC(HCapture);
     HDC device = CreateCompatibleDC(NULL);
     
     // 2. SECOND we need to CREATE BITMAP (Device Independent Bitmap)
     // bitmap = CreateDIBSection(device, &info, DIB_RGB_COLORS, (void**)&memory, 0, 0);
     unsigned int * pBitmap;
    
     if (!PrintWindow(HCapture, device, PW_CLIENTONLY)) return 2;
     HBitmap = GdipCreateBitmapFromHBITMAP(HBitmap, 0, pBitmap);
     ReleaseDC(HCapture, device);
     if(!HBitmap || !memory) return 1;
    
     // blit the contents of the desktop (winDC)
     // to the bitmap (selected in memDC)
     HDC winDC = GetWindowDC(HCapture);
     HDC memDC = CreateCompatibleDC(winDC);
     SelectObject(memDC, HBitmap);
     BitBlt(memDC, 0, 0, dx, dy, winDC, 0, 0, SRCCOPY);
     DeleteDC(memDC);
     ReleaseDC(HCapture, winDC);
    
     /** THIS IS WRONG! VARIABLE CANNOT POINT TO NOWHERE!*/
     // char *buffer; // First set the type and range and then make pointer:
      char *buffer = new char[50]; // RIGHT DECLARATION
     sprintf(buffer,"capture%d%d.bmp",dx,dy);
     // create bitmap file
     std::basic_ofstream <char> file(buffer, std::ios::binary);
     if(!file) { DeleteObject(HBitmap); return 1; }
    
     // initialize bitmap file headers
     BITMAPFILEHEADER fileHeader;
     BITMAPINFOHEADER infoHeader;
    
     fileHeader.bfType      = 0x4d42;
     fileHeader.bfSize      = 0;
     fileHeader.bfReserved1 = 0;
     fileHeader.bfReserved2 = 0;
     fileHeader.bfOffBits   = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
    
     infoHeader.biSize          = sizeof(infoHeader);
     infoHeader.biWidth         = dx;
     infoHeader.biHeight        = dy;
     infoHeader.biPlanes        = 1;
     infoHeader.biBitCount      = 24;
     infoHeader.biCompression   = BI_RGB;
     infoHeader.biSizeImage     = 0;
     infoHeader.biXPelsPerMeter = 0;
     infoHeader.biYPelsPerMeter = 0;
     infoHeader.biClrUsed       = 0;
     infoHeader.biClrImportant  = 0;
    
     // save file headers
     file.write((char*)&fileHeader, sizeof(fileHeader));
     file.write((char*)&infoHeader, sizeof(infoHeader));
    
     // save 24-bit bitmap data
     int wbytes = (((24*dx + 31) & (~31))/8);
     int tbytes = (((24*dx + 31) & (~31))/8)*dy;
     file.write((char*)memory, tbytes);
     // delete bitmap
     DeleteObject(HBitmap);
     HBitmap = 0;
     memory = 0;
    return 0;
    //......................................................................................
    }
    capture.cpp(71): error C3861: 'GdipCreateBitmapFromHBITMAP': identifier not found

    I try to find the solution for hours.
    Last edited by crazy boy; May 3rd, 2014 at 03:56 PM.

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,605

    Re: Errors in code

    Quote Originally Posted by crazy boy View Post
    ...
    Here I give complete code:

    Code:
    #pragma once
    #include "targetver.h"
    #include <stdio.h>
    #include <tchar.h>
    #include <windows.h>
    #include <fstream>
    #include <stdio.h>
    #include <wingdi.h>
    // GDI Plus
    #include <gdiplus.h>
    #include <Gdiplusflat.h> // Gdiplusflat.h // do I need it?
    #include <ostream>
    And where is this code? In what file?
    Victor Nijegorodov

  9. #9
    Join Date
    May 2014
    Posts
    149

    Re: Errors in code

    Quote Originally Posted by VictorN View Post
    And where is this code? In what file?
    The first code is header.

    The second code is cpp, and here it is on this line:

    HBitmap = GdipCreateBitmapFromHBITMAP(HBitmap, 0, pBitmap);

  10. #10
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,847

    Re: Errors in code

    GdipCreateBitmapFromHBITMAP() should be defined in some file. It's just a question of finding which one. I would do a search of the include folders for any file that contains this text. Once you find it, you should know which header file to include and inspection of the file should reveal some info about any namespace requirements.

    The other aspect to this is that once you get the code to compile you will need to know which libraries to include for the linker.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  11. #11
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,605

    Re: Errors in code

    Quote Originally Posted by crazy boy View Post
    The first code is header.
    And will you be so kind to explain us how your cpp uses (includes) this header file?
    Victor Nijegorodov

  12. #12
    Join Date
    May 2014
    Posts
    149

    Re: Errors in code

    Contains this code:

    Code:
    #include <Gdiplusflat.h>
    Is included by header not by cpp. I believe that when it is in header, so I need not to add it to cpp

    That is GDI+ Flat api to work with bitmaps. These lines I have found in #include <Gdiplusflat.h>
    Code:
    GdipCreateBitmapFromHBITMAP(HBITMAP hbm,
                                HPALETTE hpal,
                                GpBitmap** bitmap);

  13. #13
    Join Date
    May 2014
    Posts
    149

    Re: Errors in code

    I have found this:

    GdiPlusBitmap.h
    Code:
    inline 
    Bitmap::Bitmap(
        IN HBITMAP hbm, 
        IN HPALETTE hpal
        )
    {
        GpBitmap *bitmap = NULL;
    
        lastResult = DllExports::GdipCreateBitmapFromHBITMAP(hbm, hpal, &bitmap);
    
        SetNativeImage(bitmap);
    }
    I have no idea how to look in the folder \Microsoft SDKs\Windows\v7.0A\Include by Visual C++. I can only search in project files

  14. #14
    Join Date
    May 2014
    Posts
    149

    Re: Errors in code

    I see that GdipPlusBitmap.h exports the function to dll. But I see no definition of the function :-( I cannot find the file.

  15. #15
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,847

    Re: Errors in code

    Is included by header not by cpp. I believe that when it is in header, so I need not to add it to cpp
    Which header? From your post #7, the cpp only includes stdafx.h. What does stdafx.h contain?

    Are any namespaces defined?
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Page 1 of 3 123 LastLast

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center