初学多线程程序设计。碰到MTVERIFY,不知道是什么东东?请详细解答。谢谢。

解决方案 »

  1.   

    它是一个macro,对应的头文件是<mtverify.h>,但在网上没有找到关于其详细介绍的资料。呵呵
      

  2.   

    《win32多线程程序设计》侯捷译, 97版的。
      

  3.   

    呵呵,你是对的。头文件MtVerify.h定义了两个宏MTVERIFY用来检验函数是否成功,并且在函数失败时将根据GetLastError()而得的错误信息。
    MTASSERT()功能比较少,因为它不调用GetLastError().从你刚才的回答中,我是不是可以这样理解啊?一些头文件的名称一般是不是根据它的英文单词的相关组合而成的呢?
      

  4.   

    就是一个宏,类似于ASSERT()宏你可以根据自己的需要,写一些判断的宏
      

  5.   

    /*
     * MtVerify.h
     *
     * Error handling for applications in
     * "Multitheading Applications in Win32"
     *
     * The function PrintError() is ed as __inline so that it can be
     * included from one or more C or C++ files without multiple definition
     * errors. For the examples in this book, this works fine.
     * To use the PrintError() in an application, it should be taken out,
     * placed in its own source file, and the "__inline" declaration removed
     * so the function will be globally available.
     */#pragma comment( lib, "USER32" )#include <crtdbg.h>
    #define MTASSERT(a) _ASSERTE(a)
    #define MTVERIFY(a) if (!(a)) PrintError(#a,__FILE__,__LINE__,GetLastError())__inline void PrintError(LPSTR linedesc, LPSTR filename, int lineno, DWORD errnum)
    {
    LPSTR lpBuffer;
    char errbuf[256];
    #ifdef _WINDOWS
    char modulename[MAX_PATH];
    #else // _WINDOWS
    DWORD numread;
    #endif // _WINDOWS FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER
    | FORMAT_MESSAGE_FROM_SYSTEM,
    NULL,
    errnum,
    LANG_NEUTRAL,
    (LPTSTR)&lpBuffer,
    0,
    NULL ); wsprintf(errbuf, "\nThe following call failed at line %d in %s:\n\n"
                   "    %s\n\nReason: %s\n", lineno, filename, linedesc, lpBuffer);
    #ifndef _WINDOWS
    WriteFile(GetStdHandle(STD_ERROR_HANDLE), errbuf, strlen(errbuf), &numread, FALSE );
    Sleep(3000);
    #else
    GetModuleFileName(NULL, modulename, MAX_PATH);
    MessageBox(NULL, errbuf, modulename, MB_ICONWARNING|MB_OK|MB_TASKMODAL|MB_SETFOREGROUND);
    #endif
    exit(EXIT_FAILURE);
    }