我刚学VC++一个月,有C语言基础。我照书编了一个显示当前时间的程序。可是有一个错误和一个警告。错误提示是“error C2017: illegal escape sequence”,出错那一行是93行,代码是“str[strlen(str)-1]= \0;”。警告提示是“warning C4013: 'RegisterClassEX' undefined; assuming extern returning int”。我查了MSDN,\0应该是表示ASII的0,或是说表示NUL,可是我把\0改为0,或是NUL时,编译可以通过,可是连接时出现了三个错误“time.obj : error LNK2001: unresolved external symbol _RegisterClassEX” “LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16” “ebug/time.exe : fatal error LNK1120: 2 unresolved externals”。至于那个警告,我头文件包括了windows.h和winuser.h乐,为什么还是不行?
高手们给指点一下吧,我搞了很久了也没解决。libcd.lib我也连接了。源代码如下/* A clock program.*/#include<windows.h>
#include<string.h>
#include<stdio.h>
#include<time.h>LRESULT CALLBACK WindowFunc(HWND,UINT,WPARAM,LPARAM);LPCTSTR szWinName = "WinClock"; /*name of window class*/
char str[255] = " "; /*holds output string*/int WINAPIWinMain(HINSTANCE hThisInst,HINSTANCE hPrevInst,LPSTR IpszArgs,int nWinMode)
{ HWND hwnd;
MSG msg;
WNDCLASSEX wcl;
/*Define a window class*/
wcl.cbSize = sizeof(WNDCLASSEX);
wcl.hInstance = hThisInst;
wcl.lpszClassName = szWinName;
wcl.lpfnWndProc = WindowFunc;
wcl.style = 0;
wcl.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wcl.hIconSm = LoadIcon(NULL,IDI_WINLOGO);
wcl.hCursor = LoadCursor(NULL,IDC_ARROW);
wcl.lpszMenuName = NULL;
wcl.cbClsExtra = 0;
wcl.cbWndExtra = 0; /*Make the window white.*/
wcl.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); /*Register the window class.*/
if(!RegisterClassEx(&wcl)) return 0; /*Now that a widow class has been registered,a window can be created.*/
hwnd = CreateWindow(
szWinName,
"Clock",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
HWND_DESKTOP,
NULL,
hThisInst,
NULL); /*Display the window.*/
ShowWindow(hwnd,nWinMode); /*start a timer -- interrupt once per second*/
SetTimer(hwnd,1,1000,NULL); UpdateWindow(hwnd); /*Create the message loop.*/
while(GetMessage(&msg,NULL,0,0))
{ TranslateMessage(&msg);
DispatchMessage(&msg);
} KillTimer(hwnd,1); return msg.wParam;
}/*This function is called by Windows 98 and is passed messages from the mdssafe queue.
*/
LRESULT CALLBACK WindowFunc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{ HDC hdc;
PAINTSTRUCT paintstruct;
struct tm *newtime;
time_t t; switch(message)
{ case WM_PAINT:
hdc = BeginPaint(hwnd,&paintstruct);
TextOut(hdc,1,1,str,strlen(str));
EndPaint(hwnd,&paintstruct);
break; case WM_TIMER:
/*get the new time*/
t = time(NULL);
newtime = localtime(&t); /*display the mew time*/
strcpy(str,asctime(newtime));
str[strlen(str)-1]= \0;
InvalidateRect(hwnd,NULL,0);
break; case WM_DESTROY:
PostQuitMessage(0);
break;
default:
/*Let Windows98 process any messages not specified in the preceding switch statement*/
return DefWindowProc(hwnd,message,wParam,lParam);
}
return 0;
}
高手们给指点一下吧,我搞了很久了也没解决。libcd.lib我也连接了。源代码如下/* A clock program.*/#include<windows.h>
#include<string.h>
#include<stdio.h>
#include<time.h>LRESULT CALLBACK WindowFunc(HWND,UINT,WPARAM,LPARAM);LPCTSTR szWinName = "WinClock"; /*name of window class*/
char str[255] = " "; /*holds output string*/int WINAPIWinMain(HINSTANCE hThisInst,HINSTANCE hPrevInst,LPSTR IpszArgs,int nWinMode)
{ HWND hwnd;
MSG msg;
WNDCLASSEX wcl;
/*Define a window class*/
wcl.cbSize = sizeof(WNDCLASSEX);
wcl.hInstance = hThisInst;
wcl.lpszClassName = szWinName;
wcl.lpfnWndProc = WindowFunc;
wcl.style = 0;
wcl.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wcl.hIconSm = LoadIcon(NULL,IDI_WINLOGO);
wcl.hCursor = LoadCursor(NULL,IDC_ARROW);
wcl.lpszMenuName = NULL;
wcl.cbClsExtra = 0;
wcl.cbWndExtra = 0; /*Make the window white.*/
wcl.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); /*Register the window class.*/
if(!RegisterClassEx(&wcl)) return 0; /*Now that a widow class has been registered,a window can be created.*/
hwnd = CreateWindow(
szWinName,
"Clock",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
HWND_DESKTOP,
NULL,
hThisInst,
NULL); /*Display the window.*/
ShowWindow(hwnd,nWinMode); /*start a timer -- interrupt once per second*/
SetTimer(hwnd,1,1000,NULL); UpdateWindow(hwnd); /*Create the message loop.*/
while(GetMessage(&msg,NULL,0,0))
{ TranslateMessage(&msg);
DispatchMessage(&msg);
} KillTimer(hwnd,1); return msg.wParam;
}/*This function is called by Windows 98 and is passed messages from the mdssafe queue.
*/
LRESULT CALLBACK WindowFunc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{ HDC hdc;
PAINTSTRUCT paintstruct;
struct tm *newtime;
time_t t; switch(message)
{ case WM_PAINT:
hdc = BeginPaint(hwnd,&paintstruct);
TextOut(hdc,1,1,str,strlen(str));
EndPaint(hwnd,&paintstruct);
break; case WM_TIMER:
/*get the new time*/
t = time(NULL);
newtime = localtime(&t); /*display the mew time*/
strcpy(str,asctime(newtime));
str[strlen(str)-1]= \0;
InvalidateRect(hwnd,NULL,0);
break; case WM_DESTROY:
PostQuitMessage(0);
break;
default:
/*Let Windows98 process any messages not specified in the preceding switch statement*/
return DefWindowProc(hwnd,message,wParam,lParam);
}
return 0;
}
解决方案 »
- 网络编程的Create()的最后的参数是IP地址,是服务器端or客户端IP地址?
- 求软件开发
- 请教:做个网页自动填字的程序
- 帮帮忙
- 关于socket与多线程的问题,请高手指教。
- 菜鸟问题,如何在程序中启动别的exe并且把自己的程序关闭。
- 错误:Unhandled exception in genius.exe(NNOTES.DLL):0xc0000005:Access Violation 可能是什么引起的?
- 求助
- 用datagrid 控件的程序在本机好用,在另外一台提示cannot initialize data bindings
- slide中的滚动条,有NM_RELEASEDCAPTURE事件,是响应mouseup,有没有什么事件响应mousedown的?
- 如何编程发送、接受arp包?
- 如何获得当前程序的路径?
strlen是不包括‘\0’的长度的。strlen(str)-1就多扣了一个字符。
"Debug/time.exe : fatal error LNK1120: 1 unresolved externals"
是啥意思?咋解决?
--->你的程序可能是一个WINAPI程序,
--->你的程序又包含一些纯 c 的头文件
LNK2001: unresolved external symbol _WinMain@16"
"Debug/time.exe : fatal error LNK1120: 1 unresolved externals"
是说有不能定位的符号_WinMain@16,其实是找不到程序的入口点。
1、str[strlen(str)-1]= '\0'; 即\0加引号''
2、int WINAPIWinMain中加空格int WINAPI WinMain