升龙物业 老版本 ocx IPO, 加密狗 转值班电话

MiniVersion.cpp 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. // MiniVersion.cpp Version 1.1
  2. //
  3. // Author: Hans Dietrich
  4. // hdietrich2@hotmail.com
  5. //
  6. // This software is released into the public domain.
  7. // You are free to use it in any way you like, except
  8. // that you may not sell this source code.
  9. //
  10. // This software is provided "as is" with no expressed
  11. // or implied warranty. I accept no liability for any
  12. // damage or loss of business that this software may cause.
  13. //
  14. ///////////////////////////////////////////////////////////////////////////////
  15. #include "stdafx.h"
  16. #include "MiniVersion.h"
  17. #pragma message("automatic link to VERSION.LIB")
  18. #pragma comment(lib, "version.lib")
  19. ///////////////////////////////////////////////////////////////////////////////
  20. // ctor
  21. CMiniVersion::CMiniVersion(LPCTSTR lpszPath)
  22. {
  23. ZeroMemory(m_szPath, sizeof(m_szPath));
  24. if (lpszPath && lpszPath[0] != 0)
  25. {
  26. lstrcpyn(m_szPath, lpszPath, sizeof(m_szPath)-1);
  27. }
  28. else
  29. {
  30. }
  31. m_pData = NULL;
  32. m_dwHandle = 0;
  33. for (int i = 0; i < 4; i++)
  34. {
  35. m_wFileVersion[i] = 0;
  36. m_wProductVersion[i] = 0;
  37. }
  38. m_dwFileFlags = 0;
  39. m_dwFileOS = 0;
  40. m_dwFileType = 0;
  41. m_dwFileSubtype = 0;
  42. ZeroMemory(m_szCompanyName, sizeof(m_szCompanyName));
  43. ZeroMemory(m_szProductName, sizeof(m_szProductName));
  44. ZeroMemory(m_szFileDescription, sizeof(m_szFileDescription));
  45. Init();
  46. }
  47. ///////////////////////////////////////////////////////////////////////////////
  48. // Init
  49. BOOL CMiniVersion::Init()
  50. {
  51. DWORD dwHandle;
  52. DWORD dwSize;
  53. BOOL rc;
  54. dwSize = ::GetFileVersionInfoSize((LPSTR)(LPCTSTR)m_szPath, &dwHandle);
  55. if (dwSize == 0)
  56. return FALSE;
  57. m_pData = new BYTE [dwSize + 1];
  58. ZeroMemory(m_pData, dwSize+1);
  59. rc = ::GetFileVersionInfo((LPSTR)(LPCTSTR)m_szPath, dwHandle, dwSize, m_pData);
  60. if (!rc)
  61. return FALSE;
  62. // get fixed info
  63. VS_FIXEDFILEINFO FixedInfo;
  64. if (GetFixedInfo(FixedInfo))
  65. {
  66. m_wFileVersion[0] = HIWORD(FixedInfo.dwFileVersionMS);
  67. m_wFileVersion[1] = LOWORD(FixedInfo.dwFileVersionMS);
  68. m_wFileVersion[2] = HIWORD(FixedInfo.dwFileVersionLS);
  69. m_wFileVersion[3] = LOWORD(FixedInfo.dwFileVersionLS);
  70. m_wProductVersion[0] = HIWORD(FixedInfo.dwProductVersionMS);
  71. m_wProductVersion[1] = LOWORD(FixedInfo.dwProductVersionMS);
  72. m_wProductVersion[2] = HIWORD(FixedInfo.dwProductVersionLS);
  73. m_wProductVersion[3] = LOWORD(FixedInfo.dwProductVersionLS);
  74. m_dwFileFlags = FixedInfo.dwFileFlags;
  75. m_dwFileOS = FixedInfo.dwFileOS;
  76. m_dwFileType = FixedInfo.dwFileType;
  77. m_dwFileSubtype = FixedInfo.dwFileSubtype;
  78. }
  79. else
  80. return FALSE;
  81. // get string info
  82. GetStringInfo(TEXT("CompanyName"), m_szCompanyName);
  83. GetStringInfo(TEXT("FileDescription"), m_szFileDescription);
  84. GetStringInfo(TEXT("ProductName"), m_szProductName);
  85. return TRUE;
  86. }
  87. ///////////////////////////////////////////////////////////////////////////////
  88. // Release
  89. void CMiniVersion::Release()
  90. {
  91. // do this manually, because we can't use objects requiring
  92. // a dtor within an exception handler
  93. if (m_pData)
  94. delete [] m_pData;
  95. m_pData = NULL;
  96. }
  97. ///////////////////////////////////////////////////////////////////////////////
  98. // GetFileVersion
  99. BOOL CMiniVersion::GetFileVersion(WORD * pwVersion)
  100. {
  101. for (int i = 0; i < 4; i++)
  102. *pwVersion++ = m_wFileVersion[i];
  103. return TRUE;
  104. }
  105. ///////////////////////////////////////////////////////////////////////////////
  106. // GetProductVersion
  107. BOOL CMiniVersion::GetProductVersion(WORD * pwVersion)
  108. {
  109. for (int i = 0; i < 4; i++)
  110. *pwVersion++ = m_wProductVersion[i];
  111. return TRUE;
  112. }
  113. ///////////////////////////////////////////////////////////////////////////////
  114. // GetFileFlags
  115. BOOL CMiniVersion::GetFileFlags(DWORD& rdwFlags)
  116. {
  117. rdwFlags = m_dwFileFlags;
  118. return TRUE;
  119. }
  120. ///////////////////////////////////////////////////////////////////////////////
  121. // GetFileOS
  122. BOOL CMiniVersion::GetFileOS(DWORD& rdwOS)
  123. {
  124. rdwOS = m_dwFileOS;
  125. return TRUE;
  126. }
  127. ///////////////////////////////////////////////////////////////////////////////
  128. // GetFileType
  129. BOOL CMiniVersion::GetFileType(DWORD& rdwType)
  130. {
  131. rdwType = m_dwFileType;
  132. return TRUE;
  133. }
  134. ///////////////////////////////////////////////////////////////////////////////
  135. // GetFileSubtype
  136. BOOL CMiniVersion::GetFileSubtype(DWORD& rdwType)
  137. {
  138. rdwType = m_dwFileSubtype;
  139. return TRUE;
  140. }
  141. ///////////////////////////////////////////////////////////////////////////////
  142. // GetCompanyName
  143. BOOL CMiniVersion::GetCompanyName(LPTSTR lpszCompanyName, int nSize)
  144. {
  145. if (!lpszCompanyName)
  146. return FALSE;
  147. ZeroMemory(lpszCompanyName, nSize);
  148. lstrcpyn(lpszCompanyName, m_szCompanyName, nSize-1);
  149. return TRUE;
  150. }
  151. ///////////////////////////////////////////////////////////////////////////////
  152. // GetFileDescription
  153. BOOL CMiniVersion::GetFileDescription(LPTSTR lpszFileDescription, int nSize)
  154. {
  155. if (!lpszFileDescription)
  156. return FALSE;
  157. ZeroMemory(lpszFileDescription, nSize);
  158. lstrcpyn(lpszFileDescription, m_szFileDescription, nSize-1);
  159. return TRUE;
  160. }
  161. ///////////////////////////////////////////////////////////////////////////////
  162. // GetProductName
  163. BOOL CMiniVersion::GetProductName(LPTSTR lpszProductName, int nSize)
  164. {
  165. if (!lpszProductName)
  166. return FALSE;
  167. ZeroMemory(lpszProductName, nSize);
  168. lstrcpyn(lpszProductName, m_szProductName, nSize-1);
  169. return TRUE;
  170. }
  171. ///////////////////////////////////////////////////////////////////////////////
  172. ///////////////////////////////////////////////////////////////////////////////
  173. //
  174. // protected methods
  175. //
  176. ///////////////////////////////////////////////////////////////////////////////
  177. ///////////////////////////////////////////////////////////////////////////////
  178. ///////////////////////////////////////////////////////////////////////////////
  179. // GetFixedInfo
  180. BOOL CMiniVersion::GetFixedInfo(VS_FIXEDFILEINFO& rFixedInfo)
  181. {
  182. BOOL rc;
  183. UINT nLength;
  184. VS_FIXEDFILEINFO *pFixedInfo = NULL;
  185. if (!m_pData)
  186. return FALSE;
  187. if (m_pData)
  188. rc = ::VerQueryValue(m_pData, TEXT("\\"), (void **) &pFixedInfo, &nLength);
  189. else
  190. rc = FALSE;
  191. if (rc)
  192. memcpy (&rFixedInfo, pFixedInfo, sizeof (VS_FIXEDFILEINFO));
  193. return rc;
  194. }
  195. ///////////////////////////////////////////////////////////////////////////////
  196. // GetStringInfo
  197. BOOL CMiniVersion::GetStringInfo(LPCSTR lpszKey, LPTSTR lpszReturnValue)
  198. {
  199. BOOL rc;
  200. DWORD *pdwTranslation;
  201. UINT nLength;
  202. LPTSTR lpszValue;
  203. if (m_pData == NULL)
  204. return FALSE;
  205. if (!lpszReturnValue)
  206. return FALSE;
  207. if (!lpszKey)
  208. return FALSE;
  209. *lpszReturnValue = 0;
  210. rc = ::VerQueryValue(m_pData, TEXT("\\VarFileInfo\\Translation"),
  211. (void**) &pdwTranslation, &nLength);
  212. if (!rc)
  213. return FALSE;
  214. char szKey[2000];
  215. wsprintf(szKey, TEXT("\\StringFileInfo\\%04x%04x\\%s"),
  216. LOWORD (*pdwTranslation), HIWORD (*pdwTranslation),
  217. lpszKey);
  218. rc = ::VerQueryValue(m_pData, szKey, (void**) &lpszValue, &nLength);
  219. if (!rc)
  220. return FALSE;
  221. lstrcpy(lpszReturnValue, lpszValue);
  222. return TRUE;
  223. }