现在的位置: 首页 > 综合 > 正文

dll支持CString(支持unicode)

2014年01月04日 ⁄ 综合 ⁄ 共 615字 ⁄ 字号 评论关闭

 

一般情况下,vc6.0编写的动态dll不支持CString。表现状况是,编写dll中使用CString报错,在你正确添加afx.h头文件,删掉DllMain函数后,能正确生成dll文件,就是调用该dll文件的时候,程序莫名死掉。如要在dll中使用CSrting正确的方法如下:
//stdafx.h
 //......
 
  #include <afx.h>  // 添加,加在这里
  #include <windows.h>//原来默认有的
  
  //添加的
  #ifdef _DEBUG
   #pragma comment(lib, "libcmtd.lib")//crt多线程debug库
  #else
   #pragma comment(lib, "libcmt.lib")//crt多线程库
  #endif
  
  //......stdafx.h文件结束
  
  
//*.cpp文件  
//......

// The following symbol used to force inclusion of this module for _USRDLL
#ifdef _X86_
extern "C" { int _afxForceUSRDLL; }//添加的部分
#else
extern "C" { int __afxForceUSRDLL; }
#endif  

//原有的dllmain函数
BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
      )
{
    return TRUE;
}

抱歉!评论已关闭.