Re: Detecting a programm runs using Wine

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I have also been searching for a way to detect if my application is running under wine. As I haven´t found an appropriate solution I came to the following solution. It may not be perfect and there is no guarantee that it will be always working but I think it is a good approach.


Code:

BOOL CMyClass::IsWine() 
{
	CString csRet;
	BOOL fRet = FALSE;
	CString csEntry = _T("ProductName");

	HMODULE hLib = LoadLibrary(_T("ntdll"));

	if (hLib != NULL)
	{
		HRSRC hVersion = FindResource( hLib, 
		MAKEINTRESOURCE(VS_VERSION_INFO), RT_VERSION );
		if (hVersion != NULL)
		{
			HGLOBAL hGlobal = LoadResource( hLib, hVersion ); 
			if ( hGlobal != NULL)  
			{  
				LPVOID versionInfo  = LockResource(hGlobal);  
				if (versionInfo != NULL)
				{
					DWORD vLen,langD;
					BOOL retVal;    

					LPVOID retbuf=NULL;

					TCHAR fileEntry[256];

					_stprintf(fileEntry,_T("\\VarFileInfo\\Translation"));
					retVal = VerQueryValue(versionInfo,fileEntry,&retbuf,(UINT *)&vLen);
					if (retVal && vLen==4) 
					{
						memcpy(&langD,retbuf,4);            
						_stprintf(fileEntry, _T("\\StringFileInfo\\%02X%02X%02X%02X\\%s"),
						(langD & 0xff00)>>8,langD & 0xff,(langD & 0xff000000)>>24, 
						(langD & 0xff0000)>>16, csEntry);            
					}
					else 
					_stprintf(fileEntry, _T("\\StringFileInfo\\%04X04B0\\%s"), 
					GetUserDefaultLangID(), csEntry);

					if (VerQueryValue(versionInfo,fileEntry,&retbuf,(UINT *)&vLen)) 
					{
						csRet = (TCHAR*)retbuf;

						csRet.MakeLower();

						if(0 <= csRet.Find(_T("wine")))
							fRet = TRUE;
					}
				}
			}

			UnlockResource( hGlobal );  
			FreeResource( hGlobal );  
			FreeLibrary(hLib);
		}
	}
	return fRet;
}




This code is mainly based on a publication on www.codeproject.com by luetz: http://www.codeproject.com/KB/cpp/GetLocalVersionInfos.aspx?display=Print.

I simply read the product name of the ntdll.dll which is "Wine" when running under wine.

Hope this helps, JonDoe






[Index of Archives]     [Gimp for Windows]     [Red Hat]     [Samba]     [Yosemite Camping]     [Graphics Cards]     [Wine Home]

  Powered by Linux