Results 1 to 2 of 2
  1. #1
    nonlinearly is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2019

    DLL with callback problem

    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 (message function) then form's filter is set ok without crash (!!!)

    Is this a bug o MS ACCESS?


    The C dll code compiled with VS 2017:
    #include <windows.h>
    #include <stdlib.h>
    #include <tchar.h> 
    typedef void(__stdcall * CallbackFunction)();
    DWORD __stdcall ThreadFunc(CallbackFunction 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);
    And here is the code that call the dll function "message" from within vba
    Private Sub Form_Load()
        Call message(AddressOf Callback)
    End Sub
    The vba Declaration of dll
     Public Declare Sub message Lib "test.dll" Alias "_message@4" (ByVal Callback As Long)
    The vba callback subroutine (resides on a Module according to MS documentation)
     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
    End Sub

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Ontario, Canada
    cross posted - see post 31 "Third"
    - "doesn't work" doesn't help. Implement changes in copies of your database.
    "Everyone has a photographic memory; some just don't have film." Steven Wright

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Access 2010 Ribbon QAT Callback Error
    By Stephen in forum Access
    Replies: 4
    Last Post: 07-03-2018, 08:52 AM
  2. Replies: 9
    Last Post: 07-06-2015, 01:47 AM
  3. Replies: 2
    Last Post: 10-31-2012, 11:52 AM
  4. Replies: 2
    Last Post: 06-14-2010, 03:25 PM
  5. query problem i have a problem wi
    By maxx3 in forum Queries
    Replies: 0
    Last Post: 06-29-2009, 02:29 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Other Forums: Microsoft Office Forums - Senior Forums