SQLite Forum

Using sqlite3_load_extension on windows
Login
I found that if the entry point was declared with __stdcall the function name had no leading underscore in dependency walker. Thought that was that but alas no. Using the code below, line // 1 doesn't return SQLITE_OK and line // 2 gives an exception with message "privileged instruction at 0x004f158a" in console.exe. I've googled the error but I can't see anything that would cause a memory overwrite.

lite32c.dll file
//---------------------------------------------
#include <sqlite3ext.h>

SQLITE_EXTENSION_INIT1

#ifdef _WIN32
__stdcall __declspec(dllexport)
#endif

int sqlite3_lite32c_init(
  sqlite3 *db,
  char **pzErrMsg,
  const sqlite3_api_routines *pApi
){
  int rc = SQLITE_OK;
  SQLITE_EXTENSION_INIT2(pApi);

  return rc;
}
//---------------------------------------------
console.exe file
//---------------------------------------------
#ifdef _WIN32
#include <tchar.h>
#else
  typedef char _TCHAR;
  #define _tmain main
#endif

#include "sqlite3.c"
int _tmain(int argc, _TCHAR* argv[])
{
  sqlite3 *db;
  sqlite3_open(":memory:",&db);
  int rc;
  sqlite3_db_config(db,SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION,1,&rc);
  rc=sqlite3_load_extension(db,"c:/temp/Win32/Debug/lite32c.dll",0,0); // 1
  rc=sqlite3_load_extension(db,"c:/temp/Win32/Debug/lite32c.dll",      // 2
  "sqlite3_lite32c_init",0);
  return 0;
}
//---------------------------------------------