2012-02-27 4 views
0

이 샘플에서는 dwerror는 10045L이지만이 코드는 0x13d 값을 오류로 반환합니다. 형식 메시지를받는 방법은 무엇입니까? 우선이 오류를 해결하십시오. GetLastError 0x13d

TCHAR lpMsgBuf[512]; 
if(!FormatMessage(
    FORMAT_MESSAGE_ALLOCATE_BUFFER | 
    FORMAT_MESSAGE_FROM_SYSTEM, 
    NULL, 
    dwError, 
    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 
    (LPTSTR) &lpMsgBuf, 
    0, NULL)) 
{ 
    wprintf(L"Format message failed with 0x%x\n", GetLastError()); 
    return; 
} 
+0

오류 코드 '0x13d'가 무엇인지 찾아 보시기 바랍니다. 예를 들어 [here] (http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382%28v=vs.100% 29.aspx) –

답변

1

0x13d == 317 == ERROR_MR_MID_NOT_FOUND. 찾으려고하는 오류 메시지가 SYSTEM에 존재하지 않습니다. 오류가 특정 또는 드라이버에서 발생한 것일 수 있습니다. dll \ driver가 처리하려고하는 DLL을 알고 있고 FORMAT_MESSAGE_FROM_SYSTEM 대신 FORMAT_MESSAGE_FROM_HMODULE을 지정하고 FormatMessage을 호출 할 때 핸들을 소스로 제공하십시오.

그리고 그 외에 당신이 사용하는 경우

FORMAT_MESSAGE_ALLOCATE_BUFFER 당신은 LPTSTR pMsg; 같은 유형 LPTSTR의 변수를 선언하고 (LPTSTR)&pMsg로하는 formatMessage에 전달하고이 함께 할 때 그것은 할당 된 메모리를 해제 LocalFree(pMsg)를 사용해야합니다.

1

, 당신은 FORMAT_MESSAGE_ALLOCATE_BUFFER을 말할 때, 당신은 포인터보다 더 할당 할 필요가 없습니다. 그런 다음 lpBuffer에 해당 포인터에 대한 포인터를 전달합니다.

TCHAR* lpMsgBuf; 
if(!FormatMessage(
    FORMAT_MESSAGE_ALLOCATE_BUFFER | 
    FORMAT_MESSAGE_FROM_SYSTEM, 
    NULL, 
    dwError, 
    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 
    (LPTSTR) &lpMsgBuf, 
    0, NULL)) 
{ 
    wprintf(L"Format message failed with 0x%x\n", GetLastError()); 
    return; 
} 

을 그리고 LocalFree 사용

를 호출하는 것을 잊지 마세요 또는 당신이 자신을 버퍼 할당 : 그래서 이것을 시도 또한

TCHAR lpMsgBuf[512]; 
if(!FormatMessage(
    FORMAT_MESSAGE_FROM_SYSTEM, 
    NULL, 
    dwError, 
    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 
    (LPTSTR) lpMsgBuf, 
    512, NULL)) 
{ 
    wprintf(L"Format message failed with 0x%x\n", GetLastError()); 
    return; 
} 

을,이 시도 :

#include <cstdio> 
#include <cstdlib> 

int alloc(char** pbuff,unsigned int n) 
{ 
*pbuff=(char*)malloc(n*sizeof(char)); 
} 

int main() 
{ 
char buffer[512]; 

printf("Address of buffer before: %p\n",&buffer); 

// GCC sais: "cannot convert char (*)[512] to char** ... " 
// alloc(&buffer,128); 

// if i try to cast: 
alloc((char**)&buffer,128); 
printf("Address of buffer after: %p\n",&buffer); 

// if i do it the right way: 
char* p_buffer; 
alloc(&p_buffer,128); 
printf("Address of buffer after: %p\n",p_buffer); 


return 0; 
} 

그것은 않습니다 변수의 주소를 변경하려고하지 마십시오. 아마도 코드가 작동하지 않는 이유 일 것입니다.