Solved

linking gdi

Posted on 2007-12-04
6
391 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 500 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 how to clear a vector as well as how to detect empty vectors in C++.

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now