刚开始学mfc就遇到了这样的问题,比照着书上例子自己编一个程序,仅仅改了几个字符串而已,我的程序就不能运行,出现“没能找到MSVCR90D.DLL,因此这个程序未能启动,重新安装可能解决问题”对话框,而原来的例子却能够运行!真够无语!
上网查说是有一个微软的bug,代码放在fat32的磁盘中会出现这个问题,一想,对,C盘是fat32的,又学网上的方法将c盘转换成NTFS格式,结果还是出现了“没能找到MSVCR90D.DLL,因此这个程序未能启动,重新安装可能解决问题”对话框。大家帮我想想办法!下面是我的代码。
#include <windows.h>
#include <stdio.h>LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
WNDCLASS wndcls;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
wndcls.hInstance=hInstance;
wndcls.lpfnWndProc=WinSunProc;
wndcls.lpszClassName="wangxr2009";
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls); HWND hwnd;
hwnd=CreateWindow("wangxr2009","我的窗口",WS_OVERLAPPEDWINDOW,
0,0,600,400,NULL,NULL,hInstance,NULL); ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
MSG msg; while (GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
} return 0;}LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
switch(uMsg)
{
case WM_CHAR:
char szchar[20];
sprintf(szchar,"char is %d",wParam);
MessageBox(hwnd,szchar,"wangxr",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"moouse cliked","wangxr",0);
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,0,50,"MFC 基础学习",strlen("MFC 基础学习"));
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC=BeginPaint(hwnd,&ps);
TextOut(hDC,0,0,"培训",strlen("培训"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否结束?","wangxr",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc( hwnd, uMsg,wParam,lParam );
} return 0;}
上网查说是有一个微软的bug,代码放在fat32的磁盘中会出现这个问题,一想,对,C盘是fat32的,又学网上的方法将c盘转换成NTFS格式,结果还是出现了“没能找到MSVCR90D.DLL,因此这个程序未能启动,重新安装可能解决问题”对话框。大家帮我想想办法!下面是我的代码。
#include <windows.h>
#include <stdio.h>LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
WNDCLASS wndcls;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
wndcls.hInstance=hInstance;
wndcls.lpfnWndProc=WinSunProc;
wndcls.lpszClassName="wangxr2009";
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls); HWND hwnd;
hwnd=CreateWindow("wangxr2009","我的窗口",WS_OVERLAPPEDWINDOW,
0,0,600,400,NULL,NULL,hInstance,NULL); ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
MSG msg; while (GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
} return 0;}LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
switch(uMsg)
{
case WM_CHAR:
char szchar[20];
sprintf(szchar,"char is %d",wParam);
MessageBox(hwnd,szchar,"wangxr",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"moouse cliked","wangxr",0);
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,0,50,"MFC 基础学习",strlen("MFC 基础学习"));
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC=BeginPaint(hwnd,&ps);
TextOut(hDC,0,0,"培训",strlen("培训"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否结束?","wangxr",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc( hwnd, uMsg,wParam,lParam );
} return 0;}
或者编译程序的之前把项目属性中的“MFC使用”设置成“静态库中使用MFC”
include <windows.h>
#include <stdio.h>LRESULT CALLBACK WinSunProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow // show state
)
{
WNDCLASS wndcls;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
wndcls.hInstance=hInstance;
wndcls.lpfnWndProc=WinSunProc;
wndcls.lpszClassName="Weixin2003";
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls); HWND hwnd;
hwnd=CreateWindow("Weixin2003","北京维新科学技术培训中心",WS_OVERLAPPEDWINDOW,
0,0,600,400,NULL,NULL,hInstance,NULL); ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd); MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}LRESULT CALLBACK WinSunProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
switch(uMsg)
{
case WM_CHAR:
char szChar[20];
sprintf(szChar,"char is %d",wParam);
MessageBox(hwnd,szChar,"weixin",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse clicked","weixin",0);
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,0,50,"计算机编程语言培训",strlen("计算机编程语言培训"));
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC=BeginPaint(hwnd,&ps);
TextOut(hDC,0,0,"维新培训",strlen("维新培训"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否真的结束?","weixin",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
1>winmain.obj : error LNK2019: 无法解析的外部符号 __imp__DispatchMessageA@4,该符号在函数 _WinMain@16 中被引用
1>winmain.obj : error LNK2019: 无法解析的外部符号 __imp__TranslateMessage@4,该符号在函数 _WinMain@16 中被引用
1>winmain.obj : error LNK2019: 无法解析的外部符号 __imp__GetMessageA@16,该符号在函数 _WinMain@16 中被引用
1>winmain.obj : error LNK2019: 无法解析的外部符号 __imp__UpdateWindow@4,该符号在函数 _WinMain@16 中被引用
等等。
这个一般是什么问题?
“重新生成解决方案”
http://www.cnblogs.com/_xbc/archive/2010/05/03/1726753.html
Rebuild All
“重新生成解决方案”
成功解决问题
如果你的vc2008装在了NTFS分区,而且项目同样放在NTFS分区。那么安装补丁:http://download.microsoft.com/download/0/d/5/0d5580c0-9d8c-4873-9024-553323ab8589/WindowsXP-KB889016-x86-CHS.exe
中文版:项目-->项目属性-->配置属性-->清单工具-->使用FAT32解决方法-->是
然后clean下,然后Rebuild即可正常运行
Rebuild All
“重新生成解决方案”
然后放在c:windos/system32目录下就好了
或者是manifest的问题。