Winamp & Shoutcast Forums

Winamp & Shoutcast Forums (http://forums.winamp.com/index.php)
-   NSIS Discussion (http://forums.winamp.com/forumdisplay.php?f=65)
-   -   plugin hooking... one step to void the /NOUNLOAD (http://forums.winamp.com/showthread.php?t=205854)

Joel 24th January 2005 21:14

plugin hooking... one step to void the /NOUNLOAD
 
code:

HINSTANCE hInst;
HMODULE hMod;
int i;
HHOOK hHook;
HOOKPROC hHookProc;

#define Function(name) extern "C" void __declspec(dllexport) name(HWND hwndParent, int string_size, char *variables, stack_t **stacktop)

Function(suma)
{
EXDLL_INIT();
setuservariable(0, int2str(++i));
}

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
{
hInst = hinstDLL;
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
{
i = 0;
hMod = LoadLibrary("nsDLL");
hHookProc = (HOOKPROC)GetProcAddress(hMod, "suma");
hHook = SetWindowsHookEx(WH_CBT, hHookProc, hMod, 0);
return TRUE;
}
case DLL_PROCESS_DETACH:
{
UnhookWindowsHookEx(hHook);
FreeLibrary(hMod);
return TRUE;
}
}
return TRUE;
}


Example:
code:

Section
nsDLL::suma ; $0 1
nsDLL::suma; $0 2
nsDLL::suma ; $0 1
nsDLL::suma ; $0 2
DetailPrint $0 ; $0 2
SectionEnd


at the end, $0 returns 2, when it suppose to be 4.... what I'm missing? :igor:

Anders 24th January 2005 22:07

-LoadLibrary in DllMain, safe?
-SetWindowsHookEx in DllMain, safe? (if I remember correctly only some of the functions in kernel32 may be used in DllMain)
-wrong function type for SetWindowsHookEx (suma returns void, hookproc returns LRESULT)
-does not call CallNextHookEx
-global hook needed?
-why is hHookProc a global variable?

Joel 24th January 2005 22:13

so, any ideas how? :)

Anders 24th January 2005 22:20

I have not tested this code and im not even sure that the dll is not unloaded right away

As I have told you before, the way I have done it is to call LoadLibrary on yourself each time one of the exported functions are called by nsis, the only problem with this is unloading, so you could subclass the nsis window and unload in WM_DESTROY or use a hook. Dro has also talked about api hooking FreeLibrary or something like that


All times are GMT. The time now is 04:43.

Copyright © 1999 - 2010 Nullsoft. All Rights Reserved.