Static linking issue and DLLMain

Using Visual Studio 2022 on Windows 11 x64
Using version 4.7 - I have successfully built a sqlcipher.dll which I can load and run perfectly into another dll.

However I’d like to build and link everything into my main dll.

I have defined SQLCIPHER_OMIT_DLLMAIN since my main DLL already has a DLLMain

Everything works until I am exiting and closing the database. Then I get a crash and exception. I’m guessing it’s because sqlcipher_extra_shutdown() is not being called, but this is only a guess.

This is the stack trace

>	ActiveWords.dll!sqlcipher_codec_ctx_free(codec_ctx * * iCtx) Line 111273	C
 	ActiveWords.dll!sqlite3FreeCodecArg(void * pCodecArg) Line 112984	C
 	ActiveWords.dll!sqlite3PagerClose(Pager * pPager, sqlite3 * db) Line 63933	C
 	ActiveWords.dll!sqlite3BtreeClose(Btree * p) Line 76222	C
 	ActiveWords.dll!sqlite3LeaveMutexAndCloseZombie(sqlite3 * db) Line 190860	C
 	ActiveWords.dll!sqlite3Close(sqlite3 * db, int forceZombie) Line 190773	C
 	ActiveWords.dll!sqlite3_close_v2(sqlite3 * db) Line 190817	C
 	ActiveWords.dll!sqlite::database::{ctor}::__l2::<lambda>(sqlite3 * ptr) Line 420	C++
 	[External Code]	
 	ActiveWords.dll!CDatabaseManager::Close() Line 281	C++
 	ActiveWords.dll!CDatabaseManager::~CDatabaseManager() Line 36	C++
 	[External Code]	

Hello @mtissington - I don’t believe this would be an issue related to sqlcipher_extra_shutdown(). That would normally only be called at the point that the library is released and no longer being used. This should happen after sqlite3_close_v2(), so it should be unrelated. The only way I could see there being a problem is if you were calling shutdown before close.

That said, you could certainly call sqlite3_shutdown() (which would in turn call sqlcipher_extra_shutdown() when you are exiting (e.g. from your own DllMain)

Is there anything special or different about the lifecycle on the that database handle being closed? Is it being shared across multiple CDatabaseManagers or anything?