Take the 2-minute tour ×


I want to use the Windows API Postmessage() call from inside a MySQL UDF on MySQL 5.1.51 (XP SP3). I know the UDF (Written in Delphi 2006) is working by setting a bogus result for the UDF.

The syntax of the UDF takes two integer params, one for a window handle and the other for a message number. However a call to PostMessage() from inside my UDF causes an exception in mysqld and the service stops.

Any ideas or pointers? Alternatively if anyone can tell me how I am able to simulate IB Events for MySQL via AnyDAC and Delphi OR an alternate approach to getting a notification when a record has changed in the database then please show me the light.


share|improve this question
It would help if you posted what exception you're getting... –  Mason Wheeler Oct 21 '10 at 2:14
Are you running MySQL as a service? I don't think it will have access your desktop windows if you do. I don't think it should crash though. Also Delphi seems like an odd language to write a MySQL UDF in. –  Alexandre Jasmin Oct 21 '10 at 2:23
Welcome to Stack Overflow. Your final paragraph asks about how to simulate Interbase events in MySQL. If that's really what you want, then ask that ask a separate question. Don't bury it here in a question about unspecified exceptions. –  Rob Kennedy Oct 21 '10 at 2:28
Yes I am running MySQL as a service. I don't get any exception. I get Microsoft's "This application has encountered an error and needs to close". The event log shows: EventID: 1000 Category (100) Faulting application mysqld.exe, version, faulting module kernel32.dll, version 5.1.2600.5781, fault address 0x00012afb. –  TheEdge Oct 21 '10 at 2:55
@user223742 Try not running it as a service. –  Alexandre Jasmin Oct 21 '10 at 3:02

3 Answers 3

up vote 1 down vote accepted

As an alternative to windows messages or TCP/IP, you might want to consider the named pipes answer to this question on sending information between two Delphi programs and this question on what named pipes are.


share|improve this answer
Thanks Jeroen, This is the solution I ended up going with. Wrote a custom UDF that sends information via a Windows Pipe to either the application itself if it is running on the same machine as the DB server or to a simple socket server application to distribute it via TCP. --Donovan –  TheEdge Oct 22 '10 at 23:18
Cool! Glad I could be of help. –  Jeroen Wiert Pluimers Oct 23 '10 at 12:33

Your going to run into problems with this approach mainly due to the fact that messaging will only work to the same access level, and within the same session on the same computer. You would be better served by using other methods, such as TCPIP sockets, MailSlots, Memory mapped files, ect.

To best simulate a post message, I would use TCPIP UDP. A good lightweight library that I have used in the past is Synapse. The synapse library from SVN does run quite well against the latest versions of Delphi. The class you will want to use for this is the TUDPBlockSocket.

share|improve this answer
OK. So the next question is whether the UDF will open the socket in the _init and then close it in the _deinit. –  TheEdge Oct 21 '10 at 3:57
I would make this a lazy create. You don't need it until the event needs to be fired, so create it then. In the _deinit check to see if a socket was created and if so then destroy it. Keeps it simple. UDP is a fire and forget protocol. You don't have to wait and listen for a response. –  skamradt Oct 21 '10 at 15:51

While I have had success via the UDF / Windows Pipe route I had another idea leveraging off being able to tap into the information message framework(?) in MySQL. See http://stackoverflow.com/q/3992779/223742

share|improve this answer

Your Answer


