1. 程式人生 > >c與c++ mfc 常用總結

c與c++ mfc 常用總結

1.從ini獲取的api

iParam = ::GetPrivateProfileInt("Common", "LocalPort", 2000, INI_FILE_NAME);

::GetPrivateProfileString("Common", "Subject", "", cParam, 255, INI_FILE_NAME);

2.char 相關操作

    char cParam[256];  

    1. memset(cParam, 0, 256); //清理

    2. if (cParam[0] == '\0') ; //為空

    3. memset(m_cDiviceName, 0, MAX_CHANNELNAME_LEN);

        strncpy(m_cDiviceName, pszName, MAX_CHANNELNAME_LEN - 1);// 兩個char*起始地址,及cstring 轉char[]

        CString str; 

        const char* p = (LPCTSTR)str; 

SetDeviceName(const char *pszName)

        pDevice->SetDeviceName(m_strDeviceName);//包含隱式轉換

    4. m_strTitle = cParam; // 即char[] 轉 cstring

    5. memcpy(&ruleInfo.head, pHead, sizeof(MsgHead));//取結構體的頭

3.delete [] m_pBuff;

   delete 釋放new分配的單個物件指標指向的記憶體

   delete[] 釋放new分配的物件陣列指標指向的記憶體

  delete[]   rg   用來釋放rg指向的記憶體,!!還逐一呼叫陣列中每個物件的destructor!!

4. GUID guid;  if (S_OK == ::CoCreateGuid(&guid))

5. FILE *pFile = fopen("HSIVSServerLog.log", "a+");

    or   m_pLogFile = new CLogFile("Supervise.log", DEFAULT_LOGFILE_SIZE);   

6. _snprintf(cTime, 30, "[%04d-%02d-%02d %02d:%02d:%02d]",
                currTime.GetYear(), currTime.GetMonth(), currTime.GetDay(),

                currTime.GetHour(), currTime.GetMinute(), currTime.GetSecond());

7. CString tmp = strChannelID;

    m_iChannelID[i] = atoi(tmp);

    CString strtemp; 

int i = 2334;    

     strtemp.Format("%d",i);