카테고리 없음2017. 8. 17. 17:24

size_t 타입

32bit : unsigned int

64bit : unsigned long long


Posted by 좋은나무
카테고리 없음2015. 6. 11. 16:55

* 함수 닫기/펼치기

CTRL + M + O : 모두 닫기

CTRL + M + L : 모두 펼치기


* 대소문자 변환

(블럭 선택 후) CTRL + SHIFT + U : 대문자로 변환

(블럭 선택 후) CTRL + U : 소문자로 변환


* 줄 단위 복사/잘라내기

(블럭 선택 없이) CTRL + C : 한 줄 복사

(블럭 선택 없이) CTRL + X  (또는 SHIFT + DEL) : 한 줄 잘라내기


[참조]

Visual Studio - Command to collapse all sections of code?

Visual Studio : short cut Key : Duplicate Line


Posted by 좋은나무
카테고리 없음2015. 6. 5. 15:24

방법 1) #pragma pack(#)


#pragma pack(push,8)

struct T {

   int i;

   short j;

   double k;

};

#pragma pack(pop)


방법 2__declspec(align(#))


_declspec(align(8)) struct T {

   int i;

   short j;

   double k;

};


[참고 자료]

Supporting 32-Bit I/O in Your 64-Bit Driver

#pragma pack

__declspec(align(#))

Posted by 좋은나무
카테고리 없음2014. 6. 13. 10:37

// 가변인자를 사용한 디버깅 로그 쓰기 예시


void WriteLog(LPCTSTR pszFmt, ...)

{

va_list argList;

va_start(argList, pszFmt);


// 가변인자 사용시 문자열 길이 구하기

int nLength = _vsctprintf(pszFmt, argList);


// 버퍼 메모리 할당

TCHAR * szLog = new TCHAR[(nLength+1)*sizeof(TCHAR)];


// 로그 문자열 생성

_vstprintf_s(szLog, (nLength+1)*sizeof(TCHAR), pszFmt, argList);


va_end(argList);


// 디버깅 로그 쓰기

::OutputDebugString(szLog);

::OutputDebugString(_T("\n"));


// 버퍼 메모리 해제

delete [] szLog;

szLog = NULL;

}

Posted by 좋은나무
카테고리 없음2008. 7. 7. 01:06
CFtpFileFind 는 재귀 호출시 약간의 주의가 필요하다.
재귀 호출중, 이전으로 돌아갈 때,
다음 파일 또는 폴더에 대해서 CFtpFileFind::FindFile() 을 한번 더 호출해 주어야 한다.
하지만,  CFtpFileFind::FindNextFile() 을 호출하는 파일 탐색 중에는 다음 파일 정보를 미리 알 수 없으므로,
다음과 같이 파일 수집과, 재귀 호출을 분리하여, 두번의 루프를 사용해야 한다.

// 이하, 약식 코드

CFilInfo : user defined file information class...

CInternetSession * m_pInternetSession = new CInternetSession;
CFtpConnection * m_pFTPConnection = (CFtpConnection*) m_pInternetSession->GetFtpConnection(szAddress);
CFtpFileFind * m_pFtpFind = new CFtpFileFind(m_pFTPConnection);

BOOL GetFTPFileListRecursive(CFilInfo *pFileInfo)
{
   CString strPath;
   strPath.Format(_T("%s/*"), pFileInfo->GetRemotePath());
   
   m_pFTPConnection->SetCurrentDirectory(pFileInfo->GetRemotePath());
      
    // gathering child file list first...
   BOOL bContinue = m_pFtpFind->FindFile(strPath);
   while (bContinue)
   {
       bContinue = m_pFtpFind->FindNextFile();       
       ////////
       if (m_pFtpFind->IsDots() == FALSE )
           continue;
      
       if(m_pFtpFind->IsDirectory() == TRUE)
       {   
           // create file information.
           CFileinfo * pFileChild = new CFileInfo;
           pFileChild->SetIsDirectory(TRUE); // mark directory flag.
          
           // do something...
           // ... m_pFtpFind->GetFileName() ...

           // save child file
           pFileInfo->AddChild(pFileChild);

           ////////
           // invalid usage !!!
           // GetFTPFileListRecursive(pFileChild);
           // m_pFTPConnection->SetCurrentDirectory(pFileInfo->GetRemotePath());                       
           ////////
       }
       else
       {           
           // do something...
           // ... pftpFind->GetFileName() ...
       }
   }
  
  // recursive calling here   
   INT_PTR nSize = pFileInfo->GetChildCount();
   for(INT_PTR iCnt = 0; iCnt < nSize; iCnt++)
   {
       CFileInfo * pFileInfoChild = pFileInfo->GetChild(iCnt);
       if( pFileInfoChild == NULL )
           continue;

       if( pFileInfoChild->GetIsDirectory() == FALSE )
           continue;

       GetFTPFileListRecursive(pFileInfoChild);
   }
  
   return TRUE;
}
Posted by 좋은나무
카테고리 없음2008. 6. 24. 00:14
//  파일탐색기에서 드래그앤드롭한 파일의 이름을 구해서 리스트컨트롤에 추가

////////////////////////////////////////////
// FileDropListCtrl.h

#pragma once

#include <afxole.h>

////////////////////////////////////////////
// CFileDropTarget

class CFileDropTarget : public COleDropTarget
{
public:
    CFileDropTarget(CWnd* pWnd){m_pParent = pWnd;}
    ~CFileDropTarget(){}

private:
    CWnd* m_pParent;

private:
    BOOL        OnDrop(CWnd* pWnd, COleDataObject* pDataObject, DROPEFFECT dropEffect, CPoint point);
    DROPEFFECT  OnDragEnter(CWnd* pWnd, COleDataObject* pDataObject, DWORD dwKeyState, CPoint point);
    void        OnDragLeave(CWnd* pWnd);
    DROPEFFECT  OnDragOver(CWnd* pWnd, COleDataObject* pDataObject, DWORD dwKeyState, CPoint point);
    DROPEFFECT  OnDragScroll(CWnd* pWnd, DWORD dwKeyState, CPoint point);

public:
    void SetParent(CWnd* pWnd) { m_pParent = pWnd;}
    BOOL FileNamesToList( HDROP hDrop, CPoint point );
};

////////////////////////////////////////////
// CFileDropListCtrl

class CFileDropListCtrl : public CListCtrl
{
    DECLARE_DYNAMIC(CFileDropListCtrl)

public:
    CFileDropListCtrl();
    virtual ~CFileDropListCtrl();

protected:
    DECLARE_MESSAGE_MAP()

    afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);

private:
    CFileDropTarget m_dropTarget;

public:
    void FileDropRegister();

};




///////////////////////////////////////////////////
// FileDropListCtrl.cpp
//

#include "stdafx.h"
#include "FileDropListCtrl.h"

////////////////////////////////////////////////////
// CFileDropTarget


DROPEFFECT CFileDropTarget::OnDragScroll(CWnd* /*pWnd*/, DWORD /*dwKeyState*/, CPoint /*point*/)
{
   // return DROPEFFECT_SCROLL | DROPEFFECT_COPY | DROPEFFECT_LINK;
       return DROPEFFECT_SCROLL | DROPEFFECT_COPY;
}

DROPEFFECT CFileDropTarget::OnDragEnter(CWnd* /*pWnd*/, COleDataObject* /*pDataObject*/,
                                      DWORD /*dwKeyState*/, CPoint /*point*/)
{
    return DROPEFFECT_COPY;
}

void CFileDropTarget::OnDragLeave(CWnd* /*pWnd*/)
{
}

DROPEFFECT CFileDropTarget::OnDragOver(CWnd* /*pWnd*/, COleDataObject* /*pDataObject*/,
                                     DWORD /*dwKeyState*/, CPoint /*point*/)
{
    return DROPEFFECT_COPY;
}

BOOL CFileDropTarget::OnDrop(CWnd* /*pWnd*/, COleDataObject* pDataObject,
                           DROPEFFECT /*dropEffect*/, CPoint point)
{
    try
    {
        if( pDataObject->IsDataAvailable( CF_HDROP ) )
        {
            STGMEDIUM StgMed;
            FORMATETC fmte = {CF_HDROP, (DVTARGETDEVICE FAR *)NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
            if( pDataObject->GetData( CF_HDROP, &StgMed, &fmte ) )
            {
                if(! FileNamesToList( (HDROP)StgMed.hGlobal, point ) )
                {
                    return FALSE;
                } // if(! FileNamesToList( (HDROP)StgMed.hGlobal, point ) )

                if (StgMed.pUnkForRelease)
                {
                    StgMed.pUnkForRelease->Release();
                }
                else   
                {
                    ::GlobalFree(StgMed.hGlobal);
                } // if (StgMed.pUnkForRelease)...else
                return TRUE;
            } // if( pDataObject->GetData( CF_HDROP, &StgMed, &fmte ) )
        } // if( pDataObject->IsDataAvailable( CF_HDROP ) )
    } // try
    catch(...)
    {
        return FALSE;
    }
    return TRUE;
}


BOOL CFileDropTarget::FileNamesToList( HDROP hDrop, CPoint point )
{
    UINT cFiles = ::DragQueryFile(hDrop, (UINT)-1, NULL, 0);              
  
    if(cFiles <= 0)
    {
        return FALSE;
    }

    TCHAR szFile[MAX_PATH];
  
    for( UINT count = 0; count < cFiles; count++ )
    {
        ::DragQueryFile(hDrop, count, szFile, sizeof(szFile));

        if( (m_pParent != NULL ) && ( ::IsWindow( m_pParent->GetSafeHwnd() ) != FALSE))
        {
            CListCtrl * pListCtrl = dynamic_cast<CListCtrl*>(m_pParent);
            if( pListCtrl != NULL )
            {
                UINT uFlags;
                int nItem = pListCtrl->HitTest(point, &uFlags);              

                CString strItem;
                strItem.Format(_T("file=%s, nItem=%d, flag=0x%04x"),szFile, nItem, uFlags );
                pListCtrl->InsertItem(0, strItem);
            } //  if( pListCtrl != NULL )
        } // if( (m_pParent != NULL ) && ( ::IsWindow( m_pParent->GetSafeHwnd() ) != FALSE))

    } // for( UINT count = 0; count < cFiles; count++ )

    return TRUE;
}




////////////////////////////////////////////////////
// CFileDropListCtrl

IMPLEMENT_DYNAMIC(CFileDropListCtrl, CListCtrl)

CFileDropListCtrl::CFileDropListCtrl() : m_dropTarget(this)
{
}

CFileDropListCtrl::~CFileDropListCtrl()
{
}


BEGIN_MESSAGE_MAP(CFileDropListCtrl, CListCtrl)
    ON_WM_CREATE()  
END_MESSAGE_MAP()



// CFileDropListCtrl 메시지 처리기입니다.

int CFileDropListCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CListCtrl::OnCreate(lpCreateStruct) == -1)
        return -1;

    // TODO:  여기에 특수화된 작성 코드를 추가합니다.
    FileDropRegister();

    return 0;
}

void CFileDropListCtrl::FileDropRegister()
{
    DragAcceptFiles();
    m_dropTarget.Register(this); 
}


Posted by 좋은나무
카테고리 없음2008. 5. 8. 16:36
map 에서 wstring, string 을 키값으로 사용할 때 발생가능한 에러
작성일 : 2008-05-08
--------

    std::map <std::wstring, std::wstring> m1;
   typedef std::pair <std::wstring, std::wstring> wstring_pair; // <-- 에러 발생 시점
   m1.insert ( wstring_pair ( L"key", L"value" ) );

또는

    std::map <std::string, std::string> m1;
   typedef std::pair <std::string, std::string> string_pair; // <-- 에러 발생 시점
   m1.insert ( string_pair ( "key", "value" ) );

에서

오류    1    error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : 'const std::_Tree<_Traits> &'의 템플릿 인수를 'const std::wstring'에서 추론할 수 없습니다.    c:\program files\microsoft visual studio 8\vc\include\functional    143

또는

오 류    1    error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : 'const std::_Tree<_Traits> &'의 템플릿 인수를 'const std::string'에서 추론할 수 없습니다.    c:\program files\microsoft visual studio 8\vc\include\functional    143

이런 에러 발생시...

원인 및 해결책

#include <string> 이 선언되지 않았음. 소스코드에 추가할 것.

Posted by 좋은나무