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

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);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.