《对战平台》◎cs_gamedll○○○EnvironmentInfo
上述是我之后要分析代码的命名规则
《对战平台》◎cs_gamedll代表是工程项目中的项目名
《对战平台》◎cs_gamedll○○○EnvironmentInfo是项目中某个类的代码分析
2 #define __ENVIRONMENTINFO_H
3 // --------------------------------------------------------------------------------------
4 #include " http://www.cnblogs.com/client/provider/CommBridgeBase.h "
5 #include " ..\..\common\base\LockCS.h "
6
7 // --------------------------------------------------------------------------------------
8
9
10 // ##ModelId=44C4B617017C
11 class CEnvironmentInfo
12 {
13 public :
14 // ##ModelId=44C4B6170186
15 CEnvironmentInfo( void );
16 // ##ModelId=44C4B6170188
17 ~ CEnvironmentInfo( void );
18
19 // ##ModelId=44C4B617018A
20 void getLocalIPXNetNum(UCHAR * pNetNum);
21 // 获得本机的IPX节点号
22 // ##ModelId=44C4B617018C
23 void getLocalIPXNodeNum(UCHAR * pNodeNum);
24 // 在指定的内存区域查找指定数据
25
26
27 public :
28 // ##ModelId=44C4B6170197
29 bool m_fIsWin98OrLater; // 是WIN98系统
30 // ##ModelId=44C4B6170198
31 HMODULE m_hWs2_32; // WS2_32DLL的句柄
32 // ##ModelId=44C4B6170199
33 HMODULE m_hMsWsock; // MsWsock.dll的句柄
34 // ##ModelId=44C4B61701A6
35 pJOYENVIRONMENT_INFO m_lpEI; // C影射过来的环境变量的信息
36 // ##ModelId=44C4B61701AA
37 HANDLE m_hMapFile; // 内存影射对象的句柄
38 // ##ModelId=44C4B61701AC
39 CLockCS m_Lock;
40 // ##ModelId=44C4B61701B5
41 unsigned char m_Buffer[ 5120 ];
42 };
43 #endif // __ENVIRONMENTINFO_H
2 #include " environmentinfo.h "
3
4
5 // ##ModelId=44C4B6170186
6 CEnvironmentInfo::CEnvironmentInfo( void )
7 {
8 OSVERSIONINFO osvi;
9 // 检测系统的类型
10 osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
11 GetVersionEx ( & osvi);
12 m_fIsWin98OrLater = //判断是否是98以及之后的操作系统
13 (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) &&
14 ( (osvi.dwMajorVersion > 4 ) ||
15 ( (osvi.dwMajorVersion == 4 ) && (osvi.dwMinorVersion > 0 ) ) );
16 // 内存影射的处理
17 m_hMapFile = OpenFileMapping(FILE_MAP_ALL_ACCESS, false , " SkyShare " );
18 if (m_hMapFile != NULL)
19 m_lpEI = (pJOYENVIRONMENT_INFO) MapViewOfFile(m_hMapFile,FILE_MAP_ALL_ACCESS, 0 , 0 , sizeof (JOYENVIRONMENT_INFO));
20
21
22 }
23
24 // ##ModelId=44C4B6170188
25 CEnvironmentInfo:: ~ CEnvironmentInfo( void )
26 {
27 if (m_hMapFile != NULL)
28 CloseHandle(m_hMapFile);
29 }
30
31
32 /// /检查源IPX地址是不是本机地址
33 // bool CEnvironmentInfo::checkIPXaddrIsLoacl(PSOCKADDR_IPX piad)
34 // {
35 // char szLog[100];
36 // if (piad != NULL)
37 // {
38 //
39 // if ((BYTE)piad->sa_nodenum[0] == (BYTE)m_lpEI->lc_nodenum[0] && \
40 // (BYTE)piad->sa_nodenum[1] == (BYTE)m_lpEI->lc_nodenum[1] && \
41 // (BYTE)piad->sa_nodenum[2] == (BYTE)m_lpEI->lc_nodenum[2] && \
42 // (BYTE)piad->sa_nodenum[3] == (BYTE)m_lpEI->lc_nodenum[3] && \
43 // (BYTE)piad->sa_nodenum[4] == (BYTE)m_lpEI->lc_nodenum[4] && \
44 // (BYTE)piad->sa_nodenum[5] == (BYTE)m_lpEI->lc_nodenum[5]
45 // )
46 // {
47 // if (htons(IPX_LISTEN_SOCKET) == piad->sa_socket)
48 // // {
49 // // return true;
50 // // }else
51 // // return false;
52 // }
53 // }
54 // return false;
55 // }
56 // 获得本机的IPX的网段号
57 // ##ModelId=44C4B617018A
58 void CEnvironmentInfo::getLocalIPXNetNum(UCHAR * pNetNum)
59 {
60 memcpy(pNetNum,m_lpEI -> lc_netnum, 4 );
61 }
62 // 获得本机的IPX节点号
63 // ##ModelId=44C4B617018C
64 void CEnvironmentInfo::getLocalIPXNodeNum(UCHAR * pNodeNum)
65 {
66 memcpy(pNodeNum,m_lpEI -> lc_nodenum, 6 );
67 }
API解析:
OSVERSIONINFO包含了系统的版本信息:
{
DWORD dwOSVersionInfoSize;
DWORD dwMajorVersion;
DWORD dwMinorVersion;
DWORD dwBuildNumber;
DWORD dwPlatformId;
TCHAR szCSDVersion[ 128 ];
} OSVERSIONINFO;
This structure is used with the GetVersionEx function.
OpenFileMapping Function
-
dwDesiredAccess
-
The access to the file mapping object. This access is checked against any security descriptor on the target file mapping object. bInheritHandle
-
If this parameter is TRUE, a process created by the function can inherit the handle; otherwise, the handle cannot be inherited.
lpName
-
The name of the file mapping object to be opened. If there is an open handle to a file mapping object by this name and the security descriptor on the mapping object does not conflict with the dwDesiredAccess parameter, the open operation succeeds.
Terminal Services: The name can have a "
1 LPVOID WINAPI MapViewOfFile(
2 __in HANDLE hFileMappingObject,
3 __in DWORD dwDesiredAccess,
4 __in DWORD dwFileOffsetHigh,
5 __in DWORD dwFileOffsetLow,
6 __in SIZE_T dwNumberOfBytesToMap
7 );Windows XP: Fast user switching is implemented using Terminal Services sessions. The first user to log on uses session 0, the next user to log on uses session 1, and so on. Kernel object names must follow the guidelines outlined for Terminal Services so that applications can support multiple users.
Windows 2000: If Terminal Services is not running, the "Global\" and "Local\" prefixes are ignored. The remainder of the name can contain any character except the backslash character.
MapViewOfFile Function
Maps a view of a file mapping into the address space of a calling process.
To specify a suggested base address for the view, use the MapViewOfFileEx function. However, this practice is not recommended.
2 __in HANDLE hFileMappingObject,
3 __in DWORD dwDesiredAccess,
4 __in DWORD dwFileOffsetHigh,
5 __in DWORD dwFileOffsetLow,
6 __in SIZE_T dwNumberOfBytesToMap
7 );