🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Opening a file from WM_COPYMESSAGE

#3394
From: Remy Lebeau (TeamB)
Date: Mon, 19 Jun 2006 02:33
47 lines
3001 bytes
"sez" <www@sezginserin.com> wrote in message
news:4495f47e@newsgroups.borland.com...

> I have coded this but what is wrong?

You are trying to handle the message in the TMainForm class, but you are
sending the message to the TApplication class instead.  You need to do one
of two different things to make this work correctly:

1) leave your WinMain() code as it currently is, and then have TMainForm
call TApplication::HookMainWindow().  The hook method will then be able to
receive the message.

2) leave your TMainForm code as it currently is, but have your WinMain()
code look for the TMainForm window instead of the TApplication window.

With that said, all VCL applications have a TApplication class, so that is
not a very good window to use for sharing data between instances.  You very
well could end up sending the data to the completely wrong application.  You
should rename your TMainForm class to a more unique name, such as
TMyAppMainForm, and then have WinMain() look for that instead.

> HANDLE hSemaphore = ::CreateSemaphore(NULL,1,1, "App.SEMAPHORE");
> if(hSemaphore && WaitForSingleObject(hSemaphore, 0) != WAIT_OBJECT_0) {
>     CloseHandle(hSemaphore);

Why are you doing a wait on the semaphore?  You should be using
GetLastError() instead to know whether the semaphore already existed from a
previous instance or not.

>         COPYDATASTRUCT cds;
>         cds.cbData = strlen(cmdLine) + 1;
>         cds.lpData = cmdLine;
>         SendMessage(hWnd, WM_COPYDATA, 0, (LPARAM)&cds);

You are not providing any value for the dwData member of the COPYDATASTRUCT
structure.  The VCL uses WM_COPYDATA internally for its own purposes, so you
should always provide your own unique 32-bit value for the dwData member,
such as a value returned by RegisterWindowMessage().  That way, you can
validate that any received WM_COPYDATA message is really your own message
before processing its data.  If it is not your own message, then pass it on
unprocessed to the default handler so that you are not breaking the VCL's
messages.


Gambit
Technical Details
Message-ID: <44960d38$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <4495f47e@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,9166deaa46235045
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <4495f47e@newsgroups.borland.com>
Subject: Re: Opening a file from WM_COPYMESSAGE
Date: Sun, 18 Jun 2006 19:33:17 -0700
Lines: 49
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 68.69.17.41
Message-ID: <44960d38$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1150684472 68.69.17.41 (18 Jun 2006 19:34:32 -0700)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail