解决方案 »
- 编译没有错误,调试时报错: 无法启动程序“C:Projects\Driver\mydriver_check\HelloDDk.sys
- 用vc如何将数据库操作(ado方式)再加上一系列运算封装在dll里阿?最好给个例子或链接
- 急! 视图切换的问题,关于scrollView
- 为何VS 2005对应的MSDN比VC 6.0对应的MSDN难用?
- 这样的情况,是用什么算法去处理,对于统计车道里车流辆排队的长度。
- 如何提高访问网页的速度?
- fatal error RC1015:cannot open include file 'afxres.h'
- 为什么我在DEBUG时WATCH变量值时有时会出错,我加一个CString ="dfsdsfd";然后WATCH
- TREEVIEW里的对应选项的图标怎么显示不出来?
- 请大家推荐一下学TCP/IP原理的好书。
- MFC单文档程序初始化时,点击最大化按钮先提示向下还原,再次点击才是最大化
- 怎么实现视图的切换?
Describes an entry from a list that enumerates the modules used by a specified process.typedef struct tagMODULEENTRY32 {
DWORD dwSize;
DWORD th32ModuleID;
DWORD th32ProcessID;
DWORD GlblcntUsage;
DWORD ProccntUsage;
BYTE * modBaseAddr;
DWORD modBaseSize;
HMODULE hModule;
char szModule[MAX_MODULE_NAME32 + 1];
char szExePath[MAX_PATH];
} MODULEENTRY32;
typedef MODULEENTRY32 * PMODULEENTRY32;
typedef MODULEENTRY32 * LPMODULEENTRY32;
Members
dwSize
Specifies the length, in bytes, of the structure. Before calling the Module32First function, set this member to sizeof(MODULEENTRY32). If you do not initialize dwSize, Module32First will fail.
th32ModuleID
Module identifier in the context of the owning process. The contents of this member has meaning only to the tool help functions. It is not a handle, nor is it usable by Win32 API elements.
th32ProcessID
Identifier of the process being examined. The contents of this member can be used by Win32 API elements.
GlblcntUsage
Global usage count on the module.
ProccntUsage
Module usage count in the context of the owning process.
modBaseAddr
Base address of the module in the context of the owning process.
modBaseSize
Size, in bytes, of the module.
hModule
Handle to the module in the context of the owning process.
szModule
String containing the module name.
szExePath
String containing the location (path) of the module.
Note modBaseAddr and hModule are valid only in the context of the process specified by th32ProcessID. QuickInfo
Windows NT: Requires version 5.0 or later.
Windows: Requires Windows 95 or later.
Windows CE: Unsupported.
Header: Declared in tlhelp32.h.See Also
Tool Help Library Overview, Tool Help Structures
The GetModuleFileNameEx function retrieves the fully qualified path for the specified module. DWORD GetModuleFileNameEx(
HANDLE hProcess, // handle to the process
HMODULE hModule, // handle to the module
LPTSTR lpFilename, // buffer that receives the path
DWORD nSize // size of the buffer
);
Parameters
hProcess
Handle to the process that contains the module.
hModule
Handle to the module.
lpFilename
Pointer to the buffer that receives the fully qualified path to the module.
nSize
Specifies the size, in bytes, of the lpFilename buffer.
Return Value
If the function succeeds, the return value specifies the length of the string copied to the buffer. If the function fails, the return value is zero. To get extended error information, call GetLastError. See Also
Process Status Helper Overview, PSAPI Functions, EnumProcesses, GetModuleBaseName
Module32First(hfilename,&pes);要判断 hfilename 的有效性,而且,还要判断 Module32First 的返回值,最后,要关闭句柄。像这样while(hfilename != INVALID_HANDLE_VALUE && bRet)
{
hfilename = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, procList.th32ProcessID);
if(hfilename != INVALID_HANDLE_VALUE && Module32FirstW(hfilename, &pes))
{
CloseHandle(hfilename);
wprintf(L"%s\n", pes.szModule);
wprintf(L"%s\n", pes.szExePath);
}
bRet = Process32Next(hSnapshot, &procList);
}
CloseHandle(hSnapshot);
while(hSnapshot != INVALID_HANDLE_VALUE && bRet)
while (条件)
更不要使用
while (组合条件)
要使用
while (1) {
if (条件1) break;
//...
if (条件2) continue;
//...
if (条件3) return;
//...
}
因为前两种写法在语言表达意思的层面上有二义性,只有第三种才忠实反映了程序流的实际情况。
典型如:
下面两段的语义都是当文件未结束时读字符
while (!feof(f)) {
a=fgetc(f);
//...
b=fgetc(f);//可能此时已经feof了!
//...
}
而这样写就没有问题:
while (1) {
a=fgetc(f);
if (feof(f)) break;
//...
b=fgetc(f);
if (feof(f)) break;
//...
}
类似的例子还可以举很多。