0

Can anyone tell me whats wrong with this code?
It throws this exception:
A call to PInvoke function 'Web!Web.SQLiteBase::sqlite3_open' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.

The code is as follows:

if (sqlite3_open(baseName, out database) != SQL_OK)
[DllImport("sqlite3.dll", EntryPoint = "sqlite3_open")]
private static extern int sqlite3_open(string filename, out IntPtr db);

I converted it from VB and cannot get it to work properly under .Net framework 4.0

Any help is appreciated!
Thanks

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by gusano79
0

Can anyone tell me whats wrong with this code?
It throws this exception:
A call to PInvoke function 'Web!Web.SQLiteBase::sqlite3_open' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.

[DllImport("sqlite3.dll", EntryPoint = "sqlite3_open")]
private static extern int sqlite3_open(string filename, out IntPtr db);

SQLite is a C library; it needs to use the cdecl calling convention, but the .NET framework uses stdcall by default. The following will probably work:

[DllImport("sqlite3.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "sqlite3_open")]
private static extern int sqlite3_open(string filename, out IntPtr db);

Also, the EntryPoint parameter isn't strictly necessary because it's the same as the method name; if you want smaller (and IMO easier to read) code, you can leave it out:

[DllImport("sqlite3.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern int sqlite3_open(string filename, out IntPtr db);
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.