News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Interesting alternate use for an API

Started by donkey, December 12, 2010, 02:03:35 PM

Previous topic - Next topic

donkey

Yup, you're right, the message remains until the Windows session ends.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

jj2007

Quote from: Antariy on December 12, 2010, 11:41:51 PM
No, when application was ended, registered messages was *not* deleted. They stay registered until system reboot. Try to get a string from GetClipboardFormatName for an atom which you get earlyer in other running, and you will see.

Testbed... Alex is right. Still, it has an advantage over WM_COPYDATA since the latter would not work with console app.

include \masm32\include\masm32rt.inc

.data?
MessageName dd 2048 dup(?)

.code
TheString db "A test string designed for 'InterProcessCommunication' aka IPC;", 13, 10, "it works also with special characters, and you can insert CrLf easily.",13, 10,\
"The string can be a little bit longer, but it should not exceed 256 characters,", 13, 10, "apparently. Beyond 256, it will chok", 0

start: invoke SetLastError, 0
print "Testing RegisterWindowMessage with a "
print str$(sizeof TheString), " byte string:", 13, 10
Round1=1
if Round1
invoke RegisterWindowMessage, offset TheString
else
mov eax, 49799 ; on first round, I see this value
endif
push eax
print str$(eax), 9
print LastError$(), 13,10
pop eax
invoke GetClipboardFormatName,eax,offset MessageName, sizeof MessageName
print LastError$(), 13,10
print offset MessageName
exit
end start

Antariy

Quote from: donkey on December 13, 2010, 12:04:46 AM
Yup, you're right, the message remains until the Windows session ends.

Anyway, your trick is very useful. For message scanners etc.

dedndave

you mean console apps cannot share memory ?
i have never had a need to do this - but it would be cool to know how   :bg

jj2007

Quote from: dedndave on December 13, 2010, 01:51:50 AM
you mean console apps cannot share memory ?

The problem is that console apps typically have no message loop/WndProc where you could check for WM_COPYDATA.

dedndave

hmmmm
another thing i haven't tried yet   :P
create a console proc, (i.e. no gui window) with a WndProc
well - that seems easy enough
that's what happens when i accidently link a gui app as console   :bg

jj2007

Quote from: dedndave on December 13, 2010, 03:21:33 AM
create a console proc, (i.e. no gui window) with a WndProc

If you create a GUI app with subsystem console, you will have a console for printing. Everything else works as usual.

I forgot to mention that you can send WM_COPYDATA from a console.

dedndave