Pelles C forum

C language => Expert questions => Topic started by: TimoVJL on April 21, 2007, 03:56:13 pm

Title: msvcrt.lib support
Post by: TimoVJL on April 21, 2007, 03:56:13 pm
Is this correct way to get stderr to work ?

Code: [Select]
#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 x64
Code: [Select]
typedef struct FAKEFILE {
char *_ptrs[3];
int _ints[5];
} FILE;
Title: Re: msvcrt.lib support
Post by: Vortex on May 19, 2007, 12:20:00 pm
timovjl,

Your code works fine :
Code: [Select]
#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;
}

Code: [Select]
stdout = 77C4FCA0
stderr = 77C4FCC0