Foxpert Software Development & Consulting

Menu

Whitepapers
Downloads
Knowlbits
Guineu

2006-09Sep-26

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);
}

Finally, whenever you wanted to use _Execute(), you use code like this instead

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.

Previous KnowlBits

RSS

February 2011 (2)

December 2010 (1)

October 2009 (2)

September 2009 (1)

August 2009 (4)

July 2009 (2)

June 2009 (2)

May 2009 (1)

April 2009 (1)

March 2009 (1)

August 2008 (1)

July 2008 (2)

May 2008 (1)

April 2008 (2)

January 2008 (2)

December 2007 (2)

November 2007 (2)

October 2007 (1)

September 2007 (1)

August 2007 (5)

July 2007 (4)

May 2007 (6)

March 2007 (3)

February 2007 (7)

January 2007 (6)

November 2006 (1)

October 2006 (3)

September 2006 (10)

June 2006 (2)

May 2006 (6)

April 2006 (1)


Impressum Kontakt Contact