common define for testing msvcrt.dll

Started by TimoVJL, April 25, 2025, 05:48:12 PM

Previous topic - Next topic

TimoVJL

It would be nice, if we use same define for testing code with msvcrt.dll too.
For example USE_MSVCRT or similar, what we decide.
If you have better name, just tell us.
May the source be with you

Vortex

Hi Timo,

Maybe, an add-in can do the job. You need to disable the run-time library of Pelles C and use a custom C run-time library as msvcrt.dll's command-line handling depends on these functions :

https://learn.microsoft.com/en-us/cpp/c-runtime-library/getmainargs-wgetmainargs?view=msvc-170

With a batch file, you can easily accomplish the linkage against msvcrt.dll
Code it... That's all...

TimoVJL

#2
Almost same, this might be an example to avoid mistakes
and others knows case#ifdef USE_MSVCRT
#pragma comment(lib, "msvcrt.lib")
#endif
#ifdef USE_MSVCRT
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

#ifdef UNICODE
#define WINMAIN wWinMain
void __cdecl wWinMainCRTStartup(void) // for PellesC Microsoft C etc...
#else
#define WINMAIN WinMain
void __cdecl WinMainCRTStartup(void)
#endif
{
TCHAR *szCmdLine;
STARTUPINFO si;

szCmdLine = GetCommandLine();
if (*szCmdLine == '"')
{
while (*++szCmdLine)
if (*szCmdLine == '"')
{
szCmdLine++;
break;
}
}
else
{
while (*szCmdLine && *szCmdLine > ' ')
szCmdLine++;
}
while (*szCmdLine && *szCmdLine <= ' ')
szCmdLine++;

GetStartupInfo(&si);
ExitProcess(WINMAIN(GetModuleHandle(NULL), NULL, szCmdLine,
(si.dwFlags & STARTF_USESHOWWINDOW)
? si.wShowWindow : SW_SHOWDEFAULT));
}
#undef WINMAIN
#endif
May the source be with you

Vortex

Hi Timo,

Thanks for your code. My idea is to combine msvcrt.lib with a static library :

https://forum.pellesc.de/index.php?topic=10943.0

This time, I combined my tiny C startup library with msvcrt.lib

Your module above is a very good implementation.
Code it... That's all...