这样的错误是怎么回事? '_far' is an obsolete keyword [所有相关帖子] 
下面的程序可能是头文件出了问题,帮忙看看。#include  <windows.h>
#include <string.h>
#include <stdio.h>
#define        EXPORTAPI _far _pascal _export _loadds ……
int _far _pascal  _loadds getgnPageLength( hDC, height)
HDC        hDC;
int        height;
{
    RECT clipBox;
    GetClipBox( hDC, ( LPRECT )&clipBox);
    return max( ( ( (clipBox.bottom - clipBox.top) / height) - 2 ), 0);
}
出错信息:
:\temp\new\print.c(46) : error C4226: nonstandard extension used : '_far' is an obsolete keyword
d:\temp\new\print.c(46) : error C4226: nonstandard extension used : '_pascal' is an obsolete keyword
d:\temp\new\print.c(55) : error C4226: nonstandard extension used : '_far' is an obsolete keyword
d:\temp\new\print.c(55) : error C4226: nonstandard extension used : '_pascal' is an obsolete keyword……

解决方案 »

  1.   

    16位的程阿。
    _far, _pascal在32位环境都已经被废弃了。你可以这样,在头文件最前边加上
    #define _far
    #define _pascal
      

  2.   

    #define _fstrlen(s) strlen(s)
      

  3.   

    回复人: ndy_w(carpe diem) ( ) 信誉:100  2003-05-06 09:53:00  得分:0 
     
     
      #define _far
    #define _pascal
      
    _______________________________________________________________________ 
     
      回复人: VisualStudio(嗷~~~) ( ) 信誉:100  2003-05-06 15:32:00  得分:0 
     
     
      在VC中取消了_far和_pascal
    所以用VC编程不需要_far和_pascal______________________________________________________________________
    修改 文件的前面一部分后,编译通过,但build时又出现了新问题:
    #include  <windows.h>
    #include <string.h>
    #include <stdio.h>
    //#define EXPORTAPI _far _pascal _export _loadds 
    #define _far
    #define _pascal
    #define _fstrlen(s) strlen(s)#define EXPORTAPI __declspec(dllexport) __stdcall#define MM 7.092
    #define cvt(x) ( (int)((x) * MM) )出错信息:
    D:\temp\newbak1\Print.c(102) : warning C4133: 'function' : incompatible types - from 'char *' to 'const struct _devicemodeA *'是不是下面用到的函数CreateDC也是一个16位的函数?if (!(ghPrintDC = CreateDC((LPSTR) pchFile, (LPSTR) device,
    (LPSTR) pchPort,(LPSTR) NULL)))
    {
    if (ghPrintDC)
    DeleteDC(ghPrintDC);
    return FALSE;
    }
      

  4.   

    CreateDC((LPSTR)pchFile, (LPSTR)device, (LPSTR)pchPort,(DEVMODE*)NULL)))
      

  5.   

    又改了一下,编译通过,Print.obj - 0 error(s), 0 warning(s)
    但是运行的时候出错:
    --------------------Configuration: Print - Win32 Debug--------------------
    Linking...
       Creating library Debug/Print.lib and object Debug/Print.exp
    LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
    Debug/Print.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.
    、这个程序是一个DLL的打印程序,下面是部分代码:
    #include  <windows.h>
    #include <string.h>
    #include <stdio.h>
    //#define EXPORTAPI _far _pascal _export _loadds 
    #define _far 
    #define _pascal 
    #define _fstrlen(s) strlen(s)#define EXPORTAPI __declspec(dllexport) __stdcall#define MM 7.092
    #define cvt(x) ( (int)((x) * MM) )#define X_START (0 + cvt(10))
    #define Y_START (7)
    #define FontWidthE 15
    #define FontWidthC 30#define  PART3X  80
    #define  PART3Y      504
    #define LINE 43
    #define  PART4X  30
    #define  PART4Y      (PART3Y + LINE * 14 - 10)
    /*1106*/
    char            gszTempFileName[]="Testp";
    int gnPageLength;
    int gnLineLength;
    int gnChrPrtHeight;
    int gnChrPrtWidth;
    int gnPrtLine;
     
    BYTE *hpch;static int gnCharCount;
    static int  nCount = 0;
    unsigned long glTestLength;
    HDC ghPrintDC;
    HFONT oldFontRecord,newFontRecord;#define TMPNSTR 80
    #define CR 13
    #define LF 10int _far _pascal  _loadds getgnPageLength( hDC, height)
    HDC hDC;
    int height;
    {
    RECT clipBox;
    GetClipBox( hDC, ( LPRECT )&clipBox);
    return max( ( ( (clipBox.bottom - clipBox.top) / height) - 2 ), 0);
    }int _far _pascal  _loadds  getgnLineLength( hDC, width )
    HDC hDC;
    int width;
    {
    RECT clipBox;
    GetClipBox ( hDC, ( LPRECT )&clipBox );
    return max( ( ( (clipBox.right - clipBox.left) / width) - 2 ), 0);
    }
    BOOL _far _pascal  _loadds  StartOfPrint(void)
    {
    /*BYTE tmp1[TMPNSTR + 1];*/
    BYTE  device[TMPNSTR + 1];
    BYTE _far *pch;
    BYTE _far *pchFile;
    BYTE _far *pchPort;
    TEXTMETRIC  metrics;
    LOGFONT      lf;
    HFONT oldFont,newFont; GetProfileString((LPSTR)"windows",(LPSTR)"device",(LPSTR)"",
    (LPSTR)device,TMPNSTR); for (pch = device; *pch && (*pch != ','); ++pch);
    if(*pch)
    *pch ++ = 0;
    while (*pch && *pch <= ' ')
    pch++;
    pchFile = pch;
    while (*pch && *pch != ',' && *pch > ' ')
    pch ++;
    if (*pch)
    *pch ++ = 0; 
    while (*pch && (*pch <= ' ' || *pch ==','))
    pch++; 
    pchPort = pch;
    while (*pch && (*pch > ' '))
    pch++;
    *pch = 0;
    /*device = tmp1;*/
             
    if (!(ghPrintDC = CreateDC((LPSTR) pchFile, (LPSTR) device,
    (LPSTR) pchPort,(DEVMODE*) NULL)))

    {
    if (ghPrintDC)
    DeleteDC(ghPrintDC);
    return FALSE;
    } GetTextMetrics( ghPrintDC, ( LPTEXTMETRIC )&metrics );
    /*metrics.tmAveCharWidth = 500;
    metrics.tmWeight = FW_BOLD ;*/
    gnChrPrtHeight = metrics.tmHeight + metrics.tmExternalLeading;
    gnChrPrtWidth = metrics.tmAveCharWidth; gnPageLength = getgnPageLength (ghPrintDC,gnChrPrtHeight);
    gnLineLength = getgnLineLength (ghPrintDC,gnChrPrtWidth);

    lf.lfHeight = -30;/*0xfff0;*/
    lf.lfWidth  = 0;
    lf.lfEscapement  = 0;
    lf.lfOrientation = 0;
    lf.lfWeight = 0x012c;
    lf.lfItalic = 0;
    lf.lfUnderline = 0;
    lf.lfStrikeOut = 0;
    lf.lfCharSet    = ANSI_CHARSET;
    lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
    lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
    lf.lfQuality = DEFAULT_QUALITY;
    lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
    lstrcpy(lf.lfFaceName, "宋体");
    newFont = CreateFontIndirect(&lf);
    oldFont = SelectObject( ghPrintDC,newFont);
    oldFontRecord = newFont;
    newFontRecord = oldFont; if (Escape (ghPrintDC,STARTDOC, strlen(gszTempFileName),
    (LPSTR) gszTempFileName,(LPSTR) 0) <= 0)
    {
    /*errProc(IDSTR_STRPRINTERR);*/
    DeleteDC (ghPrintDC);
    return FALSE;
    }
    gnCharCount = 0;
    return TRUE;
    }
    void _far _pascal _loadds small_font(int x,int y,LPSTR ptr)
    {
    LOGFONT      lf;
    HFONT oldFont,newFont;

    lf.lfHeight = -21;/*0xfff0;*/
    lf.lfWidth  = 0;
    lf.lfEscapement  = 0;
    lf.lfOrientation = 0;
    lf.lfWeight = 0x012c;
    lf.lfItalic = 0;
    lf.lfUnderline = 0;
    lf.lfStrikeOut = 0;
    lf.lfCharSet    = ANSI_CHARSET;
    lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
    lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
    lf.lfQuality = DEFAULT_QUALITY;
    lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
    lstrcpy(lf.lfFaceName, "宋体");
    newFont = CreateFontIndirect(&lf);
    oldFont = SelectObject( ghPrintDC,newFont);
      if ( (X_START + x) > 0 ) 
    TextOut(ghPrintDC,X_START + x,Y_START + y, ptr, _fstrlen(ptr));
    else
    TextOut(ghPrintDC, 1,Y_START + y, ptr, _fstrlen(ptr));
      /*TextOut(ghPrintDC,X_START + x, Y_START + y, ptr, _fstrlen(ptr));*/
      SelectObject( ghPrintDC, oldFont);
      DeleteObject(newFont);
    } void _far _pascal _loadds small_font_truncate(int x,int y,LPSTR ptr)
    {
    LOGFONT      lf;
    HFONT oldFont,newFont;
    int nLen;
    lf.lfHeight = -21;/*0xfff0;*/
    lf.lfWidth  = 0;
    lf.lfEscapement  = 0;
    lf.lfOrientation = 0;
    lf.lfWeight = 0x012c;
    lf.lfItalic = 0;
    lf.lfUnderline = 0;
    lf.lfStrikeOut = 0;
    lf.lfCharSet    = ANSI_CHARSET;
    lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
    lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
    lf.lfQuality = DEFAULT_QUALITY;
    lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
    lstrcpy(lf.lfFaceName, "宋体");
    newFont = CreateFontIndirect(&lf);
    oldFont = SelectObject( ghPrintDC,newFont);
    if ( _fstrlen(ptr) > 20 )
    nLen = 20;
    else
    nLen = _fstrlen(ptr);
      /*TextOut(ghPrintDC,X_START + x, Y_START + y, ptr, nLen);*/
      if ( (X_START + x) > 0 ) 
    TextOut(ghPrintDC,X_START + x,Y_START + y, ptr, nLen);
    else
    TextOut(ghPrintDC, 1,Y_START + y, ptr, nLen);
      SelectObject( ghPrintDC, oldFont);
      DeleteObject(newFont);
    } void _far _pascal _loadds endOfPrintJob(void)
    {
    Escape( ghPrintDC,ENDDOC,0,(LPSTR)0,(LPSTR)0);
    DeleteDC(ghPrintDC);
      SelectObject( ghPrintDC, oldFontRecord);
      DeleteObject(newFontRecord);
    }void _far _pascal _loadds print_to(int x,int y,LPSTR ptr)
    {
      if ( (X_START + x) > 0 ) 
    TextOut(ghPrintDC,X_START + x,Y_START + y, ptr, _fstrlen(ptr));
    else
    TextOut(ghPrintDC, 1,Y_START + y, ptr, _fstrlen(ptr));} void _far _pascal _loadds print_center( x1, y1, x2, ptr)
    int x1;
    int y1;
    int x2;
    LPSTR ptr;
    {
    int x_start;
    int cent;
    cent = (x1 + x2) / 2;
    x_start = cent - FontWidthE * _fstrlen(ptr) / 2;
      TextOut(ghPrintDC,X_START + x_start,Y_START + y1, ptr,_fstrlen(ptr));
    }
      

  6.   

    error LNK2001: unresolved external symbol _main估计是个链接错误。
      

  7.   

    做成console exe了,检查工程设置。
    干脆新建一个win32 dynamic-link library,把你的代码粘贴进去
      

  8.   

    Project Settings --> Link Page --> Project Options --> 添加 /dll /implib:"Debug(Release)/***.lib"
    Project Settings --> C/C++ Page --> Project Options --> /MT(d) /ML(d) 改为 /MD(d), Preprocessor defines 添加 _USRDLL同时把 Link Page --> Output filename , Debug Page --> Debug session 改掉或者重新建一个 Win32 Dynamic-link Library 工程,将代码拷进去
      

  9.   

    好象大家出了很多的点子了。我再说一点:
    _far, _pascal在32位环境都已经被废弃了。在32中,统一用_stdcall,如果想把16位的程序换到32位中来,确实有很多的地方要注意,很多函数的差别导致了移植的困难。我也建议你按楼上两位的方法重试一遍,如果再有问题,大家再多讨论。
      

  10.   

    to:In355Hz(好象一条狗) ( )
    第二个设定:
    /MT(d) /ML(d) 改为 /MD(d), Preprocessor defines 添加 _USRDLL
    我这里C/C++ Page -->Project Options 原先设定为/nologo /MLd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Fp"Debug/Print.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /GZ /c 
    没有小括号呀!
      

  11.   

    有了新麻烦!!修改代码的方法我尝试了多次,都不行。
    后来重新建一个 Win32 Dynamic-link Library 工程,把*.c文件add to orohect中,
    修改*。c文件的前面的部分为:
    #include  <windows.h>
    #include <string.h>
    #include <stdio.h>
    #define _far 
    #define _pascal 
    #define _fstrlen(s) strlen(s)
    #define EXPORTAPI __declspec(dllexport) __stdcall编译通过。但是出了问题:生成的dll文件,其它主调用模块(GUPTA公司的SQL Window编写的,可能是16位的程序)不能调用它。
    怎么办?主调用模块修改,工作量太大,那只有改我这个dll了吗?!