错误:error C2664: “void ATL::CStringT<BaseType,StringTraits>::Format(const wchar_t *,...)”: 不能将参数 1 从“const char [26]”转换为“const wchar_t *” c:\users\administrator\desktop\2-3.cpp 121 1 os_test2_2-3
头文件:
//# include <windows.h>
# include <iostream>
# include <stdio.h>
# include <afx.h>
# include <cstring>
//#include <iostream.h> // b0:
static LPCTSTR g_szMutexName =(LPCTSTR) "w2kdg.ProcTerm.mutex.Suicide" ;
using namespace std;
main函数:
int main(int argc, char* argv[] )
{
// 决定其行为是父进程还是子进程
if (argc > 1 && strcmp(argv[1] , "child" )== 0)
{
Child() ;
}
else
{
Parent() ;
}
HANDLE hProcess;
FILETIME ftCreation, ftExit, ftKernel, ftUserStart, ftUserEnd;
LPSYSTEMTIME stCreation, stExit;
hProcess = GetCurrentProcess();
GetProcessTimes(hProcess, &ftCreation, &ftExit, &ftKernel, &ftUserStart);
CTime cc(ftCreation);
CString str;
str.Format("Created at %02d:%02d:%02d", cc.GetHour(),
cc.GetMinute(), cc.GetSecond());
cout<<"调用GetProcessTimes函数: "<<str<<endl;
Sleep(5000);
return 0;
}
警告的地方: swprintf(szCmdLine, L"\"%s\" child" , szFilename) ;//命令行参数
出错的地方:str.Format("Created at %02d:%02d:%02d", cc.GetHour(), cc.GetMinute(), cc.GetSecond());
~~~~~~~~~~~~~~我是菜鸟,希望解释的清楚一点。thank you!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 个解决方案
#1
多字符集
//# include <windows.h>
# include <iostream>
# include <stdio.h>
# include <afx.h>
# include <cstring>
//#include <iostream.h> // b0:
static LPCTSTR g_szMutexName =(LPCTSTR) "w2kdg.ProcTerm.mutex.Suicide" ;
using namespace std;
main函数:
int main(int argc, char* argv[] )
{
// 决定其行为是父进程还是子进程
if (argc > 1 && strcmp(argv[1] , "child" )== 0)
{
Child() ;
}
else
{
Parent() ;
}
HANDLE hProcess;
FILETIME ftCreation, ftExit, ftKernel, ftUserStart, ftUserEnd;
LPSYSTEMTIME stCreation, stExit;
hProcess = GetCurrentProcess();
GetProcessTimes(hProcess, &ftCreation, &ftExit, &ftKernel, &ftUserStart);
CTime cc(ftCreation);
CString str;
str.Format("Created at %02d:%02d:%02d", cc.GetHour(),
cc.GetMinute(), cc.GetSecond());
cout<<"调用GetProcessTimes函数: "<<str<<endl;
Sleep(5000);
return 0;
}
#2
第一次可以,但是现实的时间格式不对,不是00:00:00样子的
然后第二次执行就会报错
错误 1 error C2665: “swprintf”: 2 个重载中没有一个可以转换所有参数类型 c:\users\administrator\desktop\2-3.cpp 23 1 os_test2_2-3
然后第二次执行就会报错
错误 1 error C2665: “swprintf”: 2 个重载中没有一个可以转换所有参数类型 c:\users\administrator\desktop\2-3.cpp 23 1 os_test2_2-3
#3
Generic-Text Routine Mappings
TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_stprintf sprintf sprintf swprintf
TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_stprintf sprintf sprintf swprintf
#4
我是菜鸟,表示看不懂!
#1
多字符集
//# include <windows.h>
# include <iostream>
# include <stdio.h>
# include <afx.h>
# include <cstring>
//#include <iostream.h> // b0:
static LPCTSTR g_szMutexName =(LPCTSTR) "w2kdg.ProcTerm.mutex.Suicide" ;
using namespace std;
main函数:
int main(int argc, char* argv[] )
{
// 决定其行为是父进程还是子进程
if (argc > 1 && strcmp(argv[1] , "child" )== 0)
{
Child() ;
}
else
{
Parent() ;
}
HANDLE hProcess;
FILETIME ftCreation, ftExit, ftKernel, ftUserStart, ftUserEnd;
LPSYSTEMTIME stCreation, stExit;
hProcess = GetCurrentProcess();
GetProcessTimes(hProcess, &ftCreation, &ftExit, &ftKernel, &ftUserStart);
CTime cc(ftCreation);
CString str;
str.Format("Created at %02d:%02d:%02d", cc.GetHour(),
cc.GetMinute(), cc.GetSecond());
cout<<"调用GetProcessTimes函数: "<<str<<endl;
Sleep(5000);
return 0;
}
#2
第一次可以,但是现实的时间格式不对,不是00:00:00样子的
然后第二次执行就会报错
错误 1 error C2665: “swprintf”: 2 个重载中没有一个可以转换所有参数类型 c:\users\administrator\desktop\2-3.cpp 23 1 os_test2_2-3
然后第二次执行就会报错
错误 1 error C2665: “swprintf”: 2 个重载中没有一个可以转换所有参数类型 c:\users\administrator\desktop\2-3.cpp 23 1 os_test2_2-3
#3
Generic-Text Routine Mappings
TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_stprintf sprintf sprintf swprintf
TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_stprintf sprintf sprintf swprintf
#4
我是菜鸟,表示看不懂!