1

G'Day,

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.

--Donovan

7
  • 1
    It would help if you posted what exception you're getting... Commented Oct 21, 2010 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. Commented Oct 21, 2010 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. Commented Oct 21, 2010 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 0.0.0.0, faulting module kernel32.dll, version 5.1.2600.5781, fault address 0x00012afb. Commented Oct 21, 2010 at 2:55
  • @user223742 Try not running it as a service. Commented Oct 21, 2010 at 3:02

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

OK. So the next question is whether the UDF will open the socket in the _init and then close it in the _deinit.
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.
1

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.

--jeroen

2 Comments

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
Cool! Glad I could be of help.
0

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 https://stackoverflow.com/q/3992779/223742

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.