Calling _Execute() from a different thread

You can only call the _Execute VFP API function from within the same thread that Visual FoxPro uses to load the library. Calling the function from a different thread crashes Visual FoxPro. If you need to execute code originating in a different thread, you can use SendMessage, though. Here's the code for the FLL. First of all, you need a variable to hold the window handle:
HWND hWndMain = NULL;
Next, you need a function that a VFP application calls to register the handle
void FLL_Register( ParamBlk *Param )
{
hWndMain = (HWND) (Param->p[0].val.ev_long);
}


LRESULT Result;
Result = SendMessage( hWndMain, WM_USER, 0, 0 );

Here's the code that loads the FLL and initializes the messaging
Set Library To Sample.FLL Additive
BindEvent( _VFP.Hwnd, 0x400, This, "WndProc" )
FLL_REGISTER( _VFP.Hwnd )

The WndProc routine looks like this.
Procedure WndProc( tnHwnd, tnMsg, tnWParam, tnLParam )
Do case
Case m.tnMsg == 0x400
* do something
Return 2
EndCase
EndProc

The return value (2 in the sample) is passed back to the FLL in the Result value. Similar to _Execute, the FLL is suspended until the VFP program processed the message.