인스턴스 변수의 value값이 ffffffff가 됩니다.

kamui_0021의 이미지

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
 
SerialPort::SerialPort()
{
	m_hComm = INVALID_HANDLE_VALUE; //시리얼 통신을 위한 핵심 인스턴스 변수 (디버깅에서 cdcdcdcd로 값을 받음을 확인함)
	//m_hComm = NULL;
	m_bOverlapped = FALSE;
	m_strPortName = "";
}
 
SerialPort::~SerialPort()
{
	Close();
}
 
void SerialPort::Open(const CCommInfo& info)
{
	if(_heapchk() != _HEAPOK) //heap 메모리 에러 확인용
			DebugBreak();
	Open(info.portNo, info.baudRate, (Parity)info.parity, (BYTE)info.byteSize, (StopBits)info.stopBits);
}
 
void SerialPort::Open(int nPort, DWORD dwBaud, Parity parity, BYTE DataBits, StopBits stopbits, FlowControl fc, BOOL bOverlapped)
{
	if(_heapchk() != _HEAPOK) //heap 메모리 에러 확인용
			DebugBreak();
	//Validate our parameters
	ASSERT(nPort>0 && nPort<=255);
 
	//Call CreateFile to open up the comms port
	CString sPort;
	if( nPort < 10 )
		sPort.Format("COM%d", nPort);
	else 
		sPort.Format("\\\\.\\COM%d", nPort);
 
	m_hComm = CreateFile(sPort, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, bOverlapped /*? FILE_FLAG_OVERLAPPED : 0*/, NULL);
        //m_hComm이 함수 실행후에 받는 값이 ffffffff 입니다.
	if (m_hComm == INVALID_HANDLE_VALUE)
	{
                //실제로는 전부 통과하고 바로 throw SerialException으로 이동하여 heap메모리 충돌로 프로그램 전체가 종료합니다 
		if(_heapchk() != _HEAPOK) //heap 메모리 에러 확인용
			DebugBreak();
		CloseHandle(m_hComm);
		Close();
		TRACE(_T("Failed to open up the comms port\n"));
		throw SerialException(::GetLastError());
	}
 
        // 그리고 아래 중략(수많은 코드들이 있었음)
		default:
		{
			break;
		}
	}
 
	//Now that we have all the settings in place, make the changes
	SetState(dcb);
 
 
	s_CommList.AddTail(this); // Do we need this?
}

이런 코드의 상황입니다 (물론 이 코드가 win32 api 표준을 따르고 있기에 문제가 없어 보일수 있습니다)
그렇지만, m_hComm변수의 값이 ffffffff가 되는 것에서 문제가 발생된다고 여겨집니다...

파일생성 함수에서의 문제인지, 아니면 다른 변수의 값으로 인한 문제가 변수 초기화도 거치지 않고 바로 에러처리 루틴으로 빠지는지...(에러 처리 루틴에서도 결국은 메모리 heap문제로 판별해서 프로그램 전체 종료를 시킵니다)

peecky의 이미지

https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea#return-value

Quote:
If the function fails, the return value is INVALID_HANDLE_VALUE. To get extended error information, call GetLastError.

GetLastError 호출해서 에러 원인을 알아보세요.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.