STDMETHODIMP CATLCOM:: ComAppend( BSTR inStrIP,int port,BSTR password,BSTR* outValuse)
{
std::ofstream outfile;
outfile.open("log.txt");
if(outfile.is_open())
{
outfile<<"--------------------------------------------------------------------------------------------------------------------------------------------"<<endl;
outfile<<" 字符串问题 "<<endl;
try
{
//BSTR转string
string strIP;
DWORD dwNumIP = WideCharToMultiByte(CP_OEMCP,NULL,inStrIP,-1,NULL,0,NULL,FALSE);
char *psIP;
psIP= new char[dwNumIP];
WideCharToMultiByte (CP_OEMCP,NULL,inStrIP,-1,psIP,dwNumIP,NULL,FALSE);
strIP = psIP;
// 删除临时变量
delete []psIP;
string strPassword;
DWORD dwNumPassword = WideCharToMultiByte(CP_OEMCP,NULL,password,-1,NULL,0,NULL,FALSE);
char *psPassword;
psPassword= new char[dwNumPassword];
WideCharToMultiByte (CP_OEMCP,NULL,password,-1,psPassword,dwNumPassword,NULL,FALSE);
strPassword = psPassword;
// 删除临时变量
delete []psPassword;
//string转BSTR
string strOutValuse= m_CharDll.getAppend(strIP,port,strPassword);
CComBSTR temp(strOutValuse.c_str());
*outValuse= temp;
}
catch(std::exception e)
{
outfile<<"出现异常 "<<endl;
outfile<<e.what()<<endl;
}
}
else
{
cout<<"不能打开文件!"<<endl;
}
outfile<<"-----------------------------------------------------------------------------------------------------------------------------------------------------------"<<endl;
outfile.close();
return S_OK;
}
{
std::ofstream outfile;
outfile.open("log.txt");
if(outfile.is_open())
{
outfile<<"--------------------------------------------------------------------------------------------------------------------------------------------"<<endl;
outfile<<" 字符串问题 "<<endl;
try
{
//BSTR转string
string strIP;
DWORD dwNumIP = WideCharToMultiByte(CP_OEMCP,NULL,inStrIP,-1,NULL,0,NULL,FALSE);
char *psIP;
psIP= new char[dwNumIP];
WideCharToMultiByte (CP_OEMCP,NULL,inStrIP,-1,psIP,dwNumIP,NULL,FALSE);
strIP = psIP;
// 删除临时变量
delete []psIP;
string strPassword;
DWORD dwNumPassword = WideCharToMultiByte(CP_OEMCP,NULL,password,-1,NULL,0,NULL,FALSE);
char *psPassword;
psPassword= new char[dwNumPassword];
WideCharToMultiByte (CP_OEMCP,NULL,password,-1,psPassword,dwNumPassword,NULL,FALSE);
strPassword = psPassword;
// 删除临时变量
delete []psPassword;
//string转BSTR
string strOutValuse= m_CharDll.getAppend(strIP,port,strPassword);
CComBSTR temp(strOutValuse.c_str());
*outValuse= temp;
}
catch(std::exception e)
{
outfile<<"出现异常 "<<endl;
outfile<<e.what()<<endl;
}
}
else
{
cout<<"不能打开文件!"<<endl;
}
outfile<<"-----------------------------------------------------------------------------------------------------------------------------------------------------------"<<endl;
outfile.close();
return S_OK;
}