I am writing a program which works if... Or works not if... - see the next lines... :-) ...
The program has one part, mainly GUI- and User-Interaction.
The other part is a DLL. In the DLL there are readouts over RS232 from a external controller-board. Sometimes the controller-board needs some time (known how much) and this time must pass by then the result can be read out from the controller board ... and so on ...
By not blocking the GUI-User-Program for waiting the return-value of the the DLL-functions (which need some seconds to be finished) I start in the DLL a thread with
CmtScheduleThreadPoolFunction(DEFAULT_THREAD_POOL_HANDLE, THREAD_FunctionX, &tmpTFP, NULL);
with "tmpTFP" as a type-instance of "TYPE_THREAD_FUNCTION_PARAMETERS":
typedef struct
{
//
int IntVal1; // 1. Integer-Wert
int IntVal2; // 2. Integer-Wert
int IntVal3; // 3. Integer-Wert
int IntVal4; // 4. Integer-Wert
int IntVal5; // 5. Integer-Wert
//
int IntBuffer1[32]; // 1. Integer-Buffer (aktuell genügt einer)
//
double DblVal1; // 1. Double-Wert
double DblVal2; // 2. Double-Wert
double DblVal3; // 3. Double-Wert
double DblVal4; // 4. Double-Wert
double DblVal5; // 5. Double-Wert
//
char CharVal1; // 1. (Einzel-)Char-Wert
char CharVal2; // 2. (Einzel-)Char-Wert
char CharVal3; // 3. (Einzel-)Char-Wert
char CharVal4; // 4. (Einzel-)Char-Wert
char CharVal5; // 5. (Einzel-)Char-Wert
//
char CharBuffer1[1024]; // 1. Char-Buffer (akutell genügt einer)
//
} TYPE_THREAD_FUNCTION_PARAMETERS;
In the GUI-User-Program I get quick a default-return-value of the thread-starting function.
Then I poll the DLL (some global state-variables are used for that) when it is finished.
Depending on the contacted (RS232) controller-board the waiting time depends on the "mood" of the controller-board.
In the DLL-polling-routine of the GUI-User-Program now everything is working fine - without using "SetCtrlVal" !
In my GUI there is a info/comment text-box for messages. If I make some User-Outputs by using "SetCtrlVal" I get always errors, caused by wrong "TYPE_THREAD_FUNCTION_PARAMETERS"-values in the thread-function. If I set a break-point at the thread-function start I see mostly false values in my transfer-structure-variables. If I set a break-point at the thread-function-caller "CmtScheduleThreadPoolFunction(...)" and at the beginning of the thread the values are (mostly) correct!
I tried many and different things - but:
If I ONLY (!) commenting out the one (!) line with "SetCtrlVal" the program works, all states are polled well out of the DLL.
If I replace the "SetCtrlVal" with a own written logging-file function everything works fine and after the program finished I can watch the log-file and see all user-info's. BUT with "SetCtrlVal" instead or together or (...) it does not work.
Maybe my description is not totaly clear, but believe me: ONLY ONE line - the "SetCtrlVal"-line - must be comented out to let the program work fine!
Because if the "SetCtrlVal"-line is in GUI-User-program, after the thread-call in the DLL, the DLL-Memory seems to be corrupted by the "SetCtrlVal"-Call in the GUI-User-program.
Best regards,
F.