BITMAP HdcToBitmap(HDC hdcNeedle, int needleWidth, int needleHeight)
{
HDC memDC_Needle = CreateCompatibleDC(hdcNeedle);
HBITMAP memBM_Needle = CreateCompatibleBitmap(hdcNeedle, needleWidth, needleHeight);
SelectObject(memDC_Needle, memBM_Needle);
BitBlt(memDC_Needle, 0, 0, needleWidth, needleHeight, hdcNeedle, 0, 0, SRCCOPY);
BITMAP bmpNeedle;
GetObject(memBM_Needle, sizeof(BITMAP), &bmpNeedle);
return bmpNeedle;
}

strange error :-S
Bader Cheema
woops it's a HBITMAP i want to return
HBITMAP HdcToBitmap(HDC hdcNeedle, int needleWidth, int needleHeight)
{
HDC memDC_Needle = CreateCompatibleDC(hdcNeedle);
HBITMAP memBM_Needle = CreateCompatibleBitmap(hdcNeedle, needleWidth, needleHeight);
SelectObject(memDC_Needle, memBM_Needle);
BitBlt(memDC_Needle, 0, 0, needleWidth, needleHeight, hdcNeedle, 0, 0, SRCCOPY);
BITMAP bmpNeedle;
GetObject(memBM_Needle, sizeof(BITMAP), &bmpNeedle);
return memBM_Needle;
DeleteDC(memDC_Needle);
DeleteObject(memBM_Needle);
}
Qiuwei
visual ryan
What sort of project are you creating What IDE are you using
DevilDog74
HBITMAP HdcToBitmap(HDC hdcNeedle, int needleWidth, int needleHeight)
{
HDC memDC_Needle = CreateCompatibleDC(hdcNeedle);
HBITMAP memBM_Needle = CreateCompatibleBitmap(hdcNeedle, needleWidth, needleHeight);
HBITMAP bmOld = SelectObject(memDC_Needle, memBM_Needle);
BitBlt(memDC_Needle, 0, 0, needleWidth, needleHeight, hdcNeedle, 0, 0, SRCCOPY);
SelectObject(memDC_Needle, bmOld);
DeleteDC(memDC_Needle);
return memBM_Needle;
}
Try that then. So you always want your copied bitmap to be from the top left
Are you using the Express Edition Just wondering why you're not using the MFC wrappers for GDI objects
ReLoad
The first error is strange. Note how it talks about __cdecl GetObject trying to reference __stdcall GetObjectW. In the windows headers, choosing between Unicode and ANSI versions of the API is done by a macro, not a function.
Yet another thing that's strange is that the function declarations are 'extern "C"' but the linker shows the mangled C++ names. Not sure about that...
All and all, I would guess that he's running Express and came up with his own versions of the Windows APIs !
Joe Buys
There are some questions that remain - where are you getting these APIs from What sort of project did you create What IDE are you using As nobugz said, the errors you're getting make no sense, they appear to be errors in the calling convention of the APIs.
Beth31
That's very possible, I definately see layers of confusion here, not least the misconception that a BITMAP struct contains a bitmap ( at least, that's how I read it ).
RamiEmad
There's one more step to stop all leaks :
private Bitmap HdcToBitmap(IntPtr hdcJava, int width, int height)
{
IntPtr hdcBuffer = CreateCompatibleDC(hdcJava);
IntPtr hBitmap = CreateCompatibleBitmap(hdcJava, width, height);
IntPtr hOld = SelectObject(hdcBuffer, hBitmap);
BitBlt(hdcBuffer, 0, 0, width, height, hdcJava, 0, 0, 0x00CC0020);
Bitmap bJava = Bitmap.FromHbitmap(hBitmap);
SelectObject(hdcBuffer, hOld);
DeleteDC(hdcBuffer);
DeleteObject(hBitmap);
return bJava;
}
Also, a Bitmap in C# is very different to a BITMAP in C++. A CBitmap would be closer to a Bitmap. A BITMAP is just a struct with some info about a bitmap in it.
Like I said, you need to like to gdi32.lib, but the fact that you're not probably means you need to create a Windows project to start with, there are other setting that will be wrong because you've created a console app.
OliWarner
OK, well, that will sort of work, but because you're using a DDB, the colors will depend on the bit depth of your screen, and not just the image itself. But if you're in 24 bit, that won't matter.
FlyinBrian
i want to make a HBITMAP out of a selected window for GetBitmapBits
so i can find colors in a game called runescape(macro)
g-spot-web
These are all linker errors, which means you have all the correct headers in your project, but you're not linking to the libraries that contain the actual methods. There is nothing wrong with your code ( assuming that you intend the resource leak of memBM_Needle), but you're not linking to Gdi32.lib, which makes me think that you've created a console app and added Windows.h to it. If you create a windows app to start with, then all these settings will be correct for you. The other option I guess is if you've added some libs to your project, you may have deleted some by accident.
Also, what do you need the BITMAP for You already know the width and height, and unless your bitmap was created as a DIBSECTION, you won't get a pointer to the underlying bits, nor will you get proper bit depth info ( it will be the bit depth of the screen ). I don't know if createcompatiblebitmap will create a dibsection from a dibsection.
Jagan P
Error 2 error LNK2028: unresolved token (0A000010) "extern "C" int __stdcall DeleteObject(void *)" ( DeleteObject@@$$J14YGHPAX@Z) referenced in function "private: int __clrcall Testexer::Form1::FindBitmapAt(struct HDC__ *,int,int,struct HDC__ *,int,int,int,int)" ( FindBitmapAt@Form1@Testexer@@$$FA$AAMHPAUHDC__@@HH0HHHH@Z) Testexer.obj
Error 3 error LNK2028: unresolved token (0A000011) "extern "C" int __stdcall DeleteDC(struct HDC__ *)" ( DeleteDC@@$$J14YGHPAUHDC__@@@Z) referenced in function "private: int __clrcall Testexer::Form1::FindBitmapAt(struct HDC__ *,int,int,struct HDC__ *,int,int,int,int)" ( FindBitmapAt@Form1@Testexer@@$$FA$AAMHPAUHDC__@@HH0HHHH@Z) Testexer.obj
Error 4 error LNK2028: unresolved token (0A000012) "extern "C" long __stdcall GetBitmapBits(struct HBITMAP__ *,long,void *)" ( GetBitmapBits@@$$J212YGJPAUHBITMAP__@@JPAX@Z) referenced in function "private: int __clrcall Testexer::Form1::FindBitmapAt(struct HDC__ *,int,int,struct HDC__ *,int,int,int,int)" ( FindBitmapAt@Form1@Testexer@@$$FA$AAMHPAUHDC__@@HH0HHHH@Z) Testexer.obj
Error 5 error LNK2028: unresolved token (0A000015) "extern "C" int __stdcall GetObjectW(void *,int,void *)" ( GetObjectW@@$$J212YGHPAXH0@Z) referenced in function "extern "C" int __cdecl GetObject(void *,int,void *)" ( GetObject@@$$J0YAHPAXH0@Z) Testexer.obj
Error 6 error LNK2028: unresolved token (0A000016) "extern "C" int __stdcall BitBlt(struct HDC__ *,int,int,int,int,struct HDC__ *,int,int,unsigned long)" ( BitBlt@@$$J236YGHPAUHDC__@@HHHH0HHK@Z) referenced in function "private: int __clrcall Testexer::Form1::FindBitmapAt(struct HDC__ *,int,int,struct HDC__ *,int,int,int,int)" ( FindBitmapAt@Form1@Testexer@@$$FA$AAMHPAUHDC__@@HH0HHHH@Z) Testexer.obj
Error 7 error LNK2028: unresolved token (0A000017) "extern "C" void * __stdcall SelectObject(struct HDC__ *,void *)" ( SelectObject@@$$J18YGPAXPAUHDC__@@PAX@Z) referenced in function "private: int __clrcall Testexer::Form1::FindBitmapAt(struct HDC__ *,int,int,struct HDC__ *,int,int,int,int)" ( FindBitmapAt@Form1@Testexer@@$$FA$AAMHPAUHDC__@@HH0HHHH@Z) Testexer.obj
Error 8 error LNK2028: unresolved token (0A000018) "extern "C" struct HBITMAP__ * __stdcall CreateCompatibleBitmap(struct HDC__ *,int,int)" ( CreateCompatibleBitmap@@$$J212YGPAUHBITMAP__@@PAUHDC__@@HH@Z) referenced in function "private: int __clrcall Testexer::Form1::FindBitmapAt(struct HDC__ *,int,int,struct HDC__ *,int,int,int,int)" ( FindBitmapAt@Form1@Testexer@@$$FA$AAMHPAUHDC__@@HH0HHHH@Z) Testexer.obj
Error 9 error LNK2028: unresolved token (0A000019) "extern "C" struct HDC__ * __stdcall CreateCompatibleDC(struct HDC__ *)" ( CreateCompatibleDC@@$$J14YGPAUHDC__@@PAU1@@Z) referenced in function "private: int __clrcall Testexer::Form1::FindBitmapAt(struct HDC__ *,int,int,struct HDC__ *,int,int,int,int)" ( FindBitmapAt@Form1@Testexer@@$$FA$AAMHPAUHDC__@@HH0HHHH@Z) Testexer.obj
Error 10 error LNK2019: unresolved external symbol "extern "C" int __stdcall GetObjectW(void *,int,void *)" ( GetObjectW@@$$J212YGHPAXH0@Z) referenced in function "extern "C" int __cdecl GetObject(void *,int,void *)" ( GetObject@@$$J0YAHPAXH0@Z) Testexer.obj
Error 11 error LNK2019: unresolved external symbol "extern "C" int __stdcall DeleteObject(void *)" ( DeleteObject@@$$J14YGHPAX@Z) referenced in function "private: int __clrcall Testexer::Form1::FindBitmapAt(struct HDC__ *,int,int,struct HDC__ *,int,int,int,int)" ( FindBitmapAt@Form1@Testexer@@$$FA$AAMHPAUHDC__@@HH0HHHH@Z) Testexer.obj
Error 12 error LNK2019: unresolved external symbol "extern "C" int __stdcall DeleteDC(struct HDC__ *)" ( DeleteDC@@$$J14YGHPAUHDC__@@@Z) referenced in function "private: int __clrcall Testexer::Form1::FindBitmapAt(struct HDC__ *,int,int,struct HDC__ *,int,int,int,int)" ( FindBitmapAt@Form1@Testexer@@$$FA$AAMHPAUHDC__@@HH0HHHH@Z) Testexer.obj
Error 13 error LNK2019: unresolved external symbol "extern "C" long __stdcall GetBitmapBits(struct HBITMAP__ *,long,void *)" ( GetBitmapBits@@$$J212YGJPAUHBITMAP__@@JPAX@Z) referenced in function "private: int __clrcall Testexer::Form1::FindBitmapAt(struct HDC__ *,int,int,struct HDC__ *,int,int,int,int)" ( FindBitmapAt@Form1@Testexer@@$$FA$AAMHPAUHDC__@@HH0HHHH@Z) Testexer.obj
Error 14 error LNK2019: unresolved external symbol "extern "C" int __stdcall BitBlt(struct HDC__ *,int,int,int,int,struct HDC__ *,int,int,unsigned long)" ( BitBlt@@$$J236YGHPAUHDC__@@HHHH0HHK@Z) referenced in function "private: int __clrcall Testexer::Form1::FindBitmapAt(struct HDC__ *,int,int,struct HDC__ *,int,int,int,int)" ( FindBitmapAt@Form1@Testexer@@$$FA$AAMHPAUHDC__@@HH0HHHH@Z) Testexer.obj
Error 15 error LNK2019: unresolved external symbol "extern "C" void * __stdcall SelectObject(struct HDC__ *,void *)" ( SelectObject@@$$J18YGPAXPAUHDC__@@PAX@Z) referenced in function "private: int __clrcall Testexer::Form1::FindBitmapAt(struct HDC__ *,int,int,struct HDC__ *,int,int,int,int)" ( FindBitmapAt@Form1@Testexer@@$$FA$AAMHPAUHDC__@@HH0HHHH@Z) Testexer.obj
Error 16 error LNK2019: unresolved external symbol "extern "C" struct HBITMAP__ * __stdcall CreateCompatibleBitmap(struct HDC__ *,int,int)" ( CreateCompatibleBitmap@@$$J212YGPAUHBITMAP__@@PAUHDC__@@HH@Z) referenced in function "private: int __clrcall Testexer::Form1::FindBitmapAt(struct HDC__ *,int,int,struct HDC__ *,int,int,int,int)" ( FindBitmapAt@Form1@Testexer@@$$FA$AAMHPAUHDC__@@HH0HHHH@Z) Testexer.obj
Error 17 error LNK2019: unresolved external symbol "extern "C" struct HDC__ * __stdcall CreateCompatibleDC(struct HDC__ *)" ( CreateCompatibleDC@@$$J14YGPAUHDC__@@PAU1@@Z) referenced in function "private: int __clrcall Testexer::Form1::FindBitmapAt(struct HDC__ *,int,int,struct HDC__ *,int,int,int,int)" ( FindBitmapAt@Form1@Testexer@@$$FA$AAMHPAUHDC__@@HH0HHHH@Z) Testexer.obj
Error 18 fatal error LNK1120: 16 unresolved externals C:\Documents and Settings\Viktor\Mina dokument\Visual Studio 2005\Projects\Testexer\Debug\Testexer.exe
so should i make a win32 project
Diegota
{
IntPtr hdcBuffer = CreateCompatibleDC(hdcJava);
IntPtr hBitmap = CreateCompatibleBitmap(hdcJava, width, height);
SelectObject(hdcBuffer, hBitmap);
BitBlt(hdcBuffer, 0, 0, width, height, hdcJava, 0, 0, 0x00CC0020);
Bitmap bJava = Bitmap.FromHbitmap(hBitmap);
DeleteDC(hdcBuffer);
DeleteObject(hBitmap);
return bJava;
}
lol, i forgot to add the delete stuff.. im just trying to convert my C# source to C++
how do i fix the linking thing
Mario Almeida
vs8