We're trying to send a WM_DROPFILES message to MS
SoundRecorder.
We don't know exactly the format of the structure to send
as an HDROP parameter to the SendMessage (hWndSoundRec,
WM_DROPFILES, (WPARAM) &oMedium, 0L) function.
The message is actually recieved by the Sound Recorder.
However it pops up a message saying:
"File cannot be opened" with random characters (indicating
reading from a non-allocated, or corrupted memory
location) at the end.
We're using the structures STGMEDIUM and DROPFILES as
below.
What are we missing?
int main(int argc, char* argv[])
{
HWND hWndSoundRec = FindWindow ("SoundRec", NULL);
if (hWndSoundRec)
{
HGLOBAL hGlobal = GlobalAlloc (GMEM_FIXED,
sizeof ("k:\\temp\\test.wav") + 2);
char *strFile = (char*) GlobalLock
(hGlobal);
strcpy (strFile, "c:\\temp\\test.wav");
strFile [strlen ("c:\\temp\\test.wav") +
1] = NULL;
POINT point;
point.x = 100;
point.y = 100;
DROPFILES oDropFiles;
oDropFiles.pFiles = (long) &strFile;
oDropFiles.fNC = FALSE;
oDropFiles.fWide = FALSE;
oDropFiles.pt = point;
STGMEDIUM oMedium;
oMedium.tymed = 1;
oMedium.hGlobal = &oDropFiles;
//Send Message with a file reference.
BOOL bSent = SendMessage (hWndSoundRec,
WM_DROPFILES, (WPARAM) &oMedium, 0L);
BOOL bRet = GlobalUnlock (hGlobal);
GlobalFree (hGlobal);
}
return 0;
}
Henk Devos
http://www.whirlingdervishes.com
"Joseph Scandura" <cust...@scandura.com> wrote in message
news:03c301c3973d$0433f8e0$a101...@phx.gbl...
> file://Send Message with a file reference.
As Henk correctly points out, the WPARAM should be an HGLOBAL containing the DROPFILES structure. Try the following code snippet. It seems to be important to use PostMessage rather than SendMessage, I'm not too sure why that is.
int main(int argc, char* argv[])
{
if (HWND hwnd = FindWindow ("SoundRec", 0))
{
char filename[] = "c:\\temp\\test.wav";
if (HGLOBAL hGlobal =
GlobalAlloc(GHND, sizeof(DROPFILES) + strlen(filename) + 2))
{
DROPFILES * df = static_cast<DROPFILES *>(GlobalLock(hGlobal));
df->pFiles = sizeof(DROPFILES);
strcpy(reinterpret_cast<char *>(df + 1), filename);
GlobalUnlock(hGlobal);
if (!PostMessage(hwnd, WM_DROPFILES, (WPARAM)hGlobal, 0))
GlobalFree(hGlobal);
}
}
return 0;
}
--
Jim Barry, MVP for Windows SDK
"Honor Bound to Defend Freedom" - slogan displayed at the gates of Camp
Delta, Guantanamo Bay, Cuba, where over 600 prisoners are held indefinitely
by the U.S. military, without trial, in defiance of international law.
Hey, that's extremely interesting. I suppose a similar technique could
be used to "relay" any WM_DROPFILES message my window receives to a
window in another process? Any idea how that would look like?
Simon
How do you mean, other than making sure that DefWindowProc does not get a chance to free the HGLOBAL before it reaches the target?
> "ilm" <i...@msnews.account> wrote:
>
>>Hey, that's extremely interesting. I suppose a similar technique could
>>be used to "relay" any WM_DROPFILES message my window receives to a
>>window in another process? Any idea how that would look like?
>
>
> How do you mean, other than making sure that DefWindowProc does not get a chance to free the HGLOBAL before it reaches the target?
Well I actually meant making a copy of the entire original message and
all its associated data.
There shouldn't be any need to copy the data, the HGLOBAL can just be passed on as-is.
- Jim
"Jim Barry" <j...@mvps.org> wrote in message
news:eNFYlRcm...@tk2msftngp13.phx.gbl...
"Raymond Chen" <http://blogs.gotdotnet.com/raymondc/> wrote in message
news:#F2cmpfm...@TK2MSFTNGP12.phx.gbl...
Paul
"Henk Devos" <in...@dontspamme.regxplor.com> wrote in message
news:bnao4l$va$1...@reader08.wxs.nl...
Yes, exactly. (Well, not for HDROP generally, but for WM_DROPFILES in particular.) DoDragDrop would otherwise have great difficulty in delivering WM_DROPFILES messages to windows with WS_EX_ACCEPTFILES set. I must correct my earlier statement about freeing the handle - the destination process will receive a copy of the HGLOBAL, so the source process should free the original handle (i.e. call DragFinish) after forwarding it.
- Jim
That will be because these applications do not actually handle the WM_DROPFILES message. Instead, they implement IDropTarget and call RegisterDragDrop. Unfortunately, there is currently no documented method of retrieving the IDropTarget interface associated with a window.
- Jim