Dear Sirs,
I'm attempting to configure a function/subroutine written in PB/Win 8.04 as a "callback function" to an "event scheduler" in the "Universal Library" from "Measurement Computing" (which is a DLL and appears to be written in C/C++). The event scheduler calls the PB routine whenever a certain event occurs, such as when a measurement module completes a scan, experiences an error, or transfers a certain quantity of measurements to a "Windows Global Memory Buffer" (which has already been established by another routine, with great help from individuals on this forum.
)
To initialize the event scheduler, we call "cbEnableEvent" in the Universal Library, and associate an event with a user-written routine (my-routine) by passing a description of the event (EventType, defined as an equate) along with a pointer to my-routine. Other parameters which we pass define the measurement-board-number, a pointer to data I am passing to my-routine, and a more detailed definition of the event (Count), such as the amount of data to transfere before calling my-routine. The header file in C/C++ is the following:
I've created the following declaration for PowerBasic:
Then, in my PowerBasic program, I call cbEnableEvent and associate a specific event (defined elsewhere) to myRoutine and pass myParam as follows:
The documentation for cbEnableEvent says the following about the parameter which defines the CallbackFunc (my-routine):
As for the Callback Function (my-routine), the documentation says the callback function must have the following prototype in C/C++:
I've defined a subroutine in the main program module as follows:
I don't see any evidence that myRoutine is being called no matter which event I initiate into cbEnableEvent, yet there is no error code returned and no evidence of a link failure when running the PB exe.
1. Am I connecting my-routine (written in PowerBasic) correctly to cbEnableEvent?
2. I'm passing a pointer-to-myRoutine (which has a non-zero value) BYVAL to a DLL, but can a DLL access a Function/Sub in the main program source file by means of a pointer?
3. Does PowerBasic implement the "global function" concept mentioned in the documentation?

Sincerely Yours,
John Harvill
I'm attempting to configure a function/subroutine written in PB/Win 8.04 as a "callback function" to an "event scheduler" in the "Universal Library" from "Measurement Computing" (which is a DLL and appears to be written in C/C++). The event scheduler calls the PB routine whenever a certain event occurs, such as when a measurement module completes a scan, experiences an error, or transfers a certain quantity of measurements to a "Windows Global Memory Buffer" (which has already been established by another routine, with great help from individuals on this forum.

To initialize the event scheduler, we call "cbEnableEvent" in the Universal Library, and associate an event with a user-written routine (my-routine) by passing a description of the event (EventType, defined as an equate) along with a pointer to my-routine. Other parameters which we pass define the measurement-board-number, a pointer to data I am passing to my-routine, and a more detailed definition of the event (Count), such as the amount of data to transfere before calling my-routine. The header file in C/C++ is the following:
int EXTCCONV cbEnableEvent(int BoardNum, unsigned EventType, unsigned Count, EVENTCALLBACK CallbackFunc, void *UserData);
DECLARE FUNCTION cbEnableEvent LIB "cbw32.dll" ALIAS "cbEnableEvent" ( BYVAL BoardNum&, _
BYVAL EventType AS DWORD, _
BYVAL Count AS DWORD, _
BYVAL CallBack_Function_Pointer AS DWORD, _
BYREF UserData_FirstElement AS ANY ) AS LONG 'Could also be BYVAL UserData_Pointer to first element of array or user defined type.
BYVAL EventType AS DWORD, _
BYVAL Count AS DWORD, _
BYVAL CallBack_Function_Pointer AS DWORD, _
BYREF UserData_FirstElement AS ANY ) AS LONG 'Could also be BYVAL UserData_Pointer to first element of array or user defined type.
LOCAL myParam AS LONG
LOCAL myRoutinePtr AS DWORD
myRoutinePtr = CODEPTR( myRoutine )
ErrorCode_cbEnableEvent = cbEnableEvent( BoardNum, Event, EventParam, BYVAL myRoutinePtr, BYREF myParam )
LOCAL myRoutinePtr AS DWORD
myRoutinePtr = CODEPTR( myRoutine )
ErrorCode_cbEnableEvent = cbEnableEvent( BoardNum, Event, EventParam, BYVAL myRoutinePtr, BYREF myParam )
The address of or pointer to the user-defined callback function to handle the above event type(s). This function must be defined using the standard call (__stdcall) calling convention. Consequently, Visual Basic programs must define their callback functions in standard modules (.bas) and cannot be object methods. On the other hand, C++ programs can define this callback function as either a global function or as a static member function of a class (however, beware that static members do NOT have access to instance specific data).
As for the Callback Function (my-routine), the documentation says the callback function must have the following prototype in C/C++:
void __stdcall CallbackFunc( int BoardNum, unsigned EventType, unsigned EventData, void* UserData );
SUB myRoutine STDCALL ALIAS "myRoutine" ( BYVAL BoardNum AS LONG, BYVAL EventType AS DWORD, BYVAL EventData AS DWORD, BYREF PassedParameter AS LONG ) EXPORT
1. Am I connecting my-routine (written in PowerBasic) correctly to cbEnableEvent?
2. I'm passing a pointer-to-myRoutine (which has a non-zero value) BYVAL to a DLL, but can a DLL access a Function/Sub in the main program source file by means of a pointer?
3. Does PowerBasic implement the "global function" concept mentioned in the documentation?

Sincerely Yours,
John Harvill
Comment