-
July 25th, 2017, 02:13 PM
#1
GetPixel and LoadLibrary gdi32.dll
Hello,
I'm not accustomed to Visual C ++ and need a BIG help.
I hnow that I can use direct GetPixel including the windows.h, buy I need other way to call this func.
So.. I try it:
It'is a simple W32 Console app.
Code:
#include "stdafx.h"
#include "windows.h"
#include <windows.h>
#include <stdio.h>
int main()
{
FARPROC pGetPixel;
HINSTANCE _hGDI = LoadLibrary(L"gdi32.dll");
if (_hGDI)
{
pGetPixel = GetProcAddress(_hGDI, "GetPixel");
HDC _hdc = GetDC(NULL);
if (_hdc)
{
while (1)
{
POINT _cursor;
GetCursorPos(&_cursor);
COLORREF _color = (*pGetPixel) (_hdc, _cursor.x, _cursor.y);
int _red = GetRValue(_color);
int _green = GetGValue(_color);
int _blue = GetBValue(_color);
printf("Red: %d\n", _red);
printf("Green: %d\n", _green);
printf("Blue: %d\n", _blue);
Sleep(2000);
}
}
FreeLibrary(_hGDI);
}
return 0;
}
But I have error on line:
Code:
COLORREF _color = (*pGetPixel) (_hdc, _cursor.x, _cursor.y);
Why I dont able to use it? How to I do it?
The Output from VS2015 C++
Code:
1>------ Rebuild All started: Project: GetPix, Configuration: Debug Win32 ------
1> stdafx.cpp
1> GetPix.cpp
1>c:\users\ ... \getpix.cpp(23): error C2197: 'int (__stdcall *)(void)': too many arguments for call
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
-
July 25th, 2017, 02:32 PM
#2
Re: GetPixel and LoadLibrary gdi32.dll
Originally Posted by engmaster
Hello,
I'm not accustomed to Visual C ++ and need a BIG help.
I hnow that I can use direct GetPixel including the windows.h, buy I need other way to call this func.
So.. I try it:
It'is a simple W32 Console app.
Code:
#include "stdafx.h"
#include "windows.h"
#include <windows.h>
#include <stdio.h>
int main()
{
FARPROC pGetPixel;
HINSTANCE _hGDI = LoadLibrary(L"gdi32.dll");
...
return 0;
}
But I have error on line:
Code:
COLORREF _color = (*pGetPixel) (_hdc, _cursor.x, _cursor.y);
Why I dont able to use it? How to I do it?
The Output from VS2015 C++
Code:
1>------ Rebuild All started: Project: GetPix, Configuration: Debug Win32 ------
1> stdafx.cpp
1> GetPix.cpp
1>c:\users\ ... \getpix.cpp(23): error C2197: 'int (__stdcall *)(void)': too many arguments for call
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
You declared the pGetPixel as void and without the arguments.
Why?
Also see the example in GetProcAddress function article
Victor Nijegorodov
-
July 25th, 2017, 02:34 PM
#3
Re: GetPixel and LoadLibrary gdi32.dll
Victor Nijegorodov
-
July 25th, 2017, 02:53 PM
#4
Re: GetPixel and LoadLibrary gdi32.dll
VictorN,
I am very grateful for your information. (GetProcAddress function)
Thank you!!!
Now the code work!
But, I do it corret? Or still have any mistake.
Code:
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
typedef int(__stdcall *MYPROC)(HDC hd, int x, int y);
/*
(Original) GetPixel(
_In_ HDC hdc,
_In_ int nXPos,
_In_ int nYPos )
*/
HINSTANCE hinstLib;
MYPROC ProcAdd;
int main()
{
//FARPROC pGetPixel;
hinstLib = LoadLibrary(TEXT("gdi32.dll"));
if (hinstLib)
{
ProcAdd = (MYPROC)GetProcAddress(hinstLib, "GetPixel");
HDC _hdc = GetDC(NULL);
if (_hdc)
{
while (1)
{
POINT _cursor;
GetCursorPos(&_cursor);
COLORREF _color = (*ProcAdd) (_hdc, (int)_cursor.x, (int)_cursor.y);
int _red = GetRValue(_color);
int _green = GetGValue(_color);
int _blue = GetBValue(_color);
printf("Red: %d\n", _red);
printf("Green: %d\n", _green);
printf("Blue: %d\n", _blue);
Sleep(100);
}
}
FreeLibrary(hinstLib);
}
return 0;
}
Thank you!
-
July 25th, 2017, 03:04 PM
#5
Re: GetPixel and LoadLibrary gdi32.dll
But, I do it right? Or still have some mistake. ****
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|