2012-07-25 3 views
0

내 C 코드에 #include <strsafe.h>으로 선언 된 다음 코드를 컴파일하고 DEV-C++에서 다음 컴파일러 오류가 발생합니다. 이 문제를 해결하려면 컴파일러에 몇 가지 옵션이 있어야합니다. 누군가가 이것을 해결할 수 있습니까? 오류의 거대한 세트에서 오류DEV-C++의 컴파일러 오류

#include <windows.h> 
#include <strsafe.h> 

void ErrorExit(LPTSTR lpszFunction) 
{ 
    // Retrieve the system error message for the last-error code 

    LPVOID lpMsgBuf; 
    LPVOID lpDisplayBuf; 
    DWORD dw = GetLastError(); 

    FormatMessage(
     FORMAT_MESSAGE_ALLOCATE_BUFFER | 
     FORMAT_MESSAGE_FROM_SYSTEM | 
     FORMAT_MESSAGE_IGNORE_INSERTS, 
     NULL, 
     dw, 
     MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 
     (LPTSTR) &lpMsgBuf, 
     0, NULL); 

    // Display the error message and exit the process 

    lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT, 
     (lstrlen((LPCTSTR)lpMsgBuf) + lstrlen((LPCTSTR)lpszFunction) + 40) * sizeof(TCHAR)); 
    StringCchPrintf((LPTSTR)lpDisplayBuf, 
     LocalSize(lpDisplayBuf)/sizeof(TCHAR), 
     TEXT("%s failed with error %d: %s"), 
     lpszFunction, dw, lpMsgBuf); 
    MessageBox(NULL, (LPCTSTR)lpDisplayBuf, TEXT("Error"), MB_OK); 

    LocalFree(lpMsgBuf); 
    LocalFree(lpDisplayBuf); 
    ExitProcess(dw); 
} 

void main() 
{ 
    // Generate an error 

    if(!GetProcessId(NULL)) 
     ErrorExit(TEXT("GetProcessId")); 
} 

샘플 :

아래는 MSDN 사이트에서 가져옵니다 내 샘플 코드입니다.

154 26 C:\Documents and Settings\[email protected]\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h 
[Error] expected '=', ',', ';', 'asm' or '__attribute__' before 'char' 
155 26 C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h 
[Error] expected '=', ',', ';', 'asm' or '__attribute__' before 'const' 
156 1 C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h 
[Error] unknown type name '__nullterminated' 
156 33 C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h 
[Error] expected '=', ',', ';', 'asm' or '__attribute__' before '*' token 
157 26 C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h 
[Error] expected '=', ',', ';', 'asm' or '__attribute__' before 'const' 
158 26 C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h 
[Error] expected '=', ',', ';', 'asm' or '__attribute__' before 'const' 
164 38 C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h 
[Error] expected '=', ',', ';', 'asm' or '__attribute__' before 'const' 
165 38 C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h 
[Error] expected '=', ',', ';', 'asm' or '__attribute__' before 'const' 
166 38 C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h 
[Error] expected '=', ',', ';', 'asm' or '__attribute__' before 'const' 
173 10 C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h 
[Error] unknown type name 'STRSAFE_PCNZCH' 
174 10 C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h 
[Error] unknown type name '__in_range' 
175 15 C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h 
[Error] unknown type name '__deref_out_range' 
179 10 C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h 
[Error] unknown type name 'STRSAFE_PCNZWCH' 
180 10 C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h 
[Error] unknown type name '__in_range' 
181 15 C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h 
[Error] unknown type name '__deref_out_range' 
193 5 C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h 
[Error] unknown type name '__deref_in_opt_out' 
194 17 C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h 
[Error] unknown type name '__deref_out_range' 
200 5 C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h 
[Error] unknown type name '__deref_in_opt_out' 
201 17 C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h 
[Error] unknown type name '__deref_out_range' 
207 30 C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h 
[Error] unknown type name 'STRSAFE_PCNZCH' 
213 30 C:\Documents and Settings\mkumar\Desktop\DEVC\TEST-install-Driver-Difx\TO-DO\strsafe.h 
[Error] unknown type name 'STRSAFE_LPCSTR' 
continues....... 

