ATL项目中如何将cstring转为string
本帖最后由 jxsdpengbin 于 2012-12-28 16:05:40 编辑 // server8.cpp : WinMain 的实现
#include "stdafx.h"
#include "resource.h"
#include "server8_i.h"
#include <atlstr.h>
#include <stdio.h>
using namespace ATL;
class Cserver8Module : public ATL::CAtlServiceModuleT< Cserver8Module, IDS_SERVICENAME >
{
public :
DECLARE_LIBID(LIBID_server8Lib)
DECLARE_REGISTRY_APPID_RESOURCEID(IDR_SERVER8, "{2FA5D6ED-5A62-4B1A-A582-81EE32182A5D}")
HRESULT InitializeSecurity() throw()
{
// TODO : 调用 CoInitializeSecurity 并为服务提供适当的安全设置
// 建议 - PKT 级别的身份验证、
// RPC_C_IMP_LEVEL_IDENTIFY 的模拟级别
// 以及适当的非 null 安全说明符。
return S_OK;
}
};
Cserver8Module _AtlModule;
//
extern "C" int WINAPI _tWinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/,
LPTSTR /*lpCmdLine*/, int nShowCmd)
{
CString cstr=_T("127.0.0.1");;
string str;//编译不通过,报错,没有定义的string
//想通过cstr转为str后,传参给第三函数,因为第三方函数只接受string参数
return _AtlModule.WinMain(nShowCmd);
}
[解决办法]