Friday, March 11, 2022

FoxyDialogs and ctl32: Working Together at Last

Cesar Chalom is one of the best VFP developers in the world, and a great contributor to the VFP community. FoxCharts, FoxyPreviewer, and GDIPlusX are just some of the things he's created or contributed to.

A couple of years ago, he released another tool: FoxyDialogs. This cool add-on provides an incredible amount of control over MESSAGEBOX-style dialogs, so much so that you may do away with creating custom forms for some types of dialogs. For example, one line of code creates this dialog:

FoxyDialog("Covid-19 crazy warning - See the timer -->", ;
    "Please stay home!", ;
    " - Clean your hands often." + CHR(13) + ;
    " - Avoid close contact with people who are sick." + CHR(13) + ;
    " - Stay at home as much as possible." + CHR(13) + ;
    " - Put distance between yourself and other people." + CHR(13) + ;
    " - If you have a fever, cough and difficulty breathing, seek medical attention." + CHR(13), ;
    "!2", ; && Exlamation default with yellow backgound (default)
    "\More Info_99,I agree_5341,Leave me!_89,Ok_116802", ; && Button captions, 1st button disabled
    2, ;  && Default button
    "8000,<SECS> secs.") && Timeout


As excited as I was about FoxyDialogs, I quickly found that it doesn't work well with ctl32, Carlos Allotti's library of components such as BalloonTips, date pickers, status bars, and so on (I would provide a link but sadly his web site is long gone). Trying to call FoxyDialogs after using a ctl32 component causes an error. So, I had to abandon FoxyDialogs because I use ctl32 in most of my apps.

However, recently on Foxite, Daniele Rieffoli of Italy and Tomislav Sokol of Croatia posted about solutions they'd found to the problem. The problem is that both FoxyDialogs and ctl32 use VFP2C32.fll, a library that provides low-level functions that make it easier to work with some Windows API functions. Unfortunately, they use different versions of VFP2C32.fll, causing the conflict. (You won't find the actual FLL with the ctl32 files; ctl32_vfp2c32.prg, which is called by ctl32 components, creates it in the user's temporary files folder if it doesn't already exist.) If a ctl32 component is used before FoxyDialogs, it loads the older VFP2C32.fll, and FoxyDialogs errors on the BINDEVENTSEX statements in its DialogCreated function (BINDEVENTSEX is one of the functions in VFP2C32.fll) because it expects different parameters than the older library does. Using the newer VFP2C32.fll doesn't work because ctl32_vfp2c32.prg calls InitVFP2C32 and that function no longer exists in the newer library. 

The solution is actually simple: use the version that comes with FoxyDialogs and SET LIBRARY TO it at startup before anything in ctl32 is used. When a ctl32 component is used, it calls ctl32_vfp2c32.prg, but that PRG sees that VFP2C32.fll has already been loaded, so it does nothing. None of the ctl32 components I tested had a problem with the newer library, so now they both work together.

No comments: