NO

Author Topic: msvcrt.lib support  (Read 2213 times)

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 1633
msvcrt.lib support
« 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;
« Last Edit: August 02, 2016, 09:54:48 am by TimoVJL »
May the source be with you

Offline Vortex

  • Member
  • *
  • Posts: 501
    • http://www.vortex.masmcode.com
Re: msvcrt.lib support
« Reply #1 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
Code it... That's all...