Jump to content
  • Advertisement
Sign in to follow this  
michaudj

How to make a CALLBACK a friend function [resolved]

This topic is 3791 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi My problem was : Make a CALLBACK function a friend function from a class in a namespace. Platform : Windows XP sp2 Language : C++ Using Microsoft Visual Studio 2008 The solution i found is :
namespace device {
	namespace input {
class Keyboard
{
	friend LRESULT LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
	//friend LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam); //Same Error as above
public:
	Keyboard();
	~Keyboard();
private:
	int KeyboardProc( int nCode, WPARAM wParam, LPARAM lParam );
	
};
}
}









#include "stdafx.h"
#include "KeyboardDevice.hpp" // Class Keyboard
#include <iostream>

static device::input::Keyboard* pKBDev;
HHOOK hkb;
HINSTANCE hins;

//... some code ....

LRESULT CALLBACK device::input::LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{ 
	if(nCode < 0)
		return CallNextHookEx(hkb, nCode, wParam, lParam);

	pKBDev->KeyboardProc( nCode, wParam, lParam );

	return CallNextHookEx(hkb, nCode, wParam, lParam); 

}

extern "C" __declspec(dllexport) BOOL installhook()
{
    hkb=SetWindowsHookEx(WH_KEYBOARD_LL,(HOOKPROC)device::input::LowLevelKeyboardProc,hins,0);
    return TRUE;

}








[Edited by - michaudj on May 7, 2008 1:03:53 PM]

Share this post


Link to post
Share on other sites
Advertisement
Could you post the entire error message? Just posting error codes is not particularly useful.

Share this post


Link to post
Share on other sites
yes, certainly
here it is
1>.\KeyboardManager.cpp(50) : error C2440: 'cast de type' : impossible de convertir de 'overloaded-function' en 'HOOKPROC'


Maybe i don't understand the friend correctly


i simply want to be able to call the function KeyboardProc from the LowLevelKeyboardProc

And i though this would be simple :(

[Edited by - michaudj on May 7, 2008 12:57:09 PM]

Share this post


Link to post
Share on other sites
You are missing the CALLBACK #define in front of the function prototype when you friend LowLevelKeyboardProc.

IE:


friend LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);


CALLBACK is #defined to be __stdcall. __stdcall LowLevelKeyboardProc is a different function from LowLevelKeyboardProc from the compiler's persective.

Share this post


Link to post
Share on other sites
sorry, i accidently erased the comment from the code, but i tried both and they gave the same error.

I just added it in comment to the code, to show i tried this solution.

Thanks you very much for the help though.


UPDATE :

Somewhere within a file i used this : using namespace device;

which made the thing fail... so i have updated the code... a new error arise !!! :P


UPDATE ; PROBLEM SOLVE!

Thanks CPR007, though the error was somewhere else, you made me realize my misstake !

[Edited by - michaudj on May 7, 2008 12:27:24 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!