The example of source code (see in the subdirectory testThread) for creation Win32Api-dll (bin/testThread.dll), usage from under the applications VFP 9.0 (and later) (see example in the subdirectory testVfp) to create working thread, in which to fulfil "some long run continued operation"... In that sort as is written right now - to call VFP-COM-component (see example in the subdirectory ComVfpExamp [Do not forget to register ComVfpExamp/vfpcomexamp.dll through regsvr32 before attempts of usage]), not having the visible interface.

For transmission to working thread the information on that: which VFP-component, what method and with what values of parameters is required to be called the XML-file is used, more correct, the XML-string obtained from the XML-file (see examples in the subdirectory xml) is used:
- ComVfpExamp_TestTypes.xml - example of datas for call to method TestTypes from vfpcomexamp.testvfp
- ComVfpExamp_LongRun.xml - example of datas for call to method LongRun from vfpcomexamp.testvfp
- ComVfpExamp_GetTable.xml - example to call method GetTable from vfpcomexamp.testvfp [the method GetTable allows to convert the data of the table, given as parameter to xml-string. In turn, in testVfp/frmtestthread.scx the method ConvertToTable() can recognize, that string returned by a method is xml-submission of the table and convert last into VFP-cursor, which one is imaged through a VFP-command BROWSE]

The structure of any xml-file should obey to the file templateThreadData.xsd. See also in the subdirectory xml/template the standard file-template templateThreadData.xsd, and file templateThreadData.xml, in which the empty elements as possible versions of filling are placed. There file Automation_VARIANTandVARIANTARG.doc - also lies as copy of documentation from MSDN for the specification of data types in structure VARIANT.

The specification such as an option value is necessary then, when the type of the parameter can not be a priori is defined, for example, when:
- in list of parameters of the function abstract type was indicated such as VARIANT (myAnyParam as Variant) (or is not preset through as...), i.e. from typelib there is no possibility precisely to know the type of value
- and in the xml-file naturally we have string only... :- (

For the precise indicating: what an actual type of parameter value, - the attribute 'type' for element Param is used, for example in fragment:
<Param name="tnTimeOutSec" type="VT_I4">
 <Value>20</Value>
</Param>
for the parameter 'tnTimeOutSec' with value 20 specifies the type LONG (see details in Automation_VARIANTandVARIANTARG.doc)

NOTICE! In that sort "as is" there is a couple of limitations:
- at first, the given version CAN NOT perceive parameters "by reference", only "by value"! Therefore unique possibility to return the calculated values from VFP-COM-component are usages of a VFP-command RETURN
- secondly, in the present moment, the works with the ARRAYS IS NOT SUPPORTED, only with 'scalar variables'
At violation of these limitations 'the behaviour undefined' ...:-( In other words, all parameters + returned value should be as scalar value only... and are typed through As... And in case of usage in the description an abstract type Variant, the type of a concrete input-parameters should be indicated through values of attribute 'type' for the appropriate parameter in xml-file.

The result of works is returned through modified XML-strings, is more exact that was conveyed 'as input'... the element <Results> is added, and in case of errors the element <Error> is added also (see in xml/template files: templateThreadData.xml and templateThreadData.xsd)

NOTICE! All initial XML-files should be in the coding UTF-8, resulting XML-files in an example also in the coding UTF-8. (Use even "Notepad" OS Windows to be sure, that your initial XML-files in UTF-8)

At last, the example of a call from VFP is in the subdirectory testVfp as form frmtestthread.scx, for starting do follows:
- by use the button [To select the XML-file...] select the concrete xml-file from the subdirectory xml
- and to push the button [Start]
On termination of thread, if the mode "Will show result on completion" is switched to on before, the html-document-report should appear...:-) you also can use the button [Show result...] to view this report in MS IE

ATTENTION! After start of thread, push button "Start" passes in a mode "Terminate", untile the thread will not be completed. Formally, in a run time of the thread It is possible to click on the button "Terminate", and it will cause to call Win32API function TerminateThread (), but it will not mean, that the thread will be immediately terminated without consequences, while the control above it will be lost: 
- If you do not create VFP-COM-component in "Component Service" (COM +) (or under MS MTS) in multithreading mode, usage of a command "Terminate" probably, if only you COLLECT TO TERMINATE PROCESS AT ONCE AFTER THAT. Otherwise, you any more will not manage to earlier started & interrupted component so long as you do not terminate all process.
- If you create VFP-COM-component in "Component Service" (COM +) (or under MS MTS) [OS Windows NT4 or later], the control of multithreading in "Component Service", and in this case, the button "Terminate" can be used, but be cautious. Though after terminating of  thread you can again start earlier interrupted component, however each such interrupted of the component will not be more controlled by you, and will remain in an inactive condition to exist in the server-site application so long as you do not forced completion client-site process.
Thus, usage of a command "Terminate" always is involved in consequences... I advise very closely to learn behavior in your conditions before to decide usage...:- (

That was used at writing:
- MS VFP 9.0
- MS VC ++. NET from MS VS 2003 SP1
- MS IE 6.0 SP1
- Microsoft XML Core Services (MSXML) 4.0 (SP2) & SDK [C:\Program Files\MSXML 4.0\[include|lib]]
all it is necessary for you, if you will have desire to change the code...

Where/that to correct for change "the view language"
- testVfp\frmtestthread.h, ComVfpExamp\main.prg (#DEFINE LANG_RUS_LOC .T. && for Russian (.F. for English))
- testThread\stdafx.h if exist definition #define LANG_RUS_LOC - for Russian, otherwise for English
- change a contents of the file in xml\Result.xslt on taken contents from xml\template\ResultRu.xslt for Russian and on taken from contents xml\template\ResultEn.xslt for English

Best regards.
Michael Drozdov, ICS Soft, Perm, Russia
My Page:  http://vfpdev.narod.ru/







  

 





