1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804 |
- #include "stdafx.h"
- #include "underlyingapi.h"
- #include <shlobj.h>
- namespace underlyingapi
- {
-
-
- #define BUFSIZE 256
- #define PRODUCT_ULTIMATE 0x00000001
- #define PRODUCT_HOME_BASIC 0x00000002
- #define PRODUCT_HOME_PREMIUM 0x00000003
- #define PRODUCT_ENTERPRISE 0x00000004
- #define PRODUCT_HOME_BASIC_N 0x00000005
- #define PRODUCT_BUSINESS 0x00000006
- #define PRODUCT_STANDARD_SERVER 0x00000007
- #define PRODUCT_DATACENTER_SERVER 0x00000008
- #define PRODUCT_SMALLBUSINESS_SERVER 0x00000009
- #define PRODUCT_ENTERPRISE_SERVER 0x0000000A
- #define PRODUCT_STARTER 0x0000000B
- #define PRODUCT_DATACENTER_SERVER_CORE 0x0000000C
- #define PRODUCT_STANDARD_SERVER_CORE 0x0000000D
- #define PRODUCT_ENTERPRISE_SERVER_CORE 0x0000000E
- #define PRODUCT_ENTERPRISE_SERVER_IA64 0x0000000F
- #define PRODUCT_BUSINESS_N 0x00000010
- #define PRODUCT_WEB_SERVER 0x00000011
- #define PRODUCT_CLUSTER_SERVER 0x00000012
- #define PRODUCT_HOME_SERVER 0x00000013
- #define PRODUCT_STORAGE_EXPRESS_SERVER 0x00000014
- #define PRODUCT_STORAGE_STANDARD_SERVER 0x00000015
- #define PRODUCT_STORAGE_WORKGROUP_SERVER 0x00000016
- #define PRODUCT_STORAGE_ENTERPRISE_SERVER 0x00000017
- #define PRODUCT_SERVER_FOR_SMALLBUSINESS 0x00000018
- #define PRODUCT_SMALLBUSINESS_SERVER_PREMIUM 0x00000019
- #define PRODUCT_HOME_PREMIUM_N 0x0000001A
- #define PRODUCT_ENTERPRISE_N 0x0000001B
- #define PRODUCT_ULTIMATE_N 0x0000001C
- #define PRODUCT_WEB_SERVER_CORE 0x0000001D
- #define PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT 0x0000001E
- #define PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY 0x0000001F
- #define PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING 0x00000020
- #define PRODUCT_SMALLBUSINESS_SERVER_PRIME 0x00000021
- #define PRODUCT_HOME_PREMIUM_SERVER 0x00000022
- #define PRODUCT_SERVER_FOR_SMALLBUSINESS_V 0x00000023
- #define PRODUCT_STANDARD_SERVER_V 0x00000024
- #define PRODUCT_DATACENTER_SERVER_V 0x00000025
- #define PRODUCT_ENTERPRISE_SERVER_V 0x00000026
- #define PRODUCT_DATACENTER_SERVER_CORE_V 0x00000027
- #define PRODUCT_STANDARD_SERVER_CORE_V 0x00000028
- #define PRODUCT_ENTERPRISE_SERVER_CORE_V 0x00000029
- #define PRODUCT_HYPERV 0x0000002A
- #define SM_TABLETPC 86
- #define SM_MEDIACENTER 87
- #define SM_STARTER 88
- #define SM_SERVERR2 89
- #define VER_SERVER_NT 0x80000000
- #define VER_WORKSTATION_NT 0x40000000
- #define VER_SUITE_SMALLBUSINESS 0x00000001
- #define VER_SUITE_ENTERPRISE 0x00000002
- #define VER_SUITE_BACKOFFICE 0x00000004
- #define VER_SUITE_COMMUNICATIONS 0x00000008
- #define VER_SUITE_TERMINAL 0x00000010
- #define VER_SUITE_SMALLBUSINESS_RESTRICTED 0x00000020
- #define VER_SUITE_EMBEDDEDNT 0x00000040
- #define VER_SUITE_DATACENTER 0x00000080
- #define VER_SUITE_SINGLEUSERTS 0x00000100
- #define VER_SUITE_PERSONAL 0x00000200
- #define VER_SUITE_BLADE 0x00000400
- #define VER_SUITE_EMBEDDED_RESTRICTED 0x00000800
- #define VER_SUITE_SECURITY_APPLIANCE 0x00001000
- #define VER_SUITE_STORAGE_SERVER 0x00002000
- #define VER_SUITE_COMPUTE_SERVER 0x00004000
- #define VER_SUITE_WH_SERVER 0x00008000
- typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);
- typedef BOOL(WINAPI *PGPI)(DWORD, DWORD, DWORD, DWORD, PDWORD);
-
- static INT CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM pData)
- {
- switch (uMsg)
- {
- case BFFM_INITIALIZED:
- SendMessage(hwnd, BFFM_SETSELECTION, TRUE, NULL);
- break;
- case BFFM_SELCHANGED:
- {
- TCHAR szFileName[MAX_PATH];
- LPITEMIDLIST pidlCurrent = (LPITEMIDLIST)lp;
- SHGetPathFromIDList(pidlCurrent, szFileName);
- SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, (LPARAM)szFileName);
- }
- break;
-
-
-
-
-
-
-
-
-
-
- }
- return 0;
- }
- BOOL GetFilePath(TCHAR *FilePath, HWND hParentWnd, TCHAR* InstructionString, UINT ulFlags)
- {
- BROWSEINFO bInfo;
- LPITEMIDLIST pidl, pidlDesktop;
- ZeroMemory((PVOID)&bInfo, sizeof(BROWSEINFO));
- SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOP, &pidlDesktop);
- bInfo.pidlRoot = pidlDesktop;
- bInfo.hwndOwner = hParentWnd;
- bInfo.pszDisplayName = FilePath;
- bInfo.lpszTitle = InstructionString;
- bInfo.ulFlags = ulFlags;
- bInfo.lpfn = BrowseCallbackProc;
- bInfo.lParam = 0;
- if ((pidl = ::SHBrowseForFolder(&bInfo)) == NULL) return FALSE;
- if (::SHGetPathFromIDList(pidl, FilePath) == FALSE) return FALSE;
- return TRUE;
- }
- BOOL extmerge(IN CONST TString& ext1, IN CONST TString& ext2, IN TString &merge)
- {
- INT nRet = iscorrectext(ext1);
- if ( nRet == -1 ) return FALSE;
- if (nRet == 0)
- {
- merge = _T("*.*");
- return TRUE;
- }
- merge = ext1;
- nRet = iscorrectext(ext2);
- if (nRet != 1) return TRUE;
- if (merge[merge.length() - 1] != _T('|'))
- merge.append(_T("|"));
- merge.append(ext2);
- return TRUE;
- }
- INT iscorrectext(IN const TString &fext, OUT TString* lpMistakenExt )
- {
- if (fext.size() == 0) return FALSE;
- if (fext.find(_T("*.*")) != TString::npos) return 0;
- TString ext = lowercase(fext);
- if (ext[ext.length() - 1] != _T('|'))
- ext.append(_T("|"));
- INT nRet = 1;
- CONST TString sCorrectExt = _T("*.jpg|*.jpeg|*.png|*.bmp|*.cr2|*.nef|*.raw");
- int nIndex = 0;
- do
- {
- nIndex = ext.find(_T('|'));
- if (nIndex != TString::npos)
- {
- if (sCorrectExt.find(ext.substr(0, nIndex)) == TString::npos)
- {
- if (lpMistakenExt)
- *lpMistakenExt = ext.substr(0, nIndex);
- nRet = -1;
- break;
- }
- ext = ext.substr(nIndex + 1);
- }
- } while (ext.find(_T('|')) != TString::npos);
- return nRet;
- }
- TString lowercase(IN const TString &Str)
- {
- const TCHAR aazz = _T('z') - _T('Z');
- TString sResult;
- for (TString::const_iterator it = Str.begin(); Str.end() != it; it++)
- {
- if (_T('A') <= *it && *it <= _T('Z'))
- sResult.append(1, *it + aazz);
- else
- sResult.append(1, *it);
- }
- return sResult;
- }
- TString uppercase(IN const TString &Str)
- {
- const TCHAR aazz = _T('z') - _T('Z');
- TString sResult;
- for (TString::const_iterator it = Str.begin(); Str.end() != it; it++)
- {
- if (_T('a') <= *it && *it <= _T('z'))
- sResult.append(1, *it - aazz);
- else
- sResult.append(1, *it);
- }
- return sResult;
- }
- int match(IN CONST TString &sFileExt, IN CONST TString &sFile)
- {
- TString fext = uppercase(sFileExt);
- TString file = uppercase(sFile);
- int pos = file.find_last_of(_T('.'));
- if (TString::npos != pos)
- file = file.substr(pos);
- return (TString::npos != fext.find(file));
- }
- void GetDirveInfo()
- {
- UINT DiskType;
- size_t szAllDriveStrings = GetLogicalDriveStrings(0, NULL);
- TCHAR *pDriveStrings = new TCHAR[szAllDriveStrings + sizeof(_T(" "))];
- GetLogicalDriveStrings(szAllDriveStrings, pDriveStrings);
- size_t szDriveString = _tcslen(pDriveStrings);
- while (szDriveString > 0)
- {
- AfxMessageBox(pDriveStrings);
- DiskType = GetDriveType(pDriveStrings);
- switch (DiskType)
- {
- case DRIVE_NO_ROOT_DIR:
- return;
- case DRIVE_REMOVABLE:
- ::AfxMessageBox(_T("移动存储设备 "));
- break;
- case DRIVE_FIXED:
- ::AfxMessageBox(_T("固定硬盘驱动器 "));
- break;
- case DRIVE_REMOTE:
- ::AfxMessageBox(_T("这是网络驱动器 "));
- break;
- case DRIVE_CDROM:
- ::AfxMessageBox(_T("这是光盘驱动器 "));
- break;
- }
- pDriveStrings += szDriveString + 1;
- szDriveString = _tcslen(pDriveStrings);
- }
- }
- BOOL OpenFloder(IN CStringArray &vtFiles, IN LPCTSTR lpFilter )
- {
-
- TCHAR szDesktop[MAX_PATH];
- SHGetSpecialFolderPath(0, szDesktop, CSIDL_DESKTOPDIRECTORY, 0);
- CString strFindFile = _T("");
- LPTSTR lpszFile = (TCHAR*)(CONST TCHAR*)strFindFile;
-
- LPTSTR lpszFilter = _T("图片 (*.jpg;*.jpeg;*.raw;*.cr2;*.nef)||所有文件 (*.*)|*.*||");
- DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_ALLOWMULTISELECT | OFN_ENABLESIZING;
- CFileDialog dlg(TRUE, _T("default Files (*.jpg)"), NULL, dwFlags, lpszFilter, NULL);
- dlg.m_ofn.lpstrTitle = _T("请选择要导入的图片");
- dlg.m_ofn.lpstrInitialDir = szDesktop;
-
-
- dlg.m_ofn.nMaxFile = 1500 * MAX_PATH;
- dlg.m_ofn.lpstrFile = new TCHAR[dlg.m_ofn.nMaxFile];
- ZeroMemory(dlg.m_ofn.lpstrFile, sizeof(TCHAR) * dlg.m_ofn.nMaxFile);
-
- if (dlg.DoModal() == IDCANCEL)
- {
- delete[]dlg.m_ofn.lpstrFile;
- dlg.m_ofn.lpstrFile = NULL;
- return FALSE;
- }
- POSITION pos_file = dlg.GetStartPosition();
- while (pos_file != NULL)
- vtFiles.Add((LPCTSTR)dlg.GetNextPathName(pos_file));
-
- delete[]dlg.m_ofn.lpstrFile;
- dlg.m_ofn.lpstrFile = NULL;
- return TRUE;
- }
- BOOL OpenFloder(IN STR_VEC &vtFiles, IN LPCTSTR lpFilter)
- {
-
- TCHAR szDesktop[MAX_PATH];
- SHGetSpecialFolderPath(0, szDesktop, CSIDL_DESKTOPDIRECTORY, 0);
- CString strFindFile = _T("");
- LPTSTR lpszFile = (TCHAR*)(CONST TCHAR*)strFindFile;
-
- LPTSTR lpszFilter = _T("图片 (*.jpg;*.jpeg;*.raw;*.cr2;*.nef)||所有文件 (*.*)|*.*||");
- DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_ALLOWMULTISELECT | OFN_ENABLESIZING;
- CFileDialog dlg(TRUE, _T("default Files (*.jpg)"), NULL, dwFlags, lpszFilter, NULL);
- dlg.m_ofn.lpstrTitle = _T("请选择要导入的图片");
- dlg.m_ofn.lpstrInitialDir = szDesktop;
-
-
- dlg.m_ofn.nMaxFile = 1500 * MAX_PATH;
- dlg.m_ofn.lpstrFile = new TCHAR[dlg.m_ofn.nMaxFile];
- ZeroMemory(dlg.m_ofn.lpstrFile, sizeof(TCHAR) * dlg.m_ofn.nMaxFile);
-
- if (dlg.DoModal() == IDCANCEL)
- {
- delete[]dlg.m_ofn.lpstrFile;
- dlg.m_ofn.lpstrFile = NULL;
- return FALSE;
- }
- POSITION pos_file = dlg.GetStartPosition();
- while (pos_file != NULL)
- vtFiles.push_back((LPCTSTR)dlg.GetNextPathName(pos_file));
-
- delete[]dlg.m_ofn.lpstrFile;
- dlg.m_ofn.lpstrFile = NULL;
- return TRUE;
- }
-
- BOOL IsStringExist(IN CString& str, IN CStringArray &tagAry)
- {
- int nSize = tagAry.GetSize();
- if (nSize == 0) return FALSE;
- BOOL bExist = FALSE;
- for (int i = 0; i < nSize; i++)
- {
- if (str == tagAry.ElementAt(i))
- {
- bExist = TRUE;
- break;
- }
- }
- return bExist;
- }
- BOOL IsStringExist(IN TString& str, IN STR_VEC &tagVt)
- {
- int nSize = tagVt.size();
- if (nSize == 0) return FALSE;
- BOOL bExist = FALSE;
- for (STR_VEC::iterator it = tagVt.begin(); it != tagVt.end(); it++)
- {
- if (str.compare(it->c_str()) == 0)
- {
- bExist = TRUE;
- break;
- }
- }
- return bExist;
- }
-
- BOOL IsStringExistNoCase(IN CString& str, IN CStringArray &tagAry)
- {
- int nSize = tagAry.GetSize();
- if (nSize == 0) return FALSE;
- BOOL bExist = FALSE;
- for (int i = 0; i < nSize; i++)
- {
- if (str.CompareNoCase(tagAry.ElementAt(i)) == 0)
- {
- bExist = TRUE;
- break;
- }
- }
- return bExist;
- }
- BOOL IsStringExistNoCase(IN CONST TString& str, IN STR_VEC &tagVt)
- {
- int nSize = tagVt.size();
- if (nSize == 0) return FALSE;
- BOOL bExist = FALSE;
- TString stmp1 = uppercase(str);
- TString stmp2;
- for (STR_VEC::iterator it = tagVt.begin(); it != tagVt.end(); it++)
- {
- stmp2 = uppercase(*it);
- if (stmp1.compare(stmp2) == 0)
- {
- bExist = TRUE;
- break;
- }
- }
- return bExist;
- }
-
-
-
- BOOL IsValidpath(IN CONST TString &strPath)
- {
-
-
-
- if (strPath.size() < 2) return FALSE;
-
- if (strPath[1] == _T(':'))
- {
- DWORD dwDiskType = 0;
- dwDiskType = GetDriveType(strPath.substr(0, 3).c_str());
- switch (dwDiskType)
- {
- case DRIVE_UNKNOWN:
- case DRIVE_NO_ROOT_DIR:
-
-
- case DRIVE_CDROM:
- case DRIVE_RAMDISK:
- return FALSE;
- break;
- }
- }
- else if (strPath.substr(0, 2).find(_T("\\\\")) != TString::npos)
- {
-
- TString strtmp = strPath.substr(2);
- int n = strPath.substr(2).find(_T("\\"));
- if (n == TString::npos)
- return FALSE;
- strtmp = strPath.substr(0, n + 2);
-
- DWORD dwRet = 0;
- NETRESOURCE nr;
- memset(&nr, 0, sizeof(nr));
- nr.dwScope = RESOURCE_CONNECTED;
- nr.dwType = RESOURCETYPE_ANY;
- nr.dwDisplayType = RESOURCEDISPLAYTYPE_GENERIC;
- nr.dwUsage = RESOURCEUSAGE_CONNECTABLE;
- #ifndef UNICODE
- nr.lpRemoteName = (LPSTR)strtmp.c_str();
- #else
- nr.lpRemoteName = (LPWSTR)(strtmp.c_str());
- #endif
- dwRet = WNetAddConnection2(&nr, NULL, NULL, CONNECT_UPDATE_PROFILE);
- if (dwRet == ERROR_BAD_NETPATH)
- return FALSE;
- else if (dwRet == ERROR_LOGON_FAILURE)
- return FALSE;
- }
- return TRUE;
- }
- void Splitpath(IN CONST TCHAR *path, IN TCHAR * drive, IN size_t driveNumberOfElements, IN TCHAR * dir, IN size_t dirNumberOfElements, IN CONST int &nTimes)
- {
- int i = 0;
- int npoint = 0;
- int nsprit = 0;
- int ncolon = 0;
- int ntimes = -1;
- #ifdef UNICODE
- int nlen = wcslen(path);
- #else
- int nlen = strlen(path);
- #endif
- while (nlen > i++)
- {
- if (path[i] == _T(':'))
- ncolon = i;
- else if (path[i] == _T('\\'))
- {
- nsprit = i;
- if (nTimes == ++ntimes) break;
- }
- }
-
-
- #ifdef UNICODE
- wmemcpy_s(drive, driveNumberOfElements, path, ncolon + 1);
- wmemcpy_s(dir, dirNumberOfElements, &path[ncolon + 1], nsprit - ncolon);
- #else
- memcpy_s(drive, driveNumberOfElements, path, ncolon + 1);
- memcpy_s(dir, dirNumberOfElements, &path[ncolon + 1], nsprit - ncolon);
- #endif
- }
-
-
-
- BOOL CreateDirectoryEx(IN LPCTSTR lpNewDirectory)
- {
-
- if (!lpNewDirectory || !IsValidpath(lpNewDirectory)) return FALSE;
- BOOL bExists = FALSE;
- TCHAR szNewFileName[_MAX_PATH] = { 0 };
- TCHAR szDrive[_MAX_DRIVE] = { 0 };
- TCHAR szDir[_MAX_DIR] = { 0 };
- TCHAR szFna[_MAX_FNAME] = { 0 };
- TCHAR szExt[_MAX_EXT] = { 0 };
- TCHAR szNewDirectory[_MAX_PATH] = { 0 };
- if (lpNewDirectory[_tcslen(lpNewDirectory) - 1] != _T('\\'))
- StringCchPrintf(szNewDirectory, _MAX_PATH, _T("%s\\"), lpNewDirectory);
- else
- StringCchPrintf(szNewDirectory, _MAX_PATH, _T("%s"), lpNewDirectory);
- int nIndex = 0;
- do
- {
- bExists = PathFileExists(szNewDirectory);
- if (!bExists)
- {
-
-
-
-
- #ifdef UNICODE
- wmemset(szDrive, 0, _MAX_DRIVE);
- wmemset(szDir, 0, _MAX_DIR);
- wmemset(szFna, 0, _MAX_FNAME);
- wmemset(szExt, 0, _MAX_EXT);
- #else
- memset(szDrive, 0, _MAX_DRIVE);
- memset(szDir, 0, _MAX_DIR);
- memset(szFna, 0, _MAX_FNAME);
- memset(szExt, 0, _MAX_EXT);
- #endif
- Splitpath(szNewDirectory, szDrive, _MAX_DRIVE, szDir, _MAX_DIR, ++nIndex);
- StringCchPrintf(szNewFileName, _MAX_PATH, _T("%s%s"), szDrive, szDir);
- if (!CreateDirectory(szNewFileName, NULL))
- {
- DWORD dwError = GetLastError();
- switch (dwError)
- {
- case ERROR_PATH_NOT_FOUND:
- case ERROR_ACCESS_DENIED:
- case ERROR_BAD_NET_NAME:
-
- return FALSE;
- break;
- case ERROR_ALREADY_EXISTS:
- break;
- default:
- break;
- }
- }
- }
- } while (!bExists);
- return TRUE;
- }
- BOOL GetOrientation(IN Image *pImg)
- {
- if (pImg == NULL) return FALSE;
- UINT totalBufferSize;
- UINT numProperties;
- pImg->GetPropertySize(&totalBufferSize, &numProperties);
-
- PropertyItem* pAllItems = (PropertyItem*)malloc(totalBufferSize);
-
- pImg->GetAllPropertyItems(totalBufferSize, numProperties, pAllItems);
-
- for (UINT j = 0; j < numProperties; ++j)
- {
- if (PropertyTagOrientation == pAllItems[j].id)
- {
- short* ptrLong = (short*)(pAllItems[j].value);
- int ret = (int)*ptrLong;
- free(pAllItems);
- return ret;
- }
- }
- free(pAllItems);
- return TRUE;
- }
-
-
-
- int GetEncoderClsid(IN CONST WCHAR* format, OUT CLSID* pClsid)
- {
-
- UINT numEncoders = 0;
-
- UINT nSize = 0;
- ImageCodecInfo* pImageCodecInfo = NULL;
-
- GetImageEncodersSize(&numEncoders, &nSize);
- if (nSize == 0)
- return -1;
-
- pImageCodecInfo = (ImageCodecInfo*)(malloc(nSize));
- if (pImageCodecInfo == NULL)
- return -1;
-
- GetImageEncoders(numEncoders, nSize, pImageCodecInfo);
-
- for (UINT i = 0; i < numEncoders; ++i)
- {
- if (wcscmp(pImageCodecInfo[i].MimeType, format) == 0)
- {
- *pClsid = pImageCodecInfo[i].Clsid;
- free(pImageCodecInfo);
- return i;
- }
- }
-
- free(pImageCodecInfo);
- return -1;
- }
-
-
-
- BOOL SaveImg2newfile(IN Image* pImg, IN CString strNewfile, IN ULONG uQuality)
- {
- if (pImg == NULL) return FALSE;
-
- int nIndex = strNewfile.ReverseFind(_T('\\'));
- if (nIndex == -1)
- return FALSE;
- if (!PathFileExists(strNewfile.Left(nIndex)))
- {
-
- CreateDirectoryEx(strNewfile.Left(nIndex));
- }
- nIndex = strNewfile.ReverseFind(_T('.'));
- if (nIndex == -1)
- return FALSE;
- Status stat = GenericError;
- CLSID encoderClsid = { 0 };
- BSTR newfile = strNewfile.AllocSysString();
- strNewfile = strNewfile.Mid(nIndex + 1);
- if (strNewfile.CompareNoCase(_T("bmp")) == 0)
- {
- GetEncoderClsid(L"image/bmp", &encoderClsid);
- stat = pImg->Save(newfile, &encoderClsid, NULL);
- }
- else if (strNewfile.CompareNoCase(_T("png")) == 0)
- {
- GetEncoderClsid(L"image/png", &encoderClsid);
- stat = pImg->Save(newfile, &encoderClsid, NULL);
- }
- else
- {
- GetEncoderClsid(L"image/jpeg", &encoderClsid);
- EncoderParameters encoderParameters;
- encoderParameters.Count = 1;
- encoderParameters.Parameter[0].Guid = EncoderQuality;
- encoderParameters.Parameter[0].Type = EncoderParameterValueTypeLong;
- encoderParameters.Parameter[0].NumberOfValues = 1;
-
- encoderParameters.Parameter[0].Value = &uQuality;
- stat = pImg->Save(newfile, &encoderClsid, &encoderParameters);
- }
- SysFreeString(newfile);
- return stat == Ok ? TRUE : FALSE;
- }
- BOOL SaveImg2newfile(IN Image* pImg, IN TString strNewfile, IN ULONG uQuality)
- {
- if (pImg == NULL) return FALSE;
-
- int nIndex = strNewfile.find_last_of(_T('\\'));
- if (nIndex == TString::npos)
- return FALSE;
- if (!PathFileExists(strNewfile.substr(0, nIndex).c_str()))
- {
-
- CreateDirectoryEx(strNewfile.substr(0, nIndex).c_str());
- }
- nIndex = strNewfile.find_last_of(_T('.'));
- if (nIndex == TString::npos)
- return FALSE;
- Status stat = GenericError;
- CLSID encoderClsid = { 0 };
- BSTR newfile = _bstr_t(strNewfile.c_str());
- strNewfile = strNewfile.substr(nIndex + 1);
- if (strNewfile.find(_T("bmp")) == 0)
- {
- GetEncoderClsid(L"image/bmp", &encoderClsid);
- stat = pImg->Save(newfile, &encoderClsid, NULL);
- }
- else if (strNewfile.find(_T("png")) == 0)
- {
- GetEncoderClsid(L"image/png", &encoderClsid);
- stat = pImg->Save(newfile, &encoderClsid, NULL);
- }
- else
- {
- GetEncoderClsid(L"image/jpeg", &encoderClsid);
- EncoderParameters encoderParameters;
- encoderParameters.Count = 1;
- encoderParameters.Parameter[0].Guid = EncoderQuality;
- encoderParameters.Parameter[0].Type = EncoderParameterValueTypeLong;
- encoderParameters.Parameter[0].NumberOfValues = 1;
-
- encoderParameters.Parameter[0].Value = &uQuality;
- stat = pImg->Save(newfile, &encoderClsid, &encoderParameters);
- }
- SysFreeString(newfile);
- return stat == Ok ? TRUE : FALSE;
- }
-
-
-
- int ZoomImg(IN CRect &Imgrc, IN CONST DWORD &dwDisplayPix, OUT DWORD &dwZoomPix)
- {
- double fDisplayWidth = GET_XPIX(dwDisplayPix);
- double fDisplayHeight = GET_YPIX(dwDisplayPix);
-
- double fDisplayAspectRatio = fDisplayWidth / fDisplayHeight;
-
- double fImgAspectRatio = ((double)Imgrc.Width()) / ((double)Imgrc.Height());
- double fZoomWidth;
- double fZoomHeight;
- if (fDisplayAspectRatio > fImgAspectRatio)
- {
- fZoomWidth = fDisplayHeight*fImgAspectRatio;
- fZoomHeight = fDisplayHeight;
- }
- else
- {
- fZoomWidth = fDisplayWidth;
- fZoomHeight = fDisplayWidth / fImgAspectRatio;
- }
- dwZoomPix = SET_PIX((int)fZoomWidth, (int)fZoomHeight);
-
- int nRetval = 0;
- if ((fDisplayWidth == Imgrc.Width()) && (fDisplayHeight == Imgrc.Height()))
- {
- nRetval = ZoomNull;
- }
- else if ((fDisplayWidth > Imgrc.Width()) && (fDisplayHeight > Imgrc.Height()))
- {
- nRetval = ZoomOut;
- }
- else
- {
- nRetval = ZoomIn;
- }
- return nRetval;
- }
- int ZoomImg(IN CONST DWORD &dwImgPix, IN CONST DWORD &dwDisplayPix, OUT DWORD &dwZoomPix)
- {
- double fDisplayWidth = GET_XPIX(dwDisplayPix);
- double fDisplayHeight = GET_YPIX(dwDisplayPix);
-
- double fDisplayAspectRatio = fDisplayWidth / fDisplayHeight;
-
- double fImgAspectRatio = ((double)GET_XPIX(dwImgPix)) / ((double)GET_YPIX(dwImgPix));
- double fZoomWidth;
- double fZoomHeight;
- if (fDisplayAspectRatio > fImgAspectRatio)
- {
- fZoomWidth = fDisplayHeight*fImgAspectRatio;
- fZoomHeight = fDisplayHeight;
- }
- else
- {
- fZoomWidth = fDisplayWidth;
- fZoomHeight = fDisplayWidth / fImgAspectRatio;
- }
- dwZoomPix = SET_PIX((int)fZoomWidth, (int)fZoomHeight);
-
- int nRetval = 0;
- if ((fDisplayWidth == GET_XPIX(dwImgPix)) && (fDisplayHeight == GET_YPIX(dwImgPix)))
- {
- nRetval = ZoomNull;
- }
- else if ((fDisplayWidth > GET_XPIX(dwImgPix)) && (fDisplayHeight > GET_YPIX(dwImgPix)))
- {
- nRetval = ZoomOut;
- }
- else
- {
- nRetval = ZoomIn;
- }
- return nRetval;
- }
-
-
-
- BOOL ImgThumbnail(IN Image* pImg, IN CONST DWORD &dwDisplayPix, IN CString strNewfile, IN ULONG uQuality)
- {
- if (pImg == NULL) return FALSE;
- DWORD dwZoomPix;
- int retval = ZoomImg(SET_PIX(pImg->GetWidth(), pImg->GetHeight()), dwDisplayPix, dwZoomPix);
- if (retval == ZoomOut)
- {
- return FALSE;
- }
- else if (retval == ZoomNull)
- {
- return SaveImg2newfile(pImg, strNewfile, uQuality);
- }
-
- Bitmap bitmap(GET_XPIX(dwZoomPix), GET_YPIX(dwZoomPix));
- Graphics *graphic = Graphics::FromImage(&bitmap);
- graphic->Clear(Color(255, 255, 255, 255));
- graphic->SetInterpolationMode(InterpolationModeHighQualityBicubic);
- graphic->SetSmoothingMode(SmoothingModeHighQuality);
- graphic->SetPixelOffsetMode(PixelOffsetModeHighQuality);
- graphic->SetCompositingMode(CompositingModeSourceOver);
- graphic->SetCompositingQuality(CompositingQualityHighQuality);
- graphic->SetTextRenderingHint(TextRenderingHintAntiAliasGridFit);
- graphic->DrawImage(pImg, 0, 0, GET_XPIX(dwZoomPix), GET_YPIX(dwZoomPix));
- delete graphic;
-
- return SaveImg2newfile(&bitmap, strNewfile, uQuality);
- }
- BOOL ImgThumbnail(IN LPCTSTR lpImgpath, IN CONST DWORD &dwDisplayPix, IN CString strNewfile, IN ULONG uQuality)
- {
- if (!PathFileExists(lpImgpath))
- return FALSE;
- #ifdef UNICODE
- Image Img(lpImgpath);
- #else
- BSTR strtmp = _bstr_t(lpImgpath);
- Image Img(strtmp);
- SysFreeString(strtmp);
- #endif
- DWORD dwZoomPix;
- int retval = ZoomImg(SET_PIX(Img.GetWidth(), Img.GetHeight()), dwDisplayPix, dwZoomPix);
- if (retval == ZoomOut)
- {
- return FALSE;
- }
- else if (retval == ZoomNull)
- {
- return SaveImg2newfile(&Img, strNewfile, uQuality);
- }
-
- Bitmap bitmap(GET_XPIX(dwZoomPix), GET_YPIX(dwZoomPix));
- Graphics *graphic = Graphics::FromImage(&bitmap);
- graphic->Clear(Color(255, 255, 255, 255));
- graphic->SetInterpolationMode(InterpolationModeHighQualityBicubic);
- graphic->SetSmoothingMode(SmoothingModeHighQuality);
- graphic->SetPixelOffsetMode(PixelOffsetModeHighQuality);
- graphic->SetCompositingMode(CompositingModeSourceOver);
- graphic->SetCompositingQuality(CompositingQualityHighQuality);
- graphic->SetTextRenderingHint(TextRenderingHintAntiAliasGridFit);
- graphic->DrawImage(&Img, 0, 0, GET_XPIX(dwZoomPix), GET_YPIX(dwZoomPix));
- delete graphic;
-
- return SaveImg2newfile(&bitmap, strNewfile, uQuality);
- }
- BOOL ImgThumbnail(IN CONST TString &strImgpath, IN CONST DWORD &dwDisplayPix, IN TString strNewfile, IN ULONG uQuality)
- {
- if (!PathFileExists(strImgpath.c_str()))
- return FALSE;
- #ifdef UNICODE
- BSTR strtmp = _bstr_t(strImgpath.c_str());
- Image Img(strtmp);
- SysFreeString(strtmp);
-
- #else
- BSTR strtmp = _bstr_t(strImgpath.c_str());
- Image Img(strtmp);
- SysFreeString(strtmp);
- #endif
- DWORD dwZoomPix;
- int retval = ZoomImg(SET_PIX(Img.GetWidth(), Img.GetHeight()), dwDisplayPix, dwZoomPix);
- if (retval == ZoomOut)
- {
- return FALSE;
- }
- else if (retval == ZoomNull)
- {
- return SaveImg2newfile(&Img, strNewfile, uQuality);
- }
-
- Bitmap bitmap(GET_XPIX(dwZoomPix), GET_YPIX(dwZoomPix));
- Graphics *graphic = Graphics::FromImage(&bitmap);
- graphic->Clear(Color(255, 255, 255, 255));
- graphic->SetInterpolationMode(InterpolationModeHighQualityBicubic);
- graphic->SetSmoothingMode(SmoothingModeHighQuality);
- graphic->SetPixelOffsetMode(PixelOffsetModeHighQuality);
- graphic->SetCompositingMode(CompositingModeSourceOver);
- graphic->SetCompositingQuality(CompositingQualityHighQuality);
- graphic->SetTextRenderingHint(TextRenderingHintAntiAliasGridFit);
- graphic->DrawImage(&Img, 0, 0, GET_XPIX(dwZoomPix), GET_YPIX(dwZoomPix));
- delete graphic;
-
- return SaveImg2newfile(&bitmap, strNewfile, uQuality);
- }
- BOOL SimpleImgThumbnail(IN LPCWSTR lpImgpath, IN CONST DWORD &dwDisplayPix, IN CString strNewfile, IN ULONG uQuality)
- {
- if (!PathFileExistsW(lpImgpath))
- return FALSE;
- DWORD dwZoomPix;
- Image Img(lpImgpath);
- int retval = ZoomImg(SET_PIX(Img.GetWidth(), Img.GetHeight()), dwDisplayPix, dwZoomPix);
- if (retval == ZoomOut)
- {
- return FALSE;
- }
- else if (retval == ZoomNull)
- {
- return SaveImg2newfile(&Img, strNewfile, uQuality);
- }
- Image *pThumbnailImg = Img.GetThumbnailImage(GET_XPIX(dwZoomPix), GET_YPIX(dwZoomPix));
- if (pThumbnailImg)
- SaveImg2newfile(pThumbnailImg, strNewfile, uQuality);
- else
- return FALSE;
- if (pThumbnailImg) delete pThumbnailImg;
- return TRUE;
- }
-
-
-
- BOOL GetDiskSpaceInfo(IN LPCTSTR lpRootPathName, IN OUT double &dTotalNum, IN OUT double &dFreeNum)
- {
- #if 1
-
- if (lpRootPathName == NULL || _tcscmp(lpRootPathName, _T("")) == 0)
- {
-
- return FALSE;
- }
-
- int nlen = _tcslen(lpRootPathName);
- if ((1 == nlen) || (2 == nlen && lpRootPathName[nlen - 1] != _T(':')))
- {
-
- return FALSE;
- }
- if (!PathFileExists(lpRootPathName))
- {
-
- return FALSE;
- }
- #else
-
- if (!IsValidpath(lpRootPathName) || !PathFileExists(lpRootPathName)) return FALSE;
- #endif
- BOOL fResult = FALSE;
- DWORD dwSectPerClust;
- DWORD dwBytesPerSect;
- DWORD dwFreeClusters;
- DWORD dwTotalClusters;
- typedef BOOL(WINAPI *P_GDFSE)(LPCTSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER);
- P_GDFSE pGetDiskFreeSpaceEx = NULL;
- __int64 i64FreeBytesToCaller;
- __int64 i64TotalBytes;
- __int64 i64FreeBytes;
-
- #ifdef UNICODE
- pGetDiskFreeSpaceEx = (P_GDFSE)GetProcAddress(GetModuleHandle(_T("kernel32.dll")), "GetDiskFreeSpaceExW");
- #else
- pGetDiskFreeSpaceEx = (P_GDFSE)GetProcAddress(GetModuleHandle("kernel32.dll"), "GetDiskFreeSpaceExA");
- #endif
- if (pGetDiskFreeSpaceEx)
- {
- fResult = pGetDiskFreeSpaceEx(lpRootPathName,
- (PULARGE_INTEGER)&i64FreeBytesToCaller,
- (PULARGE_INTEGER)&i64TotalBytes,
- (PULARGE_INTEGER)&i64FreeBytes);
- if (fResult)
- {
-
- dTotalNum = (double)i64TotalBytes / 1024 / 1024 / 1024;
- dFreeNum = (double)i64FreeBytes / 1024 / 1024 / 1024;
- }
- }
- else
- {
- fResult = GetDiskFreeSpace(lpRootPathName,
- &dwSectPerClust,
- &dwBytesPerSect,
- &dwFreeClusters,
- &dwTotalClusters);
- if (fResult)
- {
-
- i64TotalBytes = (__int64)dwTotalClusters * dwSectPerClust * dwBytesPerSect;
- i64FreeBytes = (__int64)dwFreeClusters * dwSectPerClust * dwBytesPerSect;
-
- dTotalNum = (double)i64TotalBytes / 1024 / 1024 / 1024;
- dFreeNum = (double)i64FreeBytes / 1024 / 1024 / 1024;
- }
- }
- return fResult;
- }
-
- BOOL IsWow64()
- {
- typedef BOOL(WINAPI *LPFN_ISWOW64PROCESS)(HANDLE, PBOOL);
- LPFN_ISWOW64PROCESS fnIsWow64Process;
- BOOL bIsWow64 = FALSE;
- fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(GetModuleHandle(TEXT("kernel32")), "IsWow64Process");
- if (NULL != fnIsWow64Process)
- {
- if (!fnIsWow64Process(GetCurrentProcess(), &bIsWow64))
- {
-
- AfxMessageBox(_T("句柄错误"));
- }
- }
- return bIsWow64;
- }
-
- BOOL IsOSVerIs64()
- {
- BOOL bOSVerIs64 = FALSE;
- SYSTEM_INFO si;
- PGNSI pGNSI;
- pGNSI = (PGNSI)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetNativeSystemInfo");
- if (NULL != pGNSI)
- pGNSI(&si);
- else
- GetSystemInfo(&si);
- if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 ||
- si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64)
- {
- bOSVerIs64 = TRUE;
- }
- return bOSVerIs64;
- }
-
- INT IsWow64Process(HANDLE hprocess)
- {
- typedef BOOL(WINAPI *LPFN_ISWOW64PROCESS)(HANDLE, PBOOL);
- LPFN_ISWOW64PROCESS fnIsWow64Process;
- INT nRet = 0;
- BOOL bIsWow64 = FALSE;
- fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(GetModuleHandle(TEXT("kernel32")), "IsWow64Process");
- if (NULL != fnIsWow64Process)
- {
- if (!fnIsWow64Process(hprocess, &bIsWow64))
- {
-
- AfxMessageBox(_T("句柄错误"));
- DWORD dwError = GetLastError();
- return -1;
- }
- }
- return bIsWow64 ? 1 : 0;
- }
- INT GetNativeSystemInfo(OSVerInfo &tagOSInfo)
- {
- OSVERSIONINFOEX osvi;
- SYSTEM_INFO si;
- PGNSI pGNSI;
- BOOL bOsVersionInfoEx;
- ZeroMemory(&si, sizeof(SYSTEM_INFO));
- ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
-
-
- osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
- if (!(bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO *)&osvi)))
- {
- osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
- if (!GetVersionEx((OSVERSIONINFO *)&osvi))
- return FALSE;
- }
-
-
- pGNSI = (PGNSI)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetNativeSystemInfo");
- if (NULL != pGNSI)
- pGNSI(&si);
- else
- GetSystemInfo(&si);
- TCHAR szWindowsDescription[MAX_PATH] = { 0 };
- CString str;
- CString strWindows;
- switch (osvi.dwPlatformId)
- {
- case VER_PLATFORM_WIN32_NT:
- if (osvi.dwMajorVersion == 10)
- {
- if (osvi.dwMinorVersion == 0)
- {
- if (osvi.wProductType == VER_NT_WORKSTATION)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Microsoft Windows 10 "));
- else
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Microsoft Windows Server Technical Preview "));
- }
- }
- if (osvi.dwMajorVersion == 6)
- {
- if (osvi.dwMinorVersion == 3)
- {
- if (osvi.wProductType == VER_NT_WORKSTATION)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Microsoft Windows 8.1 "));
- else
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Microsoft Windows Server 2012 R2 "));
- }
- if (osvi.dwMinorVersion == 2)
- {
- if (osvi.wProductType == VER_NT_WORKSTATION)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Microsoft Windows 8 "));
- else
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Microsoft Windows Server 2012 "));
- }
- if (osvi.dwMinorVersion == 1)
- {
- if (osvi.wProductType == VER_NT_WORKSTATION)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Microsoft Windows 7 "));
- else
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Microsoft Windows Server 2008 R2 "));
- }
- if (osvi.dwMinorVersion == 0)
- {
- if (osvi.wProductType == VER_NT_WORKSTATION)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Microsoft Windows Vista "));
- else
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Microsoft Windows Server 2008 "));
- }
- }
- if (osvi.dwMajorVersion == 5)
- {
- if (osvi.dwMinorVersion == 2)
- {
- if (GetSystemMetrics(SM_SERVERR2) != 0)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Microsoft Windows Server 2003 R2 "));
- else
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Microsoft Windows Server 2003 "));
- if (osvi.wSuiteMask & VER_SUITE_WH_SERVER)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Microsoft Windows Home Server "));
- if ((osvi.wProductType == VER_NT_WORKSTATION) && (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64))
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Microsoft Windows XP Professional x64 Edition "));
- }
- if (osvi.dwMinorVersion == 1)
- {
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Microsoft Windows XP "));
- }
- if (osvi.dwMinorVersion == 0)
- {
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Microsoft Windows 2000 "));
- }
- }
- if (osvi.dwMajorVersion <= 4)
- {
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Microsoft Windows NT "));
- }
-
-
- if (bOsVersionInfoEx)
- {
-
- if (osvi.wProductType == VER_NT_WORKSTATION && si.wProcessorArchitecture != PROCESSOR_ARCHITECTURE_AMD64)
- {
- if (osvi.dwMajorVersion == 4)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Workstation 4.0 "));
- else if (osvi.wSuiteMask & VER_SUITE_PERSONAL)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Home Edition "));
- else
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Professional "));
- }
-
- else if (osvi.wProductType == VER_NT_SERVER || osvi.wProductType == VER_NT_DOMAIN_CONTROLLER)
- {
- if (osvi.dwMajorVersion == 6)
- {
- if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64)
- {
- if (osvi.wSuiteMask & VER_SUITE_DATACENTER)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Datacenter Edition for Itanium-based Systems"));
- else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Enterprise Edition for Itanium-based Systems"));
- }
- else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
- {
- if (osvi.wSuiteMask & VER_SUITE_DATACENTER)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Datacenter x64 Edition "));
- else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Enterprise x64 Edition "));
- else
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Standard x64 Edition "));
- }
- else
- {
- if (osvi.wSuiteMask & VER_SUITE_DATACENTER)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Datacenter Edition "));
- else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Enterprise Edition "));
- else if (osvi.wSuiteMask & VER_SUITE_BLADE)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Web Edition "));
- else
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Standard Edition "));
- }
- }
- else if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2)
- {
- if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64)
- {
- if (osvi.wSuiteMask & VER_SUITE_DATACENTER)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Datacenter Edition for Itanium-based Systems"));
- else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Enterprise Edition for Itanium-based Systems"));
- }
- else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
- {
- if (osvi.wSuiteMask & VER_SUITE_DATACENTER)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Datacenter x64 Edition "));
- else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Enterprise x64 Edition "));
- else
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Standard x64 Edition "));
- }
- else
- {
- if (osvi.wSuiteMask & VER_SUITE_DATACENTER)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Datacenter Edition "));
- else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Enterprise Edition "));
- else if (osvi.wSuiteMask & VER_SUITE_BLADE)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Web Edition "));
- else
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Standard Edition "));
- }
- }
- else if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0)
- {
- if (osvi.wSuiteMask & VER_SUITE_DATACENTER)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Datacenter Server "));
- else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Advanced Server "));
- else
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Server "));
- }
- else if (osvi.dwMajorVersion == 4)
- {
- if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Server 4.0, Enterprise Edition "));
- else
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Server 4.0 "));
- }
- }
- }
-
- else
- {
- HKEY hKey;
- TCHAR szProductType[BUFSIZE];
- DWORD dwBufLen = BUFSIZE*sizeof(TCHAR);
- LONG lRet;
- lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("SYSTEM\\CurrentControlSet\\Control\\ProductOptions"), 0, KEY_QUERY_VALUE, &hKey);
- if (lRet != ERROR_SUCCESS)
- return FALSE;
- lRet = RegQueryValueEx(hKey, TEXT("ProductType"), NULL, NULL, (LPBYTE)szProductType, &dwBufLen);
- RegCloseKey(hKey);
- if ((lRet != ERROR_SUCCESS) || (dwBufLen > BUFSIZE*sizeof(TCHAR)))
- return FALSE;
- if (lstrcmpi(TEXT("WINNT"), szProductType) == 0)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Workstation "));
- if (lstrcmpi(TEXT("LANMANNT"), szProductType) == 0)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Server "));
- if (lstrcmpi(TEXT("SERVERNT"), szProductType) == 0)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Advanced Server "));
-
- }
-
- if (osvi.dwMajorVersion == 4 && lstrcmpi(osvi.szCSDVersion, TEXT("Service Pack 6")) == 0)
- {
- HKEY hKey;
- LONG lRet;
-
- lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Hotfix\\Q246009"), 0, KEY_QUERY_VALUE, &hKey);
- if (lRet == ERROR_SUCCESS)
- str.Format(_T("Service Pack 6a (Build %d)"), osvi.dwBuildNumber & 0xFFFF);
- else
- {
- str.Format(_T("%s (Build %d)"), osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF);
- }
- RegCloseKey(hKey);
- }
- else
- {
- str.Format(_T("%s (Build %d)"), osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF);
- }
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, str);
- break;
-
- case VER_PLATFORM_WIN32_WINDOWS:
- if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
- {
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Microsoft Windows 95 "));
- if (osvi.szCSDVersion[1] == 'C' || osvi.szCSDVersion[1] == 'B')
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("OSR2 "));
- }
- if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10)
- {
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Microsoft Windows 98 "));
- if (osvi.szCSDVersion[1] == 'A' || osvi.szCSDVersion[1] == 'B')
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("SE "));
- }
- if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90)
- {
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Microsoft Windows Millennium Edition"));
- }
- break;
- case VER_PLATFORM_WIN32s:
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, _T("Microsoft Win32s"));
- break;
- }
- AfxMessageBox(strWindows);
- return 0;
- }
- BOOL GetSystemInfo(OSVerInfo &tagOSInfo)
- {
- OSVERSIONINFOEX osvi;
- SYSTEM_INFO si;
- PGNSI pGNSI;
- PGPI pGPI;
- BOOL bOsVersionInfoEx;
- DWORD dwType;
- ZeroMemory(&si, sizeof(SYSTEM_INFO));
- ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
- osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
- if (!(bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO *)&osvi)))
- {
- osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
- if (!GetVersionEx((OSVERSIONINFO *)&osvi))
- return FALSE;
- }
- pGNSI = (PGNSI)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetNativeSystemInfo");
- if (NULL != pGNSI)
- pGNSI(&si);
- else
- GetSystemInfo(&si);
- tagOSInfo.dwMajorVersion = osvi.dwMajorVersion;
- tagOSInfo.dwMinorVersion = osvi.dwMinorVersion;
- tagOSInfo.wProductType = osvi.wProductType;
- if (VER_PLATFORM_WIN32_NT == osvi.dwPlatformId && osvi.dwMajorVersion > 4)
- {
- StringCchCopy(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Microsoft "));
-
- if (osvi.dwMajorVersion == 10)
- {
- if (osvi.dwMinorVersion == 0)
- {
- if (osvi.wProductType == VER_NT_WORKSTATION)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Windows 10 "));
- else StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Windows Server Technical Preview "));
- }
- pGPI = (PGPI)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetProductInfo");
- pGPI(osvi.dwMajorVersion, osvi.dwMinorVersion, 0, 0, &dwType);
- switch (dwType)
- {
- case PRODUCT_ULTIMATE:
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Ultimate Edition"));
- break;
- case PRODUCT_HOME_PREMIUM:
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Home Premium Edition"));
- break;
- case PRODUCT_HOME_BASIC:
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Home Basic Edition"));
- break;
- case PRODUCT_ENTERPRISE:
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Enterprise Edition"));
- break;
- case PRODUCT_BUSINESS:
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Business Edition"));
- break;
- case PRODUCT_STARTER:
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Starter Edition"));
- break;
- case PRODUCT_CLUSTER_SERVER:
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Cluster Server Edition"));
- break;
- case PRODUCT_DATACENTER_SERVER:
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Datacenter Edition"));
- break;
- case PRODUCT_DATACENTER_SERVER_CORE:
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Datacenter Edition (core installation)"));
- break;
- case PRODUCT_ENTERPRISE_SERVER:
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Enterprise Edition"));
- break;
- case PRODUCT_ENTERPRISE_SERVER_CORE:
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Enterprise Edition (core installation)"));
- break;
- case PRODUCT_ENTERPRISE_SERVER_IA64:
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Enterprise Edition for Itanium-based Systems"));
- break;
- case PRODUCT_SMALLBUSINESS_SERVER:
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Small Business Server"));
- break;
- case PRODUCT_SMALLBUSINESS_SERVER_PREMIUM:
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Small Business Server Premium Edition"));
- break;
- case PRODUCT_STANDARD_SERVER:
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Standard Edition"));
- break;
- case PRODUCT_STANDARD_SERVER_CORE:
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Standard Edition (core installation)"));
- break;
- case PRODUCT_WEB_SERVER:
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Web Server Edition"));
- break;
- }
- }
- if (osvi.dwMajorVersion == 6)
- {
- if (osvi.dwMinorVersion == 0)
- {
- if (osvi.wProductType == VER_NT_WORKSTATION)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Windows Vista "));
- else StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Windows Server 2008 "));
- }
- if (osvi.dwMinorVersion == 1)
- {
- if (osvi.wProductType == VER_NT_WORKSTATION)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Windows 7 "));
- else StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Windows Server 2008 R2 "));
- }
- if (osvi.dwMinorVersion == 2)
- {
- if (osvi.wProductType == VER_NT_WORKSTATION)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Windows 8 "));
- else StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Windows Server 2012 "));
- }
- if (osvi.dwMinorVersion == 3)
- {
- if (osvi.wProductType == VER_NT_WORKSTATION)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Windows 8.1 "));
- else StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Windows Server 2012 R2 "));
- }
- pGPI = (PGPI)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetProductInfo");
- pGPI(osvi.dwMajorVersion, osvi.dwMinorVersion, 0, 0, &dwType);
- switch (dwType)
- {
- case PRODUCT_ULTIMATE:
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Ultimate Edition"));
- break;
- case PRODUCT_HOME_PREMIUM:
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Home Premium Edition"));
- break;
- case PRODUCT_HOME_BASIC:
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Home Basic Edition"));
- break;
- case PRODUCT_ENTERPRISE:
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Enterprise Edition"));
- break;
- case PRODUCT_BUSINESS:
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Business Edition"));
- break;
- case PRODUCT_STARTER:
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Starter Edition"));
- break;
- case PRODUCT_CLUSTER_SERVER:
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Cluster Server Edition"));
- break;
- case PRODUCT_DATACENTER_SERVER:
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Datacenter Edition"));
- break;
- case PRODUCT_DATACENTER_SERVER_CORE:
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Datacenter Edition (core installation)"));
- break;
- case PRODUCT_ENTERPRISE_SERVER:
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Enterprise Edition"));
- break;
- case PRODUCT_ENTERPRISE_SERVER_CORE:
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Enterprise Edition (core installation)"));
- break;
- case PRODUCT_ENTERPRISE_SERVER_IA64:
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Enterprise Edition for Itanium-based Systems"));
- break;
- case PRODUCT_SMALLBUSINESS_SERVER:
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Small Business Server"));
- break;
- case PRODUCT_SMALLBUSINESS_SERVER_PREMIUM:
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Small Business Server Premium Edition"));
- break;
- case PRODUCT_STANDARD_SERVER:
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Standard Edition"));
- break;
- case PRODUCT_STANDARD_SERVER_CORE:
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Standard Edition (core installation)"));
- break;
- case PRODUCT_WEB_SERVER:
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Web Server Edition"));
- break;
- }
- }
- if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2)
- {
- if (GetSystemMetrics(SM_SERVERR2))
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Windows Server 2003 R2, "));
- else if (osvi.wSuiteMask == VER_SUITE_STORAGE_SERVER)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Windows Storage Server 2003"));
- else if (osvi.wSuiteMask == VER_SUITE_WH_SERVER)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Windows Home Server"));
- else if (osvi.wProductType == VER_NT_WORKSTATION &&
- si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
- {
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Windows XP Professional x64 Edition"));
- }
- else StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Windows Server 2003, "));
-
- if (osvi.wProductType != VER_NT_WORKSTATION)
- {
- if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64)
- {
- if (osvi.wSuiteMask & VER_SUITE_DATACENTER)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Datacenter Edition for Itanium-based Systems"));
- else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Enterprise Edition for Itanium-based Systems"));
- }
- else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
- {
- if (osvi.wSuiteMask & VER_SUITE_DATACENTER)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Datacenter x64 Edition"));
- else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Enterprise x64 Edition"));
- else StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Standard x64 Edition"));
- }
- else
- {
- if (osvi.wSuiteMask & VER_SUITE_COMPUTE_SERVER)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Compute Cluster Edition"));
- else if (osvi.wSuiteMask & VER_SUITE_DATACENTER)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Datacenter Edition"));
- else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Enterprise Edition"));
- else if (osvi.wSuiteMask & VER_SUITE_BLADE)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Web Edition"));
- else StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Standard Edition"));
- }
- }
- }
- if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)
- {
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Windows XP "));
- if (osvi.wSuiteMask & VER_SUITE_PERSONAL)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Home Edition"));
- else StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Professional"));
- }
- if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0)
- {
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Windows 2000 "));
- if (osvi.wProductType == VER_NT_WORKSTATION)
- {
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Professional"));
- }
- else
- {
- if (osvi.wSuiteMask & VER_SUITE_DATACENTER)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Datacenter Server"));
- else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Advanced Server"));
- else StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT("Server"));
- }
- }
-
- if (_tcslen(osvi.szCSDVersion) > 0)
- {
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT(" "));
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, osvi.szCSDVersion);
- }
- TCHAR buf[80];
- StringCchPrintf(buf, 80, TEXT(" (build %d)"), osvi.dwBuildNumber);
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, buf);
- if (osvi.dwMajorVersion >= 6)
- {
- if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 ||
- si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64)
- {
- tagOSInfo.bIs64Bit = TRUE;
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT(", 64-bit"));
- }
- else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
- {
- tagOSInfo.bIs64Bit = FALSE;
- StringCchCat(tagOSInfo.szOSVerName, BUFSIZE, TEXT(", 32-bit"));
- }
- }
- return TRUE;
- }
- else
- {
- _tprintf(_T("This sample does not support this version of Windows.\n"));
- return FALSE;
- }
- }
- };
|