char szTemp[MAX_PATH];
// Setup the .ini file to use
free((void*)m_pszProfileName);
GetModuleFileName(NULL,szTemp,sizeof(szTemp));
m_pszProfileName=_tcsdup(_T(SplitFileName(szTemp,DRIVE|PATH|FNAME)+".ini"));上面语句是我看一个例子上的!找遍project也没发现m_pszProfileName的定义!
但free释放啥呀?
_tcsdup是啥啊,起什么作用啊?
_T是啥啊,起什么作用啊?

解决方案 »

  1.   

    The _strdup function calls malloc to allocate storage space for a copy of strSource and then copies strSource to the allocated space._wcsdup and _mbsdup are wide-character and multibyte-character versions of _strdup. The arguments and return value of _wcsdup are wide-character strings; those of _mbsdup are multibyte-character strings. These three functions behave identically otherwise.Generic-Text Routine MappingsTCHAR.H Routine  _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined 
    _tcsdup _strdup _mbsdup  _wcsdup 
    Because _strdup calls malloc to allocate storage space for the copy of strSource, it is good practice always to release this memory by calling the free routine on the pointer returned by the call to _strdup.
      

  2.   

    The _strdup function calls malloc to allocate storage space for a copy of strSource and then copies strSource to the allocated space._wcsdup and _mbsdup are wide-character and multibyte-character versions of _strdup. The arguments and return value of _wcsdup are wide-character strings; those of _mbsdup are multibyte-character strings. These three functions behave identically otherwise.Generic-Text Routine MappingsTCHAR.H Routine  _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined 
    _tcsdup _strdup _mbsdup  _wcsdup 
    Because _strdup calls malloc to allocate storage space for the copy of strSource, it is good practice always to release this memory by calling the free routine on the pointer returned by the call to _strdup.
      

  3.   

    The free function deallocates a memory block (memblock) that was previously allocated by a call to calloc, malloc, or realloc.
      

  4.   

    TCHAR跟据编译选项确定是char还是w_char.
    char对应的操作函数以str开头,如strlen(),w_char对应的则以_wcs开头,如_wcslen()
    对应于TCHAR,_tcs开头的函数据编译选项确定是str还是_wcs,----它们本质上只是个宏而已。
    _tcsdup():复制字符串。
      

  5.   

    CWinApp::m_pszProfileName See Also
    CWinApp Overview | Class Members | Hierarchy Chart | CWinApp::GetProfileString | CWinApp::GetProfileInt | CWinApp::WriteProfileInt | CWinApp::WriteProfileStringContains the name of the application's .INI file.
    LPCTSTR m_pszProfileName;
    Res
    m_pszProfileName is a public variable of type const char*.
    Note   If you assign a value to m_pszProfileName, it must be dynamically allocated on the heap. The CWinApp destructor calls free( ) with this pointer. You many want to use the _tcsdup( ) run-time library function to do the allocating. Also, free the memory associated with the current pointer before assigning a new value. For example:
    //First free the string allocated by MFC at CWinApp startup.
    //The string is allocated before InitInstance is called.
    free((void*)m_pszProfileName);
    //Change the name of the .INI file.
    //The CWinApp destructor will free the memory.
    m_pszProfileName=_tcsdup(_T("d:\\somedir\\myini.ini"));
      

  6.   

    _strdup 是在堆上创建一个空间,用来所复制的字符串大小
    使用后,用free释放