获得进程路径怎么会是乱码的.求指点....

tko2002 2015-10-26 05:38:34
CString csTemp = _T(""), csPid;
CString str, str2;
HANDLE hSnapshot, mehandle;
str2 =_T( "smss.exe");
hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32 pe;
MODULEENTRY32 me;
pe.dwSize = sizeof(PROCESSENTRY32);
Process32First(hSnapshot, &pe);

do
{
str.Format(_T("%s"), pe.szExeFile);
if (_tcscmp(str, str2) == 0)/加入了这个判断后就会路径乱码,名和PID都能正常 显示.
{
break;
}
}while (Process32Next(hSnapshot, &pe));

mehandle = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pe.th32ProcessID);

me.dwSize = sizeof(MODULEENTRY32);

Module32First(mehandle, &me);

csPid.Format(_T("%d"), pe.th32ProcessID);

//if (pe.th32ProcessID == 0)
//{
// csTemp = (csTemp + pe.szExeFile + "\t" + csPid + _T("\tSystem") + _T("\r\n"));
//}
//else
//{
csTemp = (csTemp + pe.szExeFile + "\t" + csPid + _T("\t") + me.szExePath + _T("\r\n"));
//}
CloseHandle(mehandle);
MessageBox( csTemp);
CloseHandle(hSnapshot);
乱码了

不加入判断就是全都显示就能正常显示出来..
...全文
205 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2015-10-27
  • 打赏
  • 举报
回复
CString::Compare int Compare( LPCTSTR lpsz ) const; Return Value Zero if the strings are identical, < 0 if this CString object is less than lpsz, or > 0 if this CString object is greater than lpsz. Parameters lpsz The other string used for comparison. Remarks Compares this CString object with another string using the generic-text function _tcscmp. The generic-text function _tcscmp, which is defined in TCHAR.H, maps to either strcmp, wcscmp, or _mbscmp depending on the character set that is defined at compile time. Each of these functions performs a case-sensitive comparison of the strings, and is not affected by locale. For more information, seestrcmp, wcscmp, _mbscmp in the Run-Time Library Reference. Example The following example demonstrates the use of CString::Compare. // example for CString::Compare CString s1( "abc" ); CString s2( "abd" ); ASSERT( s1.Compare( s2 ) == -1 ); // Compare with another CString. ASSERT( s1.Compare( "abe" ) == -1 ); // Compare with LPTSTR string. CString Overview | Class Members | Hierarchy Chart See Also CString::CompareNoCase, CString::Collate, CString::CollateNoCase CString::Find int Find( TCHAR ch ) const; int Find( LPCTSTR lpszSub ) const; int Find( TCHAR ch, int nStart ) const; int Find( LPCTSTR pstr, int nStart ) const; Return Value The zero-based index of the first character in this CString object that matches the requested substring or characters; -1 if the substring or character is not found. Parameters ch A single character to search for. lpszSub A substring to search for. nStart The index of the character in the string to begin the search with, or 0 to start from the beginning. The character at nStart is excluded from the search if nStart is not equal to 0. pstr A pointer to a string to search for. Remarks Searches this string for the first match of a substring. The function is overloaded to accept both single characters (similar to the run-time function strchr) and strings (similar to strstr). Example // First example demonstrating // CString::Find ( TCHAR ch ) CString s( "abcdef" ); ASSERT( s.Find( 'c' ) == 2 ); ASSERT( s.Find( "de" ) == 3 ); // Second example demonstrating // CString::Find( TCHAR ch, int nStart ) CString str("The stars are aligned"); int n = str.Find('e', 5); ASSERT(n == 12); CString Overview | Class Members | Hierarchy Chart See Also CString::ReverseFind, CString::FindOneOf
www_adintr_com 2015-10-26
  • 打赏
  • 举报
回复
smss.exe 是系统进程,你的访问权限不够,在 生成的 exe 上点右键,以管理员身份运行 试试

65,186

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