Click here to Skip to main content
15,867,851 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a vb6 exe that starts a thread hook injected into another process.
The hook installer code is in the dll that is written in c

After the installhook call is made I am finished with the dll and it is now injected into the target process so I call FreeLibrary which is returning 1 which means it succeeded but a look at
Process Explorer shows not only the injected hookproc in the target process but an instance of the dll code is still hanging around and being held onto by the this process that installed the hook. This is causing an issue in deleting the hook dll when the injected code terminates saying it is in use by the installing process.

I hope this is remotely clear.

VB6 "hook starter"

hinstDLL = LoadLibrary(AppFilePath + "\\BCRMultiUnit\BCRBitBridgeHelper.dll")

hkprcSysMsg = GetProcAddress(hinstDLL, "ReadVSTStripNumProc")

InstallHookProc = GetProcAddress(hinstDLL, "installhook")

BitBridgeThread = GetWindowThreadProcessId(HwndBitBridge, 0)

installhook ByVal hinstDLL, ByVal BitBridgeThread

FreeLibrary (hinstDLL) '' I expect this to unload the dll from this process


The hook installer function in the hook dll

C++
BOOL __declspec(dllexport)__stdcall installhook(HINSTANCE hinstDLL, long BitBridgeThread)
{
	hBitBridge = SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC)ReadVSTStripNumProc, hinstDLL, BitBridgeThread);
return TRUE;
}


Help? :-)

Thanks in advance!

:Ron
Posted

1 solution

Googling once again I found a un-holy solution to a similar question elsewhere.

" You might want to try calling FreeLibrary(Module) in a loop until it fails. Windows keeps a loaded count for DLLs and only when it goes to zero does it unload the DLL."

This is just nuts but for now is working.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900