#1237 Including libntdll.a in project causes errors with sprintf


If libntdll.a is added to a project with the following code:

#define UNICODE
#define _UNICODE
#include <windows.h>
#include <stdio.h>

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
wchar_t str[128];
float f = 134.56;
swprintf(str, L"%f", f);
MessageBox(NULL, str, str, MB_OK);
return 0;

the messagebox outputs hieroglyphics. If you remove ntdll.a from the build the output is as expected.
System Configuration:
MinGW 5.1.4 on Windows XP Sp2
gcc 3.4.5
__MINGW32_VERSION 3.15.1
__W32API_VERSION 3.12 And 3.13 (I tried both)


  • Keith Marshall

    Keith Marshall - 2009-01-14

    A quick search for `ntdll.lib', on http://www.google.com/microsoft, brings up a bunch of references to conflicts arising between functions in ntdll.dll and msvcrt.dll. In a VC++ forum posting: http://tinyurl.com/7ow6kf, the MS moderator says:

    > you should NOT link directly to ntdll.dll in a Win 32 application.
    > Use LoadLibrary to access the functions from this dll ...

    Surely, the same would apply when using this library from MinGW, i.e. you should use LoadLibrary() rather than linking with libntdll.a? My guess is that ntdll.dll exports an implementation for swprintf(), which is not consistent with the prototype in scope from stdio.h, (and that prototype is correct, for the msvcrt.dll implementation, which you get when you omit libntdll.a).

  • Keith Marshall

    Keith Marshall - 2009-01-22
    • milestone: --> Waiting_User_Response
    • priority: 5 --> 1
    • status: open --> pending-remind
  • SourceForge Robot

    • status: pending-remind --> closed-remind
  • SourceForge Robot

    This Tracker item was closed automatically by the system. It was
    previously set to a Pending status, and the original submitter
    did not respond within 30 days (the time period specified by
    the administrator of this Tracker).

  • Earnie Boyd

    Earnie Boyd - 2013-01-21
    • labels: w32api (deprecated use WSL) -->
    • status: closed-remind --> closed
    • resolution: --> none
    • category: --> No_User_Response
    • milestone: Waiting_User_Response --> WSL

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks