本帖最后由 yingqichen 于 2010-02-24 11:34:44 编辑

解决方案 »

  1.   

    看了半天MSDN,再花半小时查MSDNThe _strdup function calls malloc to allocate storage space for a copy of strSource and then copies strSource to the allocated space.下面的懂吗?
    int FuncA(LPCTSTR lpstr)
    {
       if (lpszAppName != NULL)
           strcpy(m_pszAppName, lpstr);
       else
           m_pszAppName = NULL;
    }LPCTSTR,这个懂吗?lpstr,这个懂吗?相同的道理
      

  2.   

    CWinApp::m_pszAppName说明:
    指定应用程序的名字。应用程序可以从传递给CWinApp的构造函数的参数中得到,如果其中没有指定名字,则是ID为AFX_IDS_APP_TITLE的资源字符串。如果在资源中找不到应用程序的名字,那么它来自程序的可执行文件名。全局函数AfxGetAppName返回该值。m_pszAppName是const char* 类型的公有变量。
      

  3.   

    The _strdup function calls malloc to allocate storage space for a copy of strSource and then copies strSource to the allocated space. 就是分配目的串内存空间,然后将源字符串的内容copy到目的串中。(加一句,用完以后记得要free掉目的串的内存)
    看看这个MSDN的例子就懂了:
    // crt_strdup.c#include <string.h>
    #include <stdio.h>int main( void )
    {
       char buffer[] = "This is the buffer text";
       char *newstring;
       printf( "Original: %s\n", buffer );
       newstring = _strdup( buffer );
       printf( "Copy:     %s\n", newstring );
       free( newstring );
    }输出:
    Original: This is the buffer text
    Copy:     This is the buffer text
      

  4.   


    看懂了 m_pszAppName = _tcsdup(lpszAppName);这句代码的意思就是把lpszAppName这个字符串内容复制到变量m_pszAppName中 对吗
      

  5.   


    是分配字符串lpszAppName长度的内存,然后返回地址指针复制给m_pszAppName
    相当于
    char *buf = (char *)malloc(strlen(lpszAppName) + 1);
    strcpy(buf, lpszAppName);m_pszAppName = buf;
      

  6.   

    m_pszAppName = _tcsdup(lpszAppName);
    是分配字符串lpszAppName长度的内存,然后返回地址指针赋值给m_pszAppName 
    相当于LPCSTR buf = (LPCSTR)malloc((_tcslen(lpszAppName) + 1) * sizeof(TCHAR));
    _tcscpy(buf, lpszAppName);m_pszAppName = buf;
      

  7.   

    没法修改帖子就是麻烦
    LPTSTR buf = (LPTSTR)malloc((_tcslen(lpszAppName) + 1) * sizeof(TCHAR)); 
    _tcscpy(buf, lpszAppName); m_pszAppName = buf;