?
Solved

linking gdi

Posted on 2007-12-04
6
Medium Priority
?
406 Views
Last Modified: 2012-06-21
this pops

C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp/ccaAbaaa.o:hdc.cpp:(.text+0x39a): undefined reference to `CreateDIBSection@24'
collect2: ld returned 1 exit status



when I try to compile this, and it's been suggested that the way to solving it is to

"You need to link with gdi32.lib - I thin, with MinGW, that is libgdi32.a"



how do I do that?








#include <sstream>
#include <windows.h>
#include <iostream>
#include <vector>
#include <string.h>
#include <stdio.h>

using namespace std;


// save window and hdc hdc return are the same color?
// do they have the same picture?
// ie, what

void SaveWindow(HWND hwnd, const char* pName);
void savewindow ( HWND hwnd1, string string1 );
// save the window given hwnd


int main ()
{
     
     
     
     
     
      return 0;
}



void savewindow ( HWND hwnd1, string string1 )
{
      stringstream ss;
      ss << string1 << ".bmp";
      SaveWindow( hwnd1, ss.str().c_str());
}
     
     
void SaveWindow(HWND hwnd, const char* pName)
{
        BYTE* pDrawingSurfaceBits;
        RECT rc;
        HDC hDC = GetDC(hwnd);
        BITMAPINFOHEADER BMIH;

        GetWindowRect(hwnd,&rc);

        BMIH.biSize = sizeof(BITMAPINFOHEADER);
        BMIH.biBitCount = 24;
        BMIH.biPlanes = 1;
        BMIH.biCompression = BI_RGB;
        BMIH.biWidth = rc.right - rc.left;
        BMIH.biHeight = rc.bottom - rc.top;
        BMIH.biSizeImage = ((((BMIH.biWidth * BMIH.biBitCount)
                           + 31) & ~31) >> 3) * BMIH.biHeight;
        HBITMAP hDrawingSurface = CreateDIBSection(hDC,
                 (CONST BITMAPINFO*)&BMIH, DIB_RGB_COLORS,
                 (void**)&pDrawingSurfaceBits, NULL, 0);
        ReleaseDC(hwnd,hDC);

       
        //Create a new file for writing
        FILE *pFile = fopen(pName, "wb");
        if(pFile == NULL)
        {
            MessageBox(NULL,"Cannot open file","Error",MB_OK);
            return;
        }
        BITMAPFILEHEADER bmfh;
        int nBitsOffset = sizeof(BITMAPFILEHEADER) + BMIH.biSize;
        LONG lImageSize = BMIH.biSizeImage;
        LONG lFileSize = nBitsOffset + lImageSize;
        bmfh.bfType = 'B'+('M'<<8);
        bmfh.bfOffBits = nBitsOffset;
        bmfh.bfSize = lFileSize;
        bmfh.bfReserved1 = bmfh.bfReserved2 = 0;
        //Write the bitmap file header
        UINT nWrittenFileHeaderSize = fwrite(&bmfh, 1,
                     sizeof(BITMAPFILEHEADER), pFile);
        //And then the bitmap info header
        UINT nWrittenInfoHeaderSize = fwrite(&BMIH,
               1, sizeof(BITMAPINFOHEADER), pFile);
        //Finally, write the image data itself
        //-- the data represents our drawing
        UINT nWrittenDIBDataSize =
             fwrite(pDrawingSurfaceBits, 1, lImageSize, pFile);

        fclose(pFile);
}
0
Comment
Question by:Troudeloup
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 20408710
As I wrote in your other Q, under MinGW, that probably is name libgdi32.a, or

g++ mycode.cpp -lgdi32
0
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 20408718
BTW, the '-lgdi32' is not a typo, it follows the GCC naming conventions: libs are created as 'libmycode.a' and referred to as '-lmycode' when building.
0
 

Author Comment

by:Troudeloup
ID: 20408719
so for this specific compile, I need to add -lgdi32    ?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:jkr
ID: 20408723
Yup, give that a try...
0
 

Author Comment

by:Troudeloup
ID: 20408752
yes it works :)
0
 

Author Comment

by:Troudeloup
ID: 20408755
however, it's black alright.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question