Jump to content
  • Advertisement
Sign in to follow this  

Silly Little DLL QuestionL

This topic is 3856 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

(Question had to have an L... ever other word in the title did :-P) Well, I'm trying to make a little windows hook, and I got the hook working, and all that's fine. But now, I'm having troubles sending a value from my DLL to my Executable. I'll just paste the code, and tell you what's going on: --------------------------
#include <windows.h>
#include <iostream>

extern "C" __declspec(dllimport) void InstallHook( );
extern "C" __declspec(dllimport) void UnInstallHook( );
extern "C" __declspec(dllimport) void GetX( int *px );
extern "C" __declspec(dllimport) void GetY( int *py );

int main()
	int x, y;
	InstallHook(  );

		std::cout << x << '\t' << y << std::endl;
		// Nothing
	}while( (x >= 5) && (y >= 5) ); 


	return 0;

#include <windows.h>

HHOOK hhk;
HINSTANCE dllInstance;
bool shown;
HWND shell;
HWND button;
RECT startRect;

int x = 10, y = 10;

LRESULT CALLBACK myMouseProc(int code, WPARAM wParam, LPARAM lParam);
extern "C"
	__declspec(dllexport) void InstallHook( );
	__declspec(dllexport) void UnInstallHook( );
	__declspec(dllexport) void GetY( int *py );
	__declspec(dllexport) void GetX( int *px );

BOOL WINAPI DllMain(HINSTANCE hInstance,DWORD fwdReason, LPVOID lpvReserved)
	dllInstance = hInstance;
	shown = true;

	shell = FindWindow(L"Shell_TrayWnd", NULL);
	button = FindWindowEx(shell, NULL, L"button", NULL);

	GetWindowRect(button, &startRect);		// Store the windows's rectangle in this rect.


extern "C" __declspec(dllexport) void InstallHook( )
	hhk = SetWindowsHookEx(WH_MOUSE, (HOOKPROC)&myMouseProc, dllInstance , NULL );

extern "C" __declspec(dllexport) void UnInstallHook( )
	if( !UnhookWindowsHookEx( hhk ) )
		MessageBox(NULL, L"NOT Uninstalled Bitch!", L"Yay!", MB_OK);


extern "C" __declspec(dllexport) void GetX( int *px )
	*px = x;

extern "C" __declspec(dllexport) void GetY( int *py )
	*py = y;

LRESULT CALLBACK myMouseProc(int code, WPARAM wParam, LPARAM lParam)

	if (code < 0) // do not process message 
		return CallNextHookEx(hhk, code, wParam, lParam); 

	x = (int)mouse_hook->pt.x;
	y = (int)mouse_hook->pt.y;

	if( (x > (startRect.left - 1 ) ) && (x < startRect.right) )
		if ( (y > startRect.top) && (y < startRect.bottom) )
			ShowWindow(button, 0);
		ShowWindow(button, 1);

	return(CallNextHookEx( hhk, code, wParam, lParam ) );


Basically, the output is constantly 10, for some reason, so the * = (int)mouse_hook->pt.* isn't working, for some reason. EDIT: sorry for the sloppy code, just trying to get things to work. BTW, this DOES compile (visual studio 2005).

Share this post

Link to post
Share on other sites
For those interested, I had to create a shared data segment for the DLL, in order to alter the values.

Secondly, I had to change my x and y types to LONGs, since the POINT struct uses LONGs, not ints.

Looks something like this:

#pragma data_seg(".SHARED")
LONG x = 0;
LONG y = 0;
#pragma data_seg()

With linker option:

Works like a charm, now :-)

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!