nonlinearly
Registered User.
- Local time
- Yesterday, 21:47
- Joined
- Jun 13, 2012
- Messages
- 21
I have made a simple dll with C for use in an Ms Access vba project. The dll makes a new thread and makes use of a vba callback function inside the thread's code. According to MS documentation the vba callback function has to be in a vba module and not in a form's code. Inside the callback function I set a form's filter property. But because of this the Access crashes when the execution it arrives there!!! Why? Other references to form's components have no problem (for example when I set the value of the form's textbox)
The mysterious is that I found the problem exists only when the vba Callback Sub is called from the Thread function (ThreadFunc). If it is called from within dll main thread then form's filter is set ok without crash (!!!)
Thanks
The C dll code compiled with VS 2017:
And here is the code that call the dll function "message" from within vba
The vba Declaration of dll
The vba callback subroutine (resides on a Module according to MS documentation)
The mysterious is that I found the problem exists only when the vba Callback Sub is called from the Thread function (ThreadFunc). If it is called from within dll main thread then form's filter is set ok without crash (!!!)
Thanks
The C dll code compiled with VS 2017:
Code:
#include <windows.h>
#include <stdlib.h>
#include <tchar.h>
typedef void(__stdcall * CallbackFunction)();
DWORD __stdcall ThreadFunc(CallbackFunction Callback) {
Callback();
return 0;
}
__declspec(dllexport) void __stdcall message(CallbackFunction Callback) {
// Array to store thread handles
HANDLE Array_Of_Thread_Handles[1];
Array_Of_Thread_Handles[0] = CreateThread(NULL, 0, ThreadFunc, Callback, 0, NULL);
}
Code:
Private Sub Form_Load()
Call message(AddressOf Callback)
End Sub
Code:
Public Declare Sub message Lib "test.dll" Alias "_message@4" (ByVal Callback As Long)
Code:
Public Sub Callback()
On Error Resume Next
Forms("MyForm").txtTest="test" 'this line executed well and the string "test" appears ok in the form.
Forms("MyForm").Filter="" 'in this line Access crashes out
Forms("MyForm").FilterOn=True
End Sub
Last edited: