CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2017
    Posts
    3

    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 ==========

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: GetPixel and LoadLibrary gdi32.dll

    Quote Originally Posted by engmaster View Post
    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

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: GetPixel and LoadLibrary gdi32.dll

    [moved thread...]
    Victor Nijegorodov

  4. #4
    Join Date
    Jul 2017
    Posts
    3

    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!

  5. #5
    Join Date
    Jul 2017
    Posts
    3

    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
  •  





Click Here to Expand Forum to Full Width

Featured