🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #7981

Re: Wierd CBTHook problem

#7981
From: mike
Date: Thu, 02 Dec 2004 12:46
106 lines
4311 bytes
Thank you both for responding.

Hmmm, seems I need to understand a few things a little better. I will be
working on this and incorporate the guidance you both have provided me.

Thanks

Mike
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message
news:41ae425d$1@newsgroups.borland.com...
>
> "mike" <mfbrowne@earthlink.net> wrote in message
> news:41ae3911@newsgroups.borland.com...
>
> >     while ( true )
>
> Why are you looping?  You should not be doing that.
>
> >          hFileMapHandle     = OpenFileMap()
> <snip>
> >          lpFileMapAddress      = MapFile( hFileMapHandle )
>
> Why are you retrieving the file mapping every time the hook is called?
You
> should be retrieving it only once, when the DLL is first loaded.
>
> >    cds.dwData = 10000
> >    cds.cbData = 0
> >    cds.lpData = NameVal.c_str()
>
> You are speciying 0 for cbData when you should be specifying
> NameVal.Length() instead.  By setting it to 0, WM_COPYDATA wo't be able to
> actually copy any data - you told it there isn't any data to copy.
>
> BTW, you should give dwData a more unique value.  You shouldn't hard-code
> it, unless you can 100% guarantee that it will always be unique.  10000 is
> not likely to always be unique.  Something more like this will be, though:
>
>     cds.dwData = 0x4D696B65; // "Mike" in hex
>
> Now, with all of that said, try this code instead:
>
>
>     HANDLE hFileMapHandle = NULL;
>     tagMemoryFileDefinition *MyMemoryFile = NULL;
>
>     BOOL WINAPI DllEntryPoint(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID
> lpvReserved)
>     {
>         switch( fdwReason )
>         {
>             case DLL_PROCESS_ATTACH:
>             {
>                 hFileMapHandle = OpenFileMap();
>                 if( !hFileMapHandle )
>                     return FALSE;
>
>                 MyMemoryFile = static_cast<tagMemoryFileDefinition*>(
> MapFile(hFileMapHandle) );
>                 if( !MyMemoryFile )
>                 {
>                     CloseHandle(hFileMapHandle);
>                     return FALSE;
>                 }
>
>                 break;
>             }
>
>             case DLL_PROCESS_DETACH:
>             {
>                 if( MyMemoryFile ) UnmapViewOfFile(MyMemoryFile);
>                 if( hFileMapHandle ) CloseHandle(hFileMapHandle);
>                 break;
>             }
>         }
>
>         return TRUE;
>     }
>
>     LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam)
>     {
>         if( (nCode >= 0) && (nCode == HCBT_CREATEWND) )
>         {
>             HWND hWndCreate = reinterpret_cast<HWND>(wParam);
>             AnsiString ClassVal =
> reinterpret_cast<LPCBT_CREATEWND>(lParam)->lpcs->lpszClass;
>             AnsiString DataVal = ("Class " + ClassVal);
>
>             COPYDATASTRUCT cds = {0};
>             cds.dwData = 0x4D696B65;
>             cds.cbData = DataVal.Length();
>             cds.lpData = DataVal.c_str();
>
>             ::SendMessage(MyMemoryFile->hWindowForMessages, WM_COPYDATA,
0,
> reinterpret_cast<LPARAM>(&cds));
>         }
>
>         return CallNextHookEx(MyMemoryFile->hMsgHook, nCode, wParam,
> lParam);
>     }
>
>
> Gambit
>
>
Technical Details
Message-ID: <41af0e65$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!lnewsoutpeer01.lnd.ops.eu.uu.net!lnewsinpeer01.lnd.ops.eu.uu.net!emea.uu.net!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <41ae07e2$1@newsgroups.borland.com> <41ae2598$1@newsgroups.borland.com> <41ae3911@newsgroups.borland.com> <41ae425d$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,80a054b0854861c4
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "mike" <mfbrowne@earthlink.net>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <41ae07e2$1@newsgroups.borland.com> <41ae2598$1@newsgroups.borland.com> <41ae3911@newsgroups.borland.com> <41ae425d$1@newsgroups.borland.com>
Subject: Re: Wierd CBTHook problem
Date: Thu, 2 Dec 2004 07:46:35 -0500
Lines: 108
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 68.204.189.169
Message-ID: <41af0e65$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1101991525 68.204.189.169 (2 Dec 2004 04:45:25 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!lnewsoutpeer01.lnd.ops.eu.uu.net!lnewsinpeer01.lnd.ops.eu.uu.net!emea.uu.net!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail