GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 15-Feb-2005, 17:54
ubergeek ubergeek is offline
Regular Member
 
Join Date: Jan 2005
Posts: 775
ubergeek is a jewel in the roughubergeek is a jewel in the roughubergeek is a jewel in the rough
Question

DLL--i have no idea how to start


hey

i'm trying to make a program that adds animation when windows are minimized (mostly because I'm using Litestep and I miss the Explorer animations). anyway, i need a system hook so that i can tell when any window is minimized or restored. for that i need a system hook, and my hook procedure, according to MSDN, needs to be in a DLL. they provide a handy example code snipped for loading the DLL with LoadLibrary(), obtaining a pointer to the hook procedure inside the DLL, and then setting the hook with SetWindowsHookEx(). but they don't mention how to make a DLL. with Dev-C++, when i create a new project and select the type DLL, all i get is:
CPP / C++ / C Code:
/* Replace "dll.h" with the name of your header */
#include "dll.h"
#include <windows.h>

DllClass::DllClass()
{

}


DllClass::~DllClass ()
{

}


BOOL APIENTRY DllMain (HINSTANCE hInst     /* Library instance handle. */ ,
                       DWORD reason        /* Reason this function is being called. */ ,
                       LPVOID reserved     /* Not used. */ )
{
    switch (reason)
    {
      case DLL_PROCESS_ATTACH:
        break;

      case DLL_PROCESS_DETACH:
        break;

      case DLL_THREAD_ATTACH:
        break;

      case DLL_THREAD_DETACH:
        break;
    }

    /* Returns TRUE on success, FALSE on failure */
    return TRUE;
}
and for dll.h
CPP / C++ / C Code:
#ifndef _DLL_H_
#define _DLL_H_

#if BUILDING_DLL
# define DLLIMPORT __declspec (dllexport)
#else /* Not BUILDING_DLL */
# define DLLIMPORT __declspec (dllimport)
#endif /* Not BUILDING_DLL */


class DLLIMPORT DllClass
{
  public:
    DllClass();
    virtual ~DllClass(void);

  private:

};


#endif /* _DLL_H_ */

i have no idea how to start with this--can someone shed some light on what i need to do to put my hook procedure in this DLL and have it work?
  #2  
Old 15-Feb-2005, 20:51
ubergeek ubergeek is offline
Regular Member
 
Join Date: Jan 2005
Posts: 775
ubergeek is a jewel in the roughubergeek is a jewel in the roughubergeek is a jewel in the rough
Question

ok partial solution, but this is weird, and aggravating

so i am using these instructions http://neworder.box.sk/newsread_print.php?newsid=10952
to completely sidestep the DLL issue.

his example code works in Dev-C++, but i am unable to tweak it to my own usage because i want to set a WH_CBT hook and his sample code seems only to work with low-level hooks--that is, WH_KEYBOARD_LL and WH_MOUSE_LL! also, those hooks get called twice! this makes no sense to me.

here is my code: (i commented out WinMain because i tried to convert it from console to windows app but it didn't work, i commented out #include "minfx.h" because i haven't implemented my own header yet, and i commented out the prototypes for winmain() and animateminimizingwindow() because they are not necessary)
CPP / C++ / C Code:
#include <windows.h> //winapi calls and defines
//#include "minfx.h" //my defines

HHOOK hCBTHook;

//int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);
void msgLoop();
DWORD WINAPI SetHook(LPVOID lpParameter);
//__declspec(dllexport) LRESULT CALLBACK AnimateMinimizingWindow(int nCode, WPARAM wParam, LPARAM lParam); //can i put this in here? i might need to find out how to put it into a DLL because i think i need a systemwide hook

//i need to set a WH_CBT hook and watch for the HCBT_MINMAX hook code




__declspec(dllexport) LRESULT CALLBACK AnimateMinimizingWindow(int nCode, WPARAM wParam, LPARAM lParam) {
	MessageBox(NULL, "hook triggered", "dbg msg", MB_OK | MB_ICONINFORMATION);
	return CallNextHookEx(hCBTHook, nCode, wParam, lParam);
}




//int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
int main(int argc, char** argv) {
	HANDLE hThread;
	DWORD dwThread;
	DWORD exThread;
	
	hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) SetHook, (LPVOID) argv[0], 0, &dwThread);
	
	return WaitForSingleObject(hThread, INFINITE);
}

DWORD WINAPI SetHook(LPVOID lpParameter) {
	HINSTANCE hExe = GetModuleHandle(NULL);
	if (!hExe) hExe = LoadLibrary((LPCSTR) lpParameter);
	hCBTHook = SetWindowsHookEx(WH_KEYBOARD_LL, (HOOKPROC) AnimateMinimizingWindow, GetModuleHandle(NULL), 0); //install our WH_CBT hook
	
	msgLoop();
	
	UnhookWindowsHookEx(hCBTHook);
	return 0;
}


void msgLoop() {
	MSG message;
	while(GetMessage(&message, NULL, 0, 0)) {
		TranslateMessage(&message);
		DispatchMessage(&message);
	}
}
note: you might not want to run this without changing the messagebox() call to cout<< (and including iostream) or something of that nature. otherwise you will get a message box (i get two) everytime you press a key. however, ctrl+alt+delete still works (despite the three/six message boxes that pop up). also, this only works on Windows NT/2k/XP; other systems do not have low-level hooks.
  #3  
Old 20-Mar-2005, 21:08
ubergeek ubergeek is offline
Regular Member
 
Join Date: Jan 2005
Posts: 775
ubergeek is a jewel in the roughubergeek is a jewel in the roughubergeek is a jewel in the rough
ok, figured it out. i had to use a DLL, and wrap the hook procedure's prototype in extern "C" { } so that C++ name mangling didn't occur.
 
 

Recent GIDBlogMeeting the populace by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent ! Pls Help Me ! mycashmoney C Programming Language 4 01-Jul-2006 22:49
start videolan program in c/c++ Rip7 C++ Forum 1 06-Jan-2005 22:19
How to start your own messenger service? GaryD Open Discussion Forum 2 07-Dec-2004 18:55
Looking for Reliable, Cheap ASP, ASP.NET MSSQL Hosting start from $4 stevewatt88 Web Hosting Advertisements & Offers 1 31-Jul-2004 04:27
Athlon system locking up on start up. Is it MoBo, Processor, PSU or what? ebolaosu Computer Hardware Forum 8 26-Feb-2004 11:19

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 11:33.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.