i'm trying to create a simple windows application but based on a main() entry point since i need to compile it on other platforms.
I found specific directives to do this with visual studio but it seems to work when using /MD runtime library compilation, but crashes when using /MT.
Here is a complete code to reproduce the crash, it fails every time. ==> Just create an empty project with a main.cpp file and set : Projet -> Properties -> C/C++ -> Code Generation -> Runtime Library -> /MT
#pragma comment(linker, "/SUBSYSTEM:WINDOWS")
#pragma comment(linker, "/ENTRY:main")
#pragma comment(linker, "/INCLUDE:mainCRTStartup")
int main(int argc, char** argv)
{
int* a = new int;
delete a;
return 0;
}
This causes the following exception :
ntdll.dll!RtlpWaitOnCriticalSection() Inconnu
ntdll.dll!RtlpEnterCriticalSectionContended() Inconnu
ntdll.dll!RtlEnterCriticalSection() Inconnu
Application.exe!__acrt_lock(__acrt_lock_id _Lock) Ligne 55 C++
Application.exe!heap_alloc_dbg_internal(const unsigned __int64 size, const int block_use, const char * const file_name, const int line_number) Ligne 309 C++
Application.exe!heap_alloc_dbg(const unsigned __int64 size, const int block_use, const char * const file_name, const int line_number) Ligne 450 C++
Application.exe!_malloc_dbg(unsigned __int64 size, int block_use, const char * file_name, int line_number) Ligne 496 C++
Application.exe!malloc(unsigned __int64 size) Ligne 27 C++
[Code externe]
Application.exe!main(int argc, char * * argv) Ligne 9 C++
[Code externe]
But if i use a WinMain entry point, it won't fail :
#pragma comment(linker, "/SUBSYSTEM:WINDOWS")
int main(int argc, char** argv)
{
int* a = new int;
delete a;
return 0;
}
INT WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpCmdLine, INT nCmdShow)
{
return main(1, reinterpret_cast<char**>(&lpCmdLine));
}
I want to complile without MSVCRT external dependency, this is the reason why i'm setting /MT mode.
Do you have any suggestion ? I'm working on this problem for days actually....