读书人

关于WINDOWS窗口程序的有关问题

发布时间: 2012-01-19 20:57:58 作者: rapoo

关于WINDOWS窗口程序的问题.
编译通过了,可是链接有三个错误:(请高手指点!)我是在VC6.0下调试的.

wincre.obj : error LNK2001: unresolved external symbol __imp__PlaySoundA@12
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/wincre.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

程序如下:
#include <windows.h>

LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,PSTR szCmdLine, int iCmdShow)

{
static TCHAR szAppName[]=TEXT( "HelloWin ");

HWND hwnd ;

MSG msg ;

WNDCLASS wndclass ;

wndclass.style = CS_HREDRAW | CS_VREDRAW ; // 窗口样式,一般设置为0

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= szAppName ;// 窗口类名


if (!RegisterClass (&wndclass))

{

MessageBox (NULL, TEXT ( "This program requires Windows NT! "),

szAppName, MB_ICONERROR) ;



return 0 ;

}

hwnd = CreateWindow( szAppName, // window class name

TEXT ( "The Hello Program "), // window caption

WS_OVERLAPPEDWINDOW, // window style

CW_USEDEFAULT,// initial x position

CW_USEDEFAULT,// initial y position

CW_USEDEFAULT,// initial x size

CW_USEDEFAULT,// initial y size

NULL, // parent window handle

NULL, // window menu handle

hInstance, // program instance handle

NULL) ; // creation parameters



ShowWindow (hwnd, iCmdShow) ;

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)

{

HDC hdc ;

PAINTSTRUCT ps ;

RECT rect ;

switch (message)
{

case WM_CREATE:

PlaySound (TEXT ( "hellowin.wav "), NULL, SND_FILENAME | SND_ASYNC) ;

return 0 ;


case WM_PAINT:

hdc = BeginPaint (hwnd, &ps) ;



GetClientRect (hwnd, &rect) ;



DrawText (hdc, TEXT ( "Hello, Windows 98! "), -1, &rect,

DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;



EndPaint (hwnd, &ps) ;

return 0 ;


case WM_DESTROY:

PostQuitMessage (0) ;

return 0 ;

}

return DefWindowProc (hwnd, message, wParam, lParam);

}




[解决办法]
unresolved external symbol __imp__PlaySoundA@12
需要加入库winmm.lib
#pragma comment(lib, "winmm.lib ")

unresolved external symbol _main 工程属性问题 用Win32APP

读书人网 >VC/MFC

热点推荐