www org instalar descargar vba sqlite vb6

org - SQLite UDF-Devolución de llamada de VBA



sqlite website (1)

¿Alguien ha intentado pasar una función VBA (o VB6) (a través de AddressOf?) Al SQLite para crear una función UDF ( http://www.sqlite.org/c3ref/create_function.html ).

¿Cómo manejaría VBA los argumentos de devolución de llamada resultantes?

La función a llamar tendría la siguiente firma ...

void ( xFunc) (sqlite3_context , int, sqlite3_value **)


Desafortunadamente, no puede usar una función VB6 / VBA como una devolución de llamada directamente, ya que VB6 solo genera funciones stdcall lugar de las funciones cdecl que SQLite espera.

Tendrá que escribir un dll C para proxy las llamadas hacia adelante y hacia atrás o recompilar SQLite para admitir su propia extensión personalizada.

Después de recompilar su dll para exportar las funciones como stdcall , puede registrar una función con el siguiente código:

''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