views:

70

answers:

1

I'm compiling both a 32-bit and 64-bit SQLite library with Microsoft Visual C++ from the command line for a simple C# wrapper. The 32-bit version works fine, but the 64-bit version crashes my application completely when sqlite3_prepare_v2 returns anything but SQLITE_OK.

build.bat

set ARGS=/nologo /LD /DSQLITE_ENABLE_COLUMN_METADATA sqlite3.c /link /def:sqlite3.def

call vcvars32.bat
cl %ARGS% /out:sqlite3.dll

call vcvars64.bat
cl %ARGS% /out:sqlite3_64.dll

C# code (relevant bits)

public delegate int _sqlite3_prepare_v2(IntPtr db, string zSql, int nByte, out IntPtr ppStmt, out IntPtr pzTail);

public static readonly _sqlite3_prepare_v2 sqlite3_prepare_v2;

IntPtr tail;
if (SQLite.sqlite3_prepare_v2(_db.Handle, text, -1, out _handle, out tail) != SQLite.SQLITE_OK)
    throw new SQLiteException(_db);

The functions are bound at runtime so that I can compile for Any CPU and choose which version of the library to use. When I run this on a 64-bit system, I get this:

vshost-clr2.exe has stopped working
Problem signature:
  Problem Event Name:       APPCRASH
  Application Name:         SQLiteTest.vshost.exe
  Application Version:      10.0.30319.1
  Application Timestamp:    4ba2084b
  Fault Module Name:        StackHash_4a05
  Fault Module Version:     6.1.7600.16559
  Fault Module Timestamp:   4ba9b802
  Exception Code:           c0000374
  Exception Offset:         00000000000c6df2
  OS Version:               6.1.7600.2.0.0.256.48
  Locale ID:                1033
  Additional Information 1: 4a05
  Additional Information 2: 4a055724055f1d4270656b7cd547877a
  Additional Information 3: 92b7
  Additional Information 4: 92b737f393457f0de2d4edb6b32c0617

Any ideas?

EDIT: The message I get when debugging the application is:

A heap has been corrupted

A: 

SQLITE_MISUSE implies that you're using the library in a bad way. If you can change your code to not trigger that in 32-bit, I suspect that your 64-bit crash will go away.

Wez Furlong
Sorry, I got the calls mixed up in my log. `sqlite3_prepare_v2` is not returning `SQLITE_MISUSE`, but `sqlite3_step` is because `sqlite3_prepare_v2` is returning `SQLITE_ERROR` when the table is trying to be created a second time. The 64-bit crash must be something else.
David Brown