in Education by
Has anybody attempted to pass a VBA (or VB6) function (via AddressOf ?) to the SQLite create a UDF function (http://www.sqlite.org/c3ref/create_function.html). How would the resulting callback arguments be handled by VBA? The function to be called would have the following signature... void (xFunc)(sqlite3_context,int,sqlite3_value**) JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Unfortunately, you can't use a VB6/VBA function as a callback directly as VB6 only generates stdcall functions rather than the cdecl functions SQLite expects. You will need to write a C dll to proxy the calls back and forth or recompile SQLite to to support your own custom extension. After recompiling your dll to export the functions as stdcall, you can register a function with the following code: 'Create Function Public Declare Function sqlite3_create_function Lib "SQLiteVB.dll" (ByVal db As Long, ByVal zFunctionName As String, ByVal nArg As Long, ByVal eTextRep As Long, ByVal pApp As Long, ByVal xFunc As Long, ByVal xStep As Long, ByVal xFinal As Long) As Long 'Gets a value Public Declare Function sqlite3_value_type Lib "SQLiteVB.dll" (ByVal arg As Long) As SQLiteDataTypes 'Gets the type Public Declare Function sqlite3_value_text_bstr Lib "SQLiteVB.dll" (ByVal arg As Long) As String 'Gets as String Public Declare Function sqlite3_value_int Lib "SQLiteVB.dll" (ByVal arg As Long) As Long 'Gets as Long 'Sets the Function Result Public Declare Sub sqlite3_result_int Lib "SQLiteVB.dll" (ByVal context As Long, ByVal value As Long) Public Declare Sub sqlite3_result_error_code Lib "SQLiteVB.dll" (ByVal context As Long, ByVal value As Long) Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As Any, source As Any, ByVal bytes As Long) Public Property Get ArgValue(ByVal argv As Long, ByVal index As Long) As Long CopyMemory ArgValue, ByVal (argv + index * 4), 4 End Property Public Sub FirstCharCallback(ByVal context As Long, ByVal argc As Long, ByVal argv As Long) Dim arg1 As String If argc >= 1 Then arg1 = sqlite3_value_text_bstr(ArgValue(argv, 0)) sqlite3_result_int context, AscW(arg1) Else sqlite3_result_error_code context, 666 End If End Sub Public Sub RegisterFirstChar(ByVal db As Long) sqlite3_create_function db, "FirstChar", 1, 0, 0, AddressOf FirstCharCallback, 0, 0 'Example query: SELECT FirstChar(field) FROM Table End Sub

Related questions

0 votes
    I store many sub records as Map in the same top record, now I need remove some sub records ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 26, 2022 in Education by JackTerrance
0 votes
    I saw an article on creating Excel UDFs in VSTO managed code, using VBA: http://blogs.msdn.com/ ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    I have a table in my android app with a column named tags, this column can contain one or ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    I would like to take a list of names (e.g. john, mary, paul) and create a SQLite "select" ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    The question is pretty self-explanatory. I'm looking for a PostgreSQL equivalent to the SQLite datetime ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 16, 2022 in Education by JackTerrance
0 votes
    I need a standard deviation function in SQLite. I have found one here: http://www.sqlite.org/contrib ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    I've met an unknown error while inserting data into the database. The LogCat had been display "unable to insert data", ... I placed into my onClick(), it failed. onStart():...
asked Feb 9, 2022 in Education by JackTerrance
0 votes
    I've met an unknown error while inserting data into the database. The LogCat had been display "unable to insert data", ... I placed into my onClick(), it failed. onStart():...
asked Feb 5, 2022 in Education by JackTerrance
0 votes
    As it currently stands, this question is not a good fit for our Q&A format. We expect answers to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jan 13, 2022 in Education by JackTerrance
0 votes
    Which of the following option/options are the advantages of SQLite? (1)Reliable (2)Better Performance (3)Accessible (4)All the options...
asked May 20, 2021 in Technology by JackTerrance
0 votes
    I need to react in a main process to random events happening in a child process. I have implemented ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 27, 2022 in Education by JackTerrance
0 votes
    I have questions regarding the execution order of async jobs. I will ask my question with example because ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 3, 2022 in Education by JackTerrance
0 votes
    I wait for onCharacteristicChanged() callbacks to receive data via BLE. But if the BluetoothDevice sends too ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 18, 2022 in Education by JackTerrance
0 votes
    I have questions regarding the execution order of async jobs. I will ask my question with example because ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 8, 2022 in Education by JackTerrance
0 votes
    I have added the Google Translate plugin to my web page. How can I get a callback to my ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
...