Re: Overwrite data_seg variable
Thanks for your reply. The following list 2 codes (Hook.cpp and CDlg.cpp):
Hook.cpp
#pragma data_seg(".SHARDAT")
static HHOOK hkb=NULL;
LPCTSTR lpData=_T("");
#pragma data_seg()
LRESULT __declspec(dllexport)__stdcall CALLBACK KeyboardProc(int nCode,
WPARAM wParam, LPARAM lParam)
{
// Require the use of lpData here
return CallNextHookEx(hkb, nCode, wParam, lParam);
}
BOOL __declspec(dllexport)__stdcall InstallHook(LPCTSTR lpExternalData)
{
lpData = lpExternalData;
hkb = SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC)KeyboardProc, hins, 0);
return TRUE;
}
CDlg.cpp
void CDlg::Hook(LPCTSTR lpData)
{
static HINSTANCE hinstDLL = LoadLibrary(_T("Hook.dll"));
typedef BOOL (CALLBACK *inshook)(LPCTSTR);
inshook instkbhook = (inshook)GetProcAddress(hinstDLL, "InstallHook");
instkbhook(lpData);
ShowWindow(SW_MINIMIZE);
}
Notice that I have a parameter pass in to the hook from my application. I
require this variable to be global to all proc such as the KeyboardProc in
the hook class. But when I tried to reference lpData in the KeyboardProc,
the data is "" and not the value of the data input from the application. Any
idea how to overcome this problem or to achieve my objective?
"Igor Tandetnik" wrote:
"cleohm" <cleohm@discussions.microsoft.com> wrote in message
news:4DE6E659-28D1-43F4-8E8F-97B9D4063A16@microsoft.com
I am currently working on a hook program where the install hook
function accepts a variable. I want this variable to be store in a
global variable so that it can be subsequently use within the proc
such as keyboardproc. I have the global variable declared in the
data_seg section, however, I can't seems to get the correct value
within the proc where the value was set in the install hook function,
instead I get the initialize value set in the data_seg section. I
have tried the following but still unsuccessful:
#pragma comment(linker,"/SECTION:.SHARE,RWS")
Show the relevant code. You are doing something wrong. This technique
works.
See KB article KB100634 "How to specify both shared data and non-shared
data in a DLL in Visual C++" (though you seem to already know everything
it has to say).
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925