(Microsoft VC++ Express)LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt

f:id:xuechui:20170318081909p:plain

There are several "cvtres.exe" in C disk, maybe installed by .NET Framework. Replace the old one in VC/bin by the first one(new?) in C disk.

f:id:xuechui:20170318081918p:plain

连接器LNK是通过调用cvtres.exe完成文件向coff格式的转换的,所以出现这种错误的原因就是cvtres.exe出现了问题。

 

在电脑里面搜索一下cvtres.exe,发现存在多个文件,使用最新的cvtres.exe替换老的文件即可,替换之前记得备份一下,如果不对,可以替换回来。


例如:我的电脑里面安装了vs2010,最近更新了系统,打了一些补丁,结果就出现这种错误了。在电脑里面搜索发现

C:\Program Files\Microsoft Visual Studio 10.0\VC\bin

C:\Windows\winsxs\x86_netfx-cvtres_for_vc_and_vb_b03f5f7f11d50a3a_6.1.7600.16385_none_ba476986f05abc65

C:\Windows\Microsoft.NET\Framework\v4.0.30319


这三个路径里面都有cvtres.exe文件,于是我尝试使用第二个路径里面的文件替换第一个路径的文件,问题解决。


参考资料如下:

http://stackoverflow.com/questions/10888391/link-fatal-error-lnk1123-failure-during-conversion-to-coff-file-invalid-or-c/14144713#14144713

blog.chinaunix.net

blog.csdn.net

マウスで円を描くコード

「猫でもわかるWindowsプログラミング」より

↓こんな感じ。 f:id:xuechui:20170227193417p:plain

#include <windows.h>

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
ATOM InitApp(HINSTANCE);
BOOL InitInstance(HINSTANCE, int);
void DrawRect(HWND, POINTS, POINTS);

TCHAR szClassName[] = TEXT("Mouse1");
POINTS start, end, old_end;     //Start and End point of Rectangle


//windows prgram entry point
int WINAPI WinMain(HINSTANCE hCurInst, HINSTANCE hPrevInst, 
                   LPSTR lpsCmdLine, int nCmdShow)
{
    MSG msg;
    BOOL bRet;
    
    if(!InitApp(hCurInst))
        return FALSE;
    if(!InitInstance(hCurInst, nCmdShow))
        return FALSE;
    
    //Get Message
    while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0){
        if (bRet == -1){
            break;
        }else{
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }
    return (int)msg.wParam;
}

//register window class
ATOM InitApp(HINSTANCE hInst)
{
    WNDCLASSEX wc;
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInst;
    wc.hIcon = NULL;
    wc.hCursor = (HCURSOR)LoadImage(
    NULL, MAKEINTRESOURCE(IDC_ARROW),
    IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE | LR_SHARED);
    wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = szClassName;
    wc.hIconSm = NULL;
    
    return (RegisterClassEx(&wc));
}

//Generage Window
BOOL InitInstance(HINSTANCE hInst, int nCmdShow)
{
    HWND hWnd;
    
    hWnd = CreateWindow(szClassName, //Class Name
            TEXT("Neko demo Mouse"),     //Window Name
            WS_OVERLAPPEDWINDOW,    //Window Style
            CW_USEDEFAULT,          //x position
            CW_USEDEFAULT,          //y position
            CW_USEDEFAULT,          //Window Width
            CW_USEDEFAULT,          //Window Height
            NULL,
            NULL,
            hInst,
            NULL,
            );
            if (!hWnd)
                return FALSE;
            ShowWindow(hWnd, nCmdShow);
            UpdateWindow(hWnd);
            return TRUE;
}

//Window Procedure
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
{
    TCHAR szBuf[32];
    HDC hdc;
    HBRUSH hBrush;
    static BOOL bDraw;
    
    switch (msg){
        case WM_LBUTTONDOWN:
            bDraw = TRUE;
            old_end = start = MAKEPOINTS(lp);
            DrawRect(hWnd, start, old_end);
            break;
        case WM_MOUSEMOVE:
            if(bDraw){
                end = MAKEPOINTS(lp);
                DrawRect(hWnd, start, old_end);
                DrawRect(hWnd, start, end);
                old_end = end;
            }else{
                return DefWindowProc(hWnd, msg, wp, lp);
            }
            break;
        case WM_LBUTTONUP:
            if(bDraw){
                SetCursor(LoadCursor(NULL, IDC_ARROW));
                DrawRect(hWnd, start, end);
                bDraw = FALSE;
                
                wsprintf(szBuf, TEXT("(%d, %d) - (%d, %d)"),
                            start.x, start.y, end.x, end.y);
                SetWindowText(hWnd, szBuf);
                hdc = GetDC(hWnd);
                hBrush = (HBRUSH)GetStockObject(NULL_BRUSH);
                SelectObject(hdc, hBrush);
                Ellipse(hdc, start.x, start.y, end.x, end.y);
                ReleaseDC(hWnd, hdc);
            }else{
                return DefWindowProc(hWnd, msg, wp, lp);
            }
            break;
        case WM_DESTROY:
            PostQuitMessage(0);
            break;
        default:
            return (DefWindowProc(hWnd, msg, wp, lp));
    }
    return 0;
}



void DrawRect(HWND hWnd, POINTS beg, POINTS end)
{
    HDC hdc;
    hdc = GetDC(hWnd);
    SetROP2(hdc, R2_NOT);
    
    MoveToEx(hdc, beg.x, beg.y, NULL);
    LineTo(hdc, end.x, beg.y);
    LineTo(hdc, end.x, end.y);
    LineTo(hdc, beg.x, end.y);
    LineTo(hdc, beg.x, beg.y);
    LineTo(hdc, end.x, end.y);
    
    ReleaseDC(hWnd, hdc);
    return;
}

Use of Macro Definitions to Simplify MD Code

C supports the use of macro definitions that can simplify the code considerably.

#define Sqr(x) ((x)*(x))
#define Cube(x) ((x)*(x)*(x))
#define VSub(v1, v2, v3) (v1).x = (v2).x - (v3).x, (v1).y = (v2).y - (v3).y 

The above definition will shorten the codes.

Wait Until Next ms Multiple vs Wait (ms)

"Wait Until Next ms Multiple"と"Wait (ms)"の違いについての説明は以下。

日本語版

"Wait (ms)"と "Wait Until Next ms Multiple"の違いはなんですか? - National Instruments

英語版

The Difference Between the Wait (ms) Function and the Wait Until Next ms Multiple Function - National Instruments

桂太郎 「図解LabVIEW実習」

f:id:xuechui:20170222145136j:image