티스토리 뷰

윈도우 버전에 따른 Visual C++관련 헤더 설정하기 

(error C2065: undeclared identifier 해결 방안)


하위  버전의 윈도우에서 개발된 Visual C++관련 코드를 수정하는 경우가 발생할 때가 가끔은 있습니다. 이런 경우 프로젝트를 업그레이드 하고 컴파일을 누르면 컴파일이 되지 않고, 코드에는 선언이 되어있는 다양한 클래스 혹은 구조체들을 찾지 못해 에러가 발생을 합니다.


이에 대한 예를 알아볼까요?


위의 그림의 경우 PSCROLLBARINFO라는 개체를 인식하지 못하여 발생하는 에러입니다. 하지만 코드에서 PSCROLLBARINFO를 찾아서 들어가 보면 코드나 헤더상에는 반드시 이 개체가 존재합니다.


이러한 문제는 왜 발생하는지 알아보도록 하겠습니다.


Microsoft Visual C++ includes copies of the Windows header files that were current at the time Visual C++ was released. Therefore, if you install updated header files from an SDK, you may end up with multiple versions of the Windows header files on your computer. If you do not ensure that you are using the latest version of the SDK header files, you will receive the following error code when compiling code that uses features that were introduced after Visual C++ was released: error C2065: undeclared identifier


위의 글을 간략히 해석해보면, Visual C++은 최신의 윈도우 헤더 파일에 대한 복사본을 포함하고 있기 때문에 과거에 만들어진(OS가 다른) 코드를 현재 PC에 가지고 왔을 때, 헤더에 대한 버전이 맞지 않아 C2065에러가 발생한다라고 설명을 하고 있습니다.


이러한 경우 어떻게 해결을 할 수 있을 까요?

프로젝트의 header 파일에 지정된 버전을 변경하시면 간략히 해결할 수 있습니다. stdafx.h을 열어보시면 아래와 같이 정의되어 있는 부분을 확인할 수 있습니다.


#ifndef _WIN32_WINNT // Allow use of features specific to Windows NT 4  or later.

#define _WIN32_WINNT 0x0400 // Change this to the appropriate value to  target Windows 98

#endif


위의 코드는 윈도우의 버전이 Window NT 버전으로 설정이 되어 있습니다. 만약 윈도우 7에서 사용을 하고자 하시면 0x0400의 부분을 0x0601로 변경해 주시면 됩니다.


왜 0x0601이냐라고 물으신다면 마이크로 소프트에서 이미 그렇게 정해놓았습니다. 아래의 표를 한번 살펴보시겠습니다. 


Minimum system required

Value for NTDDI_VERSION

Windows 8.1

NTDDI_WINBLUE (0x06030000)

Windows 8

NTDDI_WIN8 (0x06020000)

Windows 7

NTDDI_WIN7 (0x06010000)

Windows Server 2008

NTDDI_WS08 (0x06000100)

Windows Vista with 

Service Pack 1 (SP1)

NTDDI_VISTASP1 (0x06000100)

Windows Vista

NTDDI_VISTA (0x06000000)

Windows Server 2003 with 

Service Pack 2 (SP2)

NTDDI_WS03SP2 (0x05020200)

Windows Server 2003 with 

Service Pack 1 (SP1)

NTDDI_WS03SP1 (0x05020100)

Windows Server 2003

NTDDI_WS03 (0x05020000)

Windows XP 

with Service Pack 3 (SP3)

NTDDI_WINXPSP3 (0x05010300)

Windows XP 

with Service Pack 2 (SP2)

NTDDI_WINXPSP2 (0x05010200)

Windows XP 

with Service Pack 1 (SP1)

NTDDI_WINXPSP1 (0x05010100)

Windows XP

NTDDI_WINXP (0x05010000)


IE에 대한 버전도 설정이 되어 있습니다. IE는 아래의 표를 참고하시면 됩니다.


Minimum system required

Value for NTDDI_VERSION

IE 10.0

_WIN32_IE_IE100 (0x0A00)

IE 9.0

_WIN32_IE_IE90 (0x0900)

IE 8.0

_WIN32_IE_IE80 (0x0800)

IE 7.0

_WIN32_IE_IE70 (0x0700)

IE 6.0 SP2

_WIN32_IE_IE60SP2 (0x0603)

IE 6.0 SP1

_WIN32_IE_IESP1 (0x0601)

IE 6.0

_WIN32_IE_IE60 (0x0600)

IE 5.5

_WIN32_IE_IE55 (0x0550)

IE 5.01

_WIN32_IE_IE501 (0x0501)

IE 5.0, 5.0a, 5.0b

_WIN32_IE_IE50 (0x0500)



관련 링크 : http://msdn.microsoft.com/ko-kr/library/aa383745.aspx


이글이 도움이 되셨나요?
그렇다면 아래의 그림을 눌러주세요.



댓글