1

Test program source:

int main(){
    MessageBoxA(0,"show msgbox ok, but exit has issue","0 LPCSTR lpCaption",0);  
    printf("[2]\n");
    printf("[3]\n");
    printf("[4]\n");
    return 0;
}

And then compile it tcc\tcc msgbox.c tcc\lib\user32.def

msgbox.exe
echo %errorlevel%

-1073741795

If I remove MessageBoxA API call, echo %errorlevel% is 0

tcc\tcc -v

tcc version 0.9.26 (i386 Win32)

--EDIT--

tcc-0.9.27-win64 work properly

tcc64\tcc -v
tcc version 0.9.27 (x86_64 Windows)

>tcc64\tcc msgboxPid.c tcc64\lib\kernel32.def tcc64\lib\user32.def
msgboxPid.c:9: warning: implicit declaration of function 'MessageBoxA'
msgboxPid.c:10: warning: implicit declaration of function 'printf'

>msgbox.exe
[2]
[3]
[4]

>echo %errorlevel%
0

CS QGB
  • 186
  • 1
  • 2
  • 11
  • 3
    `c000001d` is "illegal instruction" exception code. Related: [Windows 10 app with dynamically linked VC++ does not start even after installation of VC++ 2017 redistributable](https://stackoverflow.com/questions/53651182/windows-10-app-with-dynamically-linked-vc-does-not-start-even-after-installati) – Weather Vane Mar 28 '21 at 09:30
  • 1
    I guess there are some missing part of the code (includes)? – OznOg Mar 28 '21 at 09:34
  • If this is complete code you didn't add the include for the function that contains prototype of `MessageBoxA`, which might already be the reason. If this is not the complete code then your question lacks [mre]. – Antti Haapala -- Слава Україні Mar 28 '21 at 09:39
  • @OznOg no include It still can pass compile – CS QGB Mar 28 '21 at 09:40
  • @CSQGB then add that include. It is widely known that C code without includes is wrong but still compiles, and TCC lacks diagnostics. – Antti Haapala -- Слава Україні Mar 28 '21 at 09:41
  • Did the message box open or did the program not get that far? Why not just use the usual `MessageBox()` function? Another relevance: [Should an application calling MessageBoxA() always terminate by ExitProcess() instead of normal function epilogue?](https://stackoverflow.com/questions/40408848/should-an-application-calling-messageboxa-always-terminate-by-exitprocess-in) – Weather Vane Mar 28 '21 at 09:45
  • @WeatherVane show msgbox ok, but exit has issue。 – CS QGB Mar 28 '21 at 12:08
  • 3
    Your "implicit declaration" warnings suggest you have forgotten to `#include ` and `#include `. – Adrian Mole Mar 28 '21 at 12:14
  • 1
    Yes, deal with compiler warnings before raising fault issues! – Weather Vane Mar 28 '21 at 12:31
  • If you include the call to `MessageBoxA()` and run it, does it print "[2]" to "[4]"? – the busybee Mar 28 '21 at 12:32
  • In the "Edit" I don't understand why the version that uses `MessageBoxA()` (we know that because of the compiler warning) is returning `0`. This question lacks clarity and a [Minimal Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). – Weather Vane Mar 28 '21 at 12:35

0 Answers0