2017년 2월 19일 일요일

Gidplus를 사용한 MFC 버튼 이미지( Select, Disable, Mousehover, MouseLeave)

Gdiplus를 사용해서 resource의 이미지를 가져와 버튼에 이미지를 올리는 클래스다.

GdiplusBitmapBtn.h/GdiplusBitmapBtn.cpp

Bitmap 변수가 NULL일때

  • 생성자에

GdiplusStartupInput gdiStartUp;
::GdiplusStartup( &m_gdiToken, &gdiStartUp,NULL);

  • 소멸자에

::GdiplusShutdown(m_gdiToken);

  • 해더에
ULONG_PTR m_gdiToken;


를 추가해 준다.

< 퍼갈땐 퍼간다고 남겨주세요. >

2017년 2월 8일 수요일

UpdateData(TRUE) / UpdateData(FALSE)

간혹 기억이 안나서 적어 둠
UpdateData(TRUE) : 컨트롤의 값을 변수로
UpdateData(FALSE) : 변수의 값을 컨트롤로
MSDN

MFC에서 Add variable로 컨트롤의 변수나 클래스를 추가할때 스크립트 오류 메세지 발생시

DDX_ 가 호출되기 전에 DDV_가 작성되어 있으면 발생한다. DDX_가 먼저 작성되고 DDV_가 장성되도록 하자
ex) 이런 순서가 되도록
DDX_Text(pDX, IDC_EDIT, m_nInt);
DDV_inMaxUInt(pDX, m_nInt, 0, 1000);

2017년 1월 11일 수요일

4GB 이상 파일 포인터 지정( SetFilePointerEx )

4GB 이상의 파일의 파일포인터를 지정할때는 SetFilePointerEx를씀

int64_t llFileSeek (HANDLE hf, __int64 distance, DWORD MoveMethod)
{
LARGE_INTEGER li;
li.QuadPart = distance;
SetFilePointerEx(hf, li, &li, MoveMethod);
if (GetLastError() != NO_ERROR)
{
  li.QuadPart = -1;
}
    return li.QuadPart;
}


SetFilePointer를 쓸대는 QuadPart를 음수로 변환해서
난 잘 안되던데 왜인지.... 댓글좀
int64_t llFileSeek (HANDLE hf, __int64 distance, DWORD MoveMethod)
{
LARGE_INTEGER li;
li.QuadPart = -distance;
SetFilePointerEx(hf, li, &li, MoveMethod);
if (GetLastError() != NO_ERROR)
{
   li.QuadPart = -1;
}
    return li.QuadPart;
}

2016년 12월 5일 월요일

2016년 1월 12일 화요일

Invalid Address specified to RtlFreeHeap 에러 메세지

This may be due to a corruption of the heap, which indicates a bug in xxxx.exe or any of the DLLs it has loaded.
This may also be due to the user pressing F12 while xxxx.exe has focus.
The output window may have more diagnostic information.

이러한 에러가 나올때

http://egloos.zum.com/saintrv/v/1560122


위의 에러메세지가 호출될 경우,
New와 Delete 혹은 malloc과 free과 잘못 Match 되어 있을 가능성이 높다.
이는 DLL에서 지정한 메모리를 EXE에서 풀거나 할 때도 발생 된다.

이를테면 아래와 같은 소스의 경우

 uri = parser->getSubjectURI();

 if (uri)
 {
  fprintf(stdout, "-Subject URI: [%s]\n", (char*)uri);
  delete uri;
 }

내부에서 지정한 메모리를 외부에서 풀려고 하니 문제가 발생한다. (MultiThread 일 경우에 이 같은 현상이 나타나지 않아야 할 것 같은데 나타난다...)
이를 내부 메모리 해제 함수를 두어서 아래와 같이 수정할 경우

 uri = parser->getSubjectURI();

 if (uri)
 {
  fprintf(stdout, "-Subject URI: [%s]\n", (char*)uri);
  parser->freeliteral(uri);  
 }

해결된다. 


하지만 위의 방법으로 안될 경우에는 아래를 참고한다.

[펌]
Visual Studio를 사용하다 보면
Invalid Address specified to RtlFreeHeap와 같은 에러가 발생할 때가 있습니다.
주로 DLL을 이용한 프로그램을 만들때에 이런 에러가 발생하는데요.
이거가지고 삽질을 많이 하다가 해결 방법을 발견했습니다.

간단히 답만 말씀드리면
프로그램에서 사용하는 DLL들과 메인 프로그램 모두의 설정을 다음과 같이 바꿔주어야 합니다.

Setting -> C/C++ --> Code Generation --> MultiThreaded DLL (Debug모드일 경우 MultiThreaded DLL Debug)

그러면 위와 같은 에러가 없어집니다.
해결 방법은 여기에서 발견했습니다^^