C++ and API Considerations

Top  Previous  Next


The Clarion RTL thread handler does not do automatic binding of non-Clarion threads.

This minimizes unnecessary overhead; for example, some COM objects start up to 10 internal threads and Clarion data is not accessed from within them.


If you need access to threaded data or to make calls to Clarion functions from a non-Clarion thread you must use the AttachThreadToClarion() function from the non-Clarion DLL. On the call to AttachThreadToClarion(), instances of threaded variables are allocated and their constructors are called, and so they are available to the thread created by the CreateThread API.


Prototype Information


The AttachThreadToClarion() is prototyped as follows:


Clarion prototype:

AttachThreadToClarion (BOOL),PASCAL

C/C++ prototype:

void PASCAL AttachThreadToClarion (int);

Visual Basic prototype:

Declare Sub AttachThreadToClarion Lib "Clarunx.dll" (ByVal Bool As Boolean)


This AttachThreadToClarion function must be called by the launching thread to attach it to the thread handler in the runtime library. Without this call, any attempt within the thread to use thread dependent Clarion functions and operations (all string and decimal operators, BIND/EVALUATE, ERROR/ERRORCODE, most FILE statements, etc.) will cause a program termination.

The main thread of Clarion programs and all threads started with the START function do not require this call.

The AttachThreadToClarion has a BOOLEAN parameter that is used in the following manner. If AttachThreadToClarion is called with a FALSE ( 0 ) parameter, the runtime library does not allocate instances of threaded variables for this thread and hence, does not initialize them. If the parameter is TRUE ( 1 ), the runtime library allocates instances of threaded variables for the thread and executes the initialization code for them. Any attached threads are detached automatically on their termination.