如果你用的是VC,那么可以使用下面的代码:FILE * f;
// ...
extern  int _osfhnd[];
HANDLE hFile=_osfhnd[fileno(f)];谁还有更好的办法?

解决方案 »

  1.   

    thx but it can not be used in multithreading program.
      

  2.   

    typedef struct {
            long osfhnd;    /* underlying OS file HANDLE */
            char osfile;    /* attributes of file (e.g., open in text mode?) */
            char pipech;    /* one char buffer for handles opened on pipes */
    #ifdef _MT
            int lockinitflag;
            CRITICAL_SECTION lock;
    #endif
        }   ioinfo;#define IOINFO_L2E          5
    #define IOINFO_ARRAY_ELTS   (1 << IOINFO_L2E)
    #define _pioinfo(i) ( __pioinfo[(i) >> IOINFO_L2E] + ((i) & (IOINFO_ARRAY_ELTS -                               1)) )
    #define _osfhnd(i)  ( _pioinfo(i)->osfhnd )然后调用_osfhnd(i) 即可
      

  3.   

    少了,还有extern "C" _CRTIMP ioinfo * __pioinfo[];