📜 ⬆️ ⬇️

Under Wine or not under Wine?

Prelude



In the life of every Windows developer, there may come a time when blood from the nose needs to be understood whether the program is running under WineHQ or not. Why? Because the world is not perfect, and you need to help Wine digest the application correctly. Of course, if the developer is concerned about feedback from the guys on the other side of the barricades (Mac, Linux, etc.).


')

Motives



I’ll name a few reasons why our command needed it:


I am sure the list can be supplemented, but this is not the purpose of this article.

Implementation



The way is elegant and simple. I guess any sane developer will be able to adapt this for their favorite language.

Implementation for C:

bool GetWineAvail ()
{
HMODULE h = LoadLibrary ( "ntdll.dll" );
bool r = false ;

if (h ! = NULL )
{
r = GetProcAddress (h, "wine_get_version" ) ! = NULL ;
FreeLibrary (h);
}

return r;
}

//using
if (GetWineAvail ())
{
ShowMessage ( "Around wine, cap!" );
}
else
{
ShowMessage ( "I did not see the window is more transparent." );
}

Implementation for Delphi:
function GetWineAvail : boolean ;
var H : cardinal ;
begin
Result : = False ;
H : = LoadLibrary ( 'ntdll.dll' ) ;
if H > 0 then
begin
Result : = Assigned (GetProcAddress (H , 'wine_get_version' )) ;
FreeLibrary (H) ;
end ;
end ;

//using
if GetWineAvail () then
ShowMessage ( 'Hurray! We're at Vinische!' )
else
ShowMessage ( 'Cleanest Windows, sir!' ) ;
end ;

Good luck!

Source: https://habr.com/ru/post/76131/


All Articles