News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

msvcrt.lib support

Started by TimoVJL, April 21, 2007, 03:56:13 PM

Previous topic - Next topic

TimoVJL

Is this correct way to get stderr to work ?


#include <stdio.h>

#define MSVCRT
// msvcrt-supp.h
#ifdef MSVCRT
typedef struct FAKEFILE {
char fake[0x20];
} FAKEFILE;
__declspec(dllimport) extern FAKEFILE _iob[];
#undef stdin
#define stdin  (FILE*)(&_iob[0])
#undef stdout
#define stdout (FILE*)(&_iob[1])
#undef stderr
#define stderr (FILE*)(&_iob[2])
#pragma lib "msvcrt.lib"
#endif

int main(int argc, char **argv)
{
int size = sizeof(FILE);

fprintf(stdout, "stdout\n");
fprintf(stderr, "stderr\n");
return 0;
}

EDIT: for x64typedef struct FAKEFILE {
char *_ptrs[3];
int _ints[5];
} FILE;
May the source be with you

Vortex

timovjl,

Your code works fine :

#include <stdio.h>

#define MSVCRT
// msvcrt-supp.h
#ifdef MSVCRT
typedef struct FAKEFILE {
char fake[0x20];
} FAKEFILE;
__declspec(dllimport) extern FAKEFILE _iob[];
#undef stdin
#define stdin  (FILE*)(&_iob[0])
#undef stdout
#define stdout (FILE*)(&_iob[1])
#undef stderr
#define stderr (FILE*)(&_iob[2])
#pragma lib "msvcrt.lib"
#endif

int main(int argc, char **argv)
{
int size = sizeof(FILE);

fprintf(stdout, "stdout = %X\n",stdout);
fprintf(stderr, "stderr = %X\n",stderr);
return 0;
}

stdout = 77C4FCA0
stderr = 77C4FCC0
Code it... That's all...