Gregor, to add to Gregery's post, you may also wish to investigate the article on using PB to create multithreaded VB applications...
Multithreading Article for PB and VB: http://www.powerbasic.com/support/te...threading3.asp
------------------
Lance
PowerBASIC Support
mailto:[email protected][email protected]</A>
Announcement
Collapse
No announcement yet.
Newbi: Ansynchron Function Call
Collapse
X
-
Greg,
Here is some basic PB and VB code for you. To fully understand
everything you need to first do some reading on THREAD CREATE
and do some side reading on CRITICAL_SECTION on MSDN. In any
case here it is.
PBDLL CODE
Code:#COMPILE DLL "C:\TEST.DLL" #INCLUDE "win32api.inc" GLOBAL LStop& FUNCTION DoSomething(x AS LONG) AS LONG OPEN "C:\APP.LOG" FOR APPEND AS #1 WHILE lStop& = %FALSE PRINT #1, DATE$ & " " & TIME$ & " TEST!" WEND CLOSE #1 END FUNCTION FUNCTION PBDoSomething() EXPORT AS LONG THREAD CREATE DoSomething(0) TO woot& END FUNCTION FUNCTION PBStopDoSomething() EXPORT AS LONG lStop& = %TRUE END FUNCTION
Code:Declare Sub PBDoSomething Lib "C:\TEST.DLL" Alias "PBDOSOMETHING" () Declare Sub PBStopDoSomething Lib "C:\TEST.DLL" Alias "PBSTOPDOSOMETHING" ()
function names that are exported are in UPPER Case, you can use the
alias statement in PB to change that.
To make this example fully thread safe you need to add
InitializeCriticalSection around Global/Static variables. Sorry
I have to jet to work.
Hope that helps.
------------------
-Greg
[This message has been edited by Gregery D Engle (edited October 16, 2001).]
Leave a comment:
-
Newbi: Ansynchron Function Call
Hi,
I would like to call a PB Function from an VB Application.
The VB aplication should carry on with its work, and the PB function should run parallel.
The VB app calls then a PB stop function, and the previosly started PB function should come to an end.
Symbolic Example:
VB Code:
Sub Main()
....
PBDoSomething 'Ansync call to the PB Function
.....
.....
PBStopWithDoSomething
End Sub()
PB Code:
Private Stop As Boolean
Sub PBDoSomething()
Do
....
Loop Until Stop
End Sub
Sub PBStopWithDoSomething()
Stop = True
End Sub
Is this possible???
Greg
------------------
Tags: None
Leave a comment: