
Under Wine or not under Wine?
- Tutorial
Prelude
In the life of every Windows developer, there may come a time when blood from the nose needs to understand whether WineHQ is running the program or not. Why? Because the world is not perfect, and it is necessary to help Wine digest the application correctly. Of course, if the developer cares about the feedback from the guys on the other side of the barricades (Mac, Linux, etc.).
Motives
I will name a few reasons why our team needed it :
- CHM helpers are disgustingly displayed under Wine;
- on bare Wine there are no MS Jet 4.0 and MS MDAC 2.8;
- and as it turned out, our applications ( one and two ) look better when using Microsoft Core Fonts (Arial, Courier, Times, etc.).
I am sure the list can be supplemented, but this is not the purpose of this article.
Implementation
The method is elegant and simple. I believe that 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;
}
// use
if (GetWineAvail ())
{
ShowMessage ("Wine around, cap!");
}
else
{
ShowMessage ("I did not see the windows more transparently.");
}
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 ;
// use
if GetWineAvail () then
ShowMessage ('Hooray! We are under Winish!')
else
ShowMessage ('Pure Windows, sir!');
end ;
Good luck