?
Solved

linking gdi

Posted on 2007-12-04
6
Medium Priority
?
412 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
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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 use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

862 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