the #pragma comment line just adds a linker option without me having to go
to the project settings. The shared segment name is ".shared"
--
Chris Tacke, eMVP
Advisory Board Member
www.OpenNETCF.org
---
Windows CE Product Manager
Applied Data Systems
www.applieddata.net
"100" <100@100.com> wrote in message
news:%23rURuMfiDHA.1172@TK2MSFTNGP09.phx.gbl...[color=blue]
> Hi Chris,
> Do you use /SECTION I can't seet in your code. Without that you don't[/color]
share[color=blue]
> anything
>
> #pragma comment(linker, "/SECTION:.shared,RWS")
> #pragma data_seg(".shared")
> int nShared = 0;
> #pragma data_seg()
>
> HTH
> B\rgds
> 100
>
> "Chris Tacke, eMVP" <ctacke@spamfree-opennetcf.org> wrote in message
> news:%23Kqxt8biDHA.1692@TK2MSFTNGP10.phx.gbl...[color=green]
> > I'm not sure whether this is a C# or C++ question, so I'm asking in both
> > groups.
> >
> > Here's my scenario:
> > I need to get all text added to a ListBox that is in another process[/color][/color]
that[color=blue]
> I[color=green]
> > have no control over. I want to get this information in my C#[/color][/color]
application[color=blue][color=green]
> > through a callback.
> >
> > Here's what I've done:
> > Since global hooks must be done in C, I've written a simple DLL that[/color][/color]
finds[color=blue][color=green]
> > the handle of the ListBox I want the info from, hooks it, and gets the
> > string data as it is added. This all works just fine.
> >
> > The problem:
> > From C# I create a delegate and pass it into the DLL prior to hooking[/color][/color]
the[color=blue][color=green]
> > ListBox. The DLL then saves the function pointer to a global variable[/color][/color]
for[color=blue][color=green]
> > use in the hook procedure. I *can* successfully call the callback from[/color]
> the[color=green]
> > routine that accepts the handler. When I try to use said handle from[/color][/color]
the[color=blue][color=green]
> > hook proc, it is NULL and things go bad.
> >
> > So this is basically what I've got:
> >
> > #pragma data_seg(".shared")
> > CallBack m_callback = NULL;
> > #pragma data_seg()
> >
> > typedef void (__stdcall *CallBack)(LPCTSTR);
> >
> > __declspec(dllexport)
> > BOOL __stdcall LoadHook(CallBack callback)
> > {
> > // If already hooked, don't do it again.
> >
> > // save the hook to a global area
> > m_callback = callback;
> >
> > // I *CAN* call the callback here - this works:
> > m_callback("test");
> > }
> >
> > LRESULT CALLBACK HookProc(int nCode,WPARAM wParam,LPARAM lParam)
> > {
> > CWPSTRUCT *lpcwt;
> > lpcwt = (CWPSTRUCT *)lParam;
> >
> > switch (lpcwt->message)
> > {
> >
> > case LB_ADDSTRING:
> > // my global callback handle is ALWAYS NULL here
> > if(m_callback)
> > m_callback("test");
> >
> > }
> > }
> >
> >
> > I've also tried using a memory-mapped file to store the callback[/color][/color]
function[color=blue][color=green]
> > pointer, but that also fails.
> >
> > Is there something special about a hook proc that makes this so it can't
> > work?
> >
> > Any pointers are GREATLY appreciated!
> >
> > --
> > Chris Tacke, eMVP
> > Advisory Board Member
> >
www.OpenNETCF.org
> > ---
> > Windows CE Product Manager
> > Applied Data Systems
> >
www.applieddata.net
> >
> >[/color]
>
>[/color]