2013-12-27 1 views
0

에 대한 몇 가지 오류 : 파일 iweardrv.h을 포함 내가 추가 살고 있고 한C++ : 내 USB 주변 장치에서 데이터를 읽기 위해이 코드를 발견 CONST 문자 *와의 printf

#include "stdafx.h" 
#define IWEARDRV_EXPLICIT 
#include <windows.h> 
#include <iweardrv.h> 

int _tmain(int argc, _TCHAR* argv[]) 
{ 
    // Load functions dynamically (in case they don't have a VR920) 
    HINSTANCE iweardll = LoadLibraryA("iweardrv.dll"); 
    if (!iweardll) { 
     printf("VR920 drivers are not installed, you probably don't have a VR920."); 
     return 2; 
    } 

    IWROpenTracker = (PIWROPENTRACKER) GetProcAddress(iweardll, "IWROpenTracker"); 
    IWRCloseTracker = (PIWRCLOSETRACKER) GetProcAddress(iweardll, "IWRCloseTracker"); 
    IWRZeroSet = (PIWRZEROSET) GetProcAddress(iweardll, "IWRZeroSet"); 
    IWRGetTracking = (PIWRGETTRACKING) GetProcAddress(iweardll, "IWRGetTracking"); 
    IWRGetVersion = (PIWRGETVERSION) GetProcAddress(iweardll, "IWRGetVersion"); 

    // Try to connect to the VR920 tracker 
    if (IWROpenTracker()) { 
     printf("VR920 is not connected."); 
     return 1; 
    } 

    // Read 20 samples 
    for (int i=1; i<=20; i++) { 
     LONG y, p, r; 
     double yaw, pitch, roll; 
     if (!IWRGetTracking(&y,&p,&r)) { 
      yaw = y*(180.0/32768.0); 
      pitch = p*(180.0/32768.0); 
      roll = r*(180.0/32768.0); 
      printf("Yaw=%lf degrees, Pitch=%lf degrees, Roll=%lf degrees", yaw, pitch, roll); 
     } else { 
      printf("Unable to read tracking."); 
     } 
    Sleep(500); 
    } 

    // Tidy up 
    IWRCloseTracker(); 
    FreeLibrary(iweardll); 
    return 0; 
} 

디렉토리를 포함한다. 다음과 같은 오류 메시지가 표시됩니다.

IntelliSense: argument of type "const char *" is incompatible with parameter of type "LPCWSTR" 
IntelliSense: identifier "printf" is undefined 

오류를 방지하려면 어떻게합니까? 첫 번째 오류는 LoadLibrary 인수가 "iweardrv.dll" (동적 라이브러리는 iweardrv.h과 관련 있음)이며 두 번째 오류는 모두 printf 호출 줄을 나타냅니다.

편집 : const char*이 걸리기 때문에 LoadLibraryA()을 사용하여 첫 번째 오류를 수정했지만 두 번째 오류는 해결할 수 없습니다.

+0

코드가 이중 간격을두고 들여 쓰여져 있지 않으므로 읽기가 매우 어려웠습니다. (웹 양식에 복사 한 방식의 인공물이었을 수도 있습니다.) 나는 당신을 위해 그것을 고쳤습니다. –

답변

1

첫 번째 오류는 UNICODE가 정의되어 컴파일되고 LoadLibrary가 넓은 문자열을 예상하기 때문에 발생합니다. 넓은 문자를 지정하려면 L 접두사를 사용

LoadLibrary(L"iweardrv.dll"); 

두 번째 오류가 누락 된 #INCLUDE 때문이다. 당신은 정의 STDIO.H를 포함해야 printf와 :

C를 들어
#include <stdio.h> 

++는 표준 : : cout을하기보다는의 printf를 사용하는 것이 더 일반적인 것입니다.

+0

답장을 보내 주셔서 감사합니다. Studio를 포함하지만 이제는 다음을 반환합니다. 오류 오류 C1083 : 미리 컴파일 된 헤더 파일을 열 수 없습니다 : 'Debug \ file.pch': 해당 파일이나 디렉터리가 없습니다. – Orlok

+0

질문에 대한 답변을 생각합니다. 나 자신,이 같은 빠른 속박에 대해, 나는 미리 컴파일 된 헤더를 사용하지 않을 것이고, 나는 stdafx.h를 사용하지 않을 것이다. –

관련 문제