A I 위의 오류를 얻고있는 곳에서 strsafe.h 파일의 일부 :

// 
// These typedefs are used in places where the string is guaranteed to 
// be null terminated. 
// 
typedef __nullterminated char* STRSAFE_LPSTR; 
typedef __nullterminated const char* STRSAFE_LPCSTR; 
typedef __nullterminated wchar_t* STRSAFE_LPWSTR; 
typedef __nullterminated const wchar_t* STRSAFE_LPCWSTR; 
typedef __nullterminated const wchar_t UNALIGNED* STRSAFE_LPCUWSTR; 

// 
// These typedefs are used in places where the string is NOT guaranteed to 
// be null terminated. 
// 
typedef __possibly_notnullterminated const char* STRSAFE_PCNZCH; 
typedef __possibly_notnullterminated const wchar_t* STRSAFE_PCNZWCH; 
typedef __possibly_notnullterminated const wchar_t UNALIGNED* STRSAFE_PCUNZWCH; 


// prototypes for the worker functions 

STRSAFEWORKERAPI 
StringLengthWorkerA(
    __in STRSAFE_PCNZCH psz, 
    __in __in_range(<=, STRSAFE_MAX_CCH) size_t cchMax, 
    __out_opt __deref_out_range(<, cchMax) size_t* pcchLength); 

STRSAFEWORKERAPI 
StringLengthWorkerW(
    __in STRSAFE_PCNZWCH psz, 
    __in __in_range(<=, STRSAFE_MAX_CCH) size_t cchMax, 
    __out_opt __deref_out_range(<, cchMax) size_t* pcchLength); 

#ifdef ALIGNMENT_MACHINE 
STRSAFEWORKERAPI 
UnalignedStringLengthWorkerW(
    __in STRSAFE_PCUNZWCH psz, 
    __in __in_range(<=, STRSAFE_MAX_CCH) size_t cchMax, 
    __out_opt __deref_out_range(<, cchMax) size_t* pcchLength); 
#endif // ALIGNMENT_MACHINE 

STRSAFEWORKERAPI 
StringExValidateSrcA(
    __deref_in_opt_out STRSAFE_LPCSTR* ppszSrc, 
    __inout_opt __deref_out_range(<, cchMax) size_t* pcchToRead, 
    __in const size_t cchMax, 
    __in DWORD dwFlags); 
+4

문제 코드를 게시해도 도움이 될 것입니다. – dandan78

+0

[SSCE] (http://sscce.org/)를 작성하고 질문을 편집하여 코드를 포함 시키십시오. –

+0

유일한 오류는 strsafe.h입니다. – 2vision2

답변

2

__nullterminated, __out_opt, __in, __in_opt 및 기타 단어는 마이크로 소프트 고유의 키워드입니다. gcc를 사용할 때 공백 매크로가되도록 정의 할 수 있습니다.

#define __in 
#define __deref_out_range(A,B) 
... and so on 

포함하기 전에 정의를 삽입하십시오.

또는 의견은 <strsafe.h>

편집 사용하지 않는 것이 좋습니다 같이

는 MinGW (64는 http://equation.com에서 구축) 위에서 조용히 (심지어 strsafe.h 포함)이 코드를 컴파일 단순한 명령 :

gcc -c Test.cpp -o Test.exe -lstdc++ 
+0

모든 매크로를 정의하고 싶습니까? 다른 컴파일러 옵션을 사용하는 것과 같은 방법으로이를 피할 수 있습니까? 그리고 죄송합니다. 코멘트에서 그들이 strsafe.h를 사용하는 것을 피하도록 말한 곳을 묻습니다. – 2vision2

+0

나는 단지 나를 위해 일한 솔루션을 제안합니다. (저는 MinGW/GCC와 함께 DirectX 11 헤더를 사용했습니다 - 거기에는 __in_opt와 물건). 그건 그렇고, MinGW로 코드를 검사하고 조용히 컴파일합니다. –

+0

그래, 고마워. 가능한 경우 컴파일에 사용되는 명령을 알 수 있습니까? 내 devcon은 내부적으로 Mingw 만 호출하기 때문에. – 2vision2