728x90
MFC에서 문자열을 변환하는 과정에서 Runtime Exception 이 발생했고 내용은 위와 같았다
Microsoft Visual C++ Runtime Library
Debug Assertion Failed!
Program: -
File: minkernel\crts\ucrt\inc\corecrt_internal_stdio_output.h Line: 1690
Expression: ("Incorrect format specifier", 0)
For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts.
(Press Retry to debug the application)
코드를 추적해 보니
sprintf_s(szSendBuffer, sizeof(szSendBuffer), m_csSendData.GetBuffer())
위 부분이었는데 CString을 char array로 변경하는 간단한 코드였다.
원인을 확인해 보니 CString인 m_csSendData 변수에 "%"라는 특수문자가 있었고 sprintf 특성상 이 특수문자가 뒤의 문자와 결합하려고 시도하였고(예: %s, %d) 존재하지 않는 서식문자이기에 에러가 발생하였던 것이다
아래는 수정된 코드
strcpy_s(szSendBuffer, sizeof(szSendBuffer), CT2A(m_csSendData));
이상 끝~
728x90
'운동하는 개발자 > c++' 카테고리의 다른 글
MFC 다른 솔루션의 Dialog 복사 방법 Visual Studio (0) | 2025.02.06 |
---|---|
MFC char* to Hex (부제 : DLL의 응답 값 변환하여 로그 찍기) (0) | 2025.01.19 |
MFC] 프로세스에 연결할 수 없습니다. 지정된 파일을 찾을 수 없습니다. (0) | 2024.10.11 |
C++로 Windows 환경에서 코드 동작 시간 체크 (feat. GetTickCount64의 오류) (0) | 2024.03.27 |
Visual studio Stack overflow (Stack Reserve Size) (0) | 2023.11.29 |