프로그래밍

Visual studio 2005에서 Win32API를 빌드시 링크에러 대처 방법

봄바다별하늘 2006. 2. 1. 05:25

Visual studio 2005에서 Win32API를 빌드시 링크에러 대처 방법

 

요약 : VS6에서 빌드 잘되던 Win32 프로그램이 2005에서 빌드에러시 대처방법


Win32API를 공부해 보고자 Visual Studio 2005 trial을 설치 후 윈도우 창을 띄우는 아주 간단한 프로그램을 작성하여 빌드시 링크에러 남

 

Alt+F7누르면 나타나는 설정창(PROJECT NAME Property Pages)에서 Configuration Properties>Linker>Input>Additional Dependencies에 WINMM.LIB를 추가하면 링크 문제해결됨


아래 참고로 에러 내용과 Win32API 스터디에 사용한 소스코드를 첨부함

참고 사이트 :

http://www.codecomments.com/archive371-2005-9-600585.html

http://64.233.179.104/search?q=cache:twuAkrkAVOcJ:www.codecomments.com/archive371-2005-9-600585.html+error+LNK2019:+unresolved+external+symbol+__stdcall+WndProc+2005&hl=ko&gl=kr&ct=clnk&cd=8

 

## 에러 내용

---------------------------- Build started: Project: myWin32, Configuration: Debug Win32 ------
Compiling...
mywin32.cpp
Linking...
mywin32.obj : error LNK2019: unresolved external symbol __imp__PlaySoundW@12 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)
C:\Documents and Settings\USERNAME\My Documents\Visual Studio 2005\Projects\myWin32\Debug\myWin32.exe : fatal error LNK1120: 1 unresolved externals
Build log was saved at "file://c:\Documents and Settings\USERNAME\My Documents\Visual Studio 2005\Projects\myWin32\myWin32\Debug\BuildLog.htm"
myWin32 - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

## 소스코드
/*------------------------------------------------------------
   HELLOWIN.C -- Displays "Hello, Windows 98!" in client area
                 (c) Charles Petzold, 1998
  ------------------------------------------------------------*/

#include

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

#define IDI_MYW32   107
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 ;
     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
                          0,              // initial x position
                          0,              // initial y position
                          100,              // initial x size
                          100,              // 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 (int)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) ;
}