win7系统中,将Visual C++ 6.0按照默认的方式安装在C盘,运行程序,即使是简单的程序,仍然会出现错误。如:
#include "windows.h" LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASS wndclass; HWND hwnd; MSG msg; wndclass.style = CS_HREDRAW|CS_VREDRAW; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wndclass.lpszMenuName = NULL; wndclass.lpszClassName = "Chap1Exa1"; if(!RegisterClass(&wndclass)) return FALSE; hwnd = CreateWindow("Chap1Exa1", "Chap1Exa1", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); ShowWindow(hwnd, nCmdShow); UpdateWindow(hwnd); while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_PAINT: HDC hdc; PAINTSTRUCT ps; hdc = BeginPaint(hwnd, &ps); TextOut(hdc, 20, 60, "The First Windows Application Showing Window", 35); EndPaint(hwnd, &ps); case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, message, wParam, lParam); }
LINK : fatal error LNK1104: cannot open file Debug/Chap1Exa1.exe
经测试,以上程序没有任何问题。
为了试验,作者再建了一个简单的程序,依旧放在默认的空间里。程序如下:
#include "stdio.h" int main(void) { printf("Welcome!"); return 0; }运行过后,依然发现系统提示相同的错误。
解决办法:
win7系统为了安全考虑,在C盘中的文件受到一定的保护。所以,以默认的形式放在C盘MyProjects文件夹下的文件,不允许被执行。我们只需将项目建立在其他的盘中(非系统盘),这时就可以运行了。
本人也做了实验,可以成功的。