🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: [Remy] SendMessage() from a DLL to APP

#6500
From: Vladimir Stefanovic
Date: Wed, 04 May 2005 18:59
95 lines
4295 bytes
Thanks,

I'll implement all that tomorrow...


-- 
Best regards,
Vladimir Stefanovic
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message 
news:42791382$1@newsgroups.borland.com...
>
> "Vladimir Stefanovic" <antivari@po.sbb.co.yu> wrote in message
> news:4278b3f0@newsgroups.borland.com...
>
>> Anyway, can you please take a short look at the code and see if
>> I should make any (maybe code security) corrections to it.
>
>> 1) Is there any sigifficant difference if I use SendMessage() or
>> PostMessage() from my DLL, in my case?
>
> That entirely depends on your actual needs.  SendMessage() waits for the
> message to be processed.  PostMessage() does not.
>
>> 2) In the API CreateFileMapping(), I named a last argument
>> "DiHook", and I never used it after that. Is that OK? Should I use
>> NULL?
>
> No, do not use NULL, or else the memory won't be shared at all.  The name 
> is
> what makes it sharable to begin with.
>
>> 3) Is that normal that I haven't any chages (because of shared memory
>> changes in y DLL) at my App side, except that I passed the HWND
>> argument to install a DLL?
>
>
>> extern "C" __declspec(dllexport) __stdcall void SetHook(HWND);
>> extern "C" __declspec(dllexport) __stdcall void RemoveHook(void);
>
> I would recommend adding return values to those functions so that the
> application can know whether or not the hooking/unhooking actuall 
> succeeds.
>
>>            if ( hFileMapping )
>>               pHookInfo = (PHOOKINFO)MapViewOfFile( hFileMapping,
>>                                                     FILE_MAP_WRITE,
>>                                                     0,
>>                                                     0,
>>                                                     0 );
>
> If either CreateFileMapping() or MapViewOfFile() fail, I prefer to release
> the file mapping and make DllEntryPoint() return FALSE.  That way, the
> application knows that the DLL was unable to initialize itself, and thus 
> the
> hooks won't work properly.
>
>>            UnmapViewOfFile( pHookInfo );
>>            pHookInfo = NULL;
>>            CloseHandle( hFileMapping );
>>            hFileMapping = NULL;
>>            break;
>
> Make sure to check for NULL pointers before calling the functions:
>
>    if( pHookInfo  )
>        UnmapViewOfFile( pHookInfo );
>    if( hFileMapping )
>        CloseHandle( hFileMapping );
>
>> DWORD __stdcall CheckKey( int nCode, WORD wParam, LONG lParam )
>
> You can simplify that code to the following:
>
>    DWORD __stdcall CheckKey( int nCode, WORD wParam, LONG lParam )
>    {
>        if( pHookInfo )
>        {
>            if( ((nCode >= 0) && (nCode != HC_NOREMOVE))
>                && ((lParam & 0x40000000) == 0) // Skip if it's a repeat
>                && (lParam & 0x20000000) ) // Check if Alt is pressed
>            {
>                // Send key information to the main window
>                if( pHookInfo->hAppWnd )
>                    PostMessage(pHookInfo->hAppWnd, WM_KEYHOOK, 0, lParam);
>            }
>            return CallNextHookEx(pHookInfo->ghhookKB, nCode, wParam,
> lParam);
>        }
>        return 0;
>    }
>
>
> Gambit
>
> 
Technical Details
Message-ID: <42791b96@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news2.google.com!proxad.net!212.101.4.254.MISMATCH!solnet.ch!solnet.ch!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <427748eb@newsgroups.borland.com> <4277c28c$1@newsgroups.borland.com> <4278b3f0@newsgroups.borland.com> <42791382$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,94b1d46dd644a85c
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Vladimir Stefanovic" <antivari@po.sbb.co.yu>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <427748eb@newsgroups.borland.com> <4277c28c$1@newsgroups.borland.com> <4278b3f0@newsgroups.borland.com> <42791382$1@newsgroups.borland.com>
Subject: Re: [Remy] SendMessage() from a DLL to APP
Date: Wed, 4 May 2005 20:59:43 +0200
Lines: 97
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 82.117.212.65
Message-ID: <42791b96@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1115233174 82.117.212.65 (4 May 2005 11:59:34 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news2.google.com!proxad.net!212.101.4.254.MISMATCH!solnet.ch!solnet.ch!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail