Can I Detect Host OS for Wine from Within Program?

Open forum for end-user questions about Wine. Before asking questions, check out the Wiki as a first step.
Forum Rules
Locked
robertinventor
Level 1
Level 1
Posts: 7
Joined: Wed Mar 06, 2013 11:52 am

Can I Detect Host OS for Wine from Within Program?

Post by robertinventor »

Hi, I am in process of making my App Wine compatible.

Anyway I know how to detect if it is running under Wine from the registry keys here:

http://wiki.winehq.org/UsefulRegistryKeys

That's been very useful for bugs not yet fixed, including for instance an ancient bug that doesn't look like it is ever going to be fixed to do with use of SetFocus to bring a window to the front - this dosn't work in Wine, so when running under Wine my program instead just destroys the window and re-creates it which has pretty much the same effect.

Anyway - but now I want to be able to detect if my program is running under Wine on Linux or under Wine on the Mac.

It is so it can show help to the user about ways to improve timing. I will recommend the user changes to the realtime kernel for Wine if they want the very best accuracy of timing (my program is a metronome and accuracy of timing is important to its users).

This message though wouldn't mean anything to a user running it under Wine on a Mac and would just confuse them.

I can imagine there might also be other occasions in the future when my program might want to know if the host OS for Wine is a Mac or Linux.

Can I detect anything about the host OS from within my program?

Thanks,
jorl17
Level 5
Level 5
Posts: 365
Joined: Mon Jul 28, 2008 6:44 pm

Re: Can I Detect Host OS for Wine from Within Program?

Post by jorl17 »

If you're using winelib, then you can just use whatever POSIX functions allow you to do this, and that is well documented online.

(You can always use hardcoded sycalls, anyway)

However, if you are not using winelib, you can simply find ways to run commands which tell you which operating system you are on. Think, for example, 'uname'.

Cheers,
João Ricardo Lourenço
robertinventor
Level 1
Level 1
Posts: 7
Joined: Wed Mar 06, 2013 11:52 am

Re: Can I Detect Host OS for Wine from Within Program?

Post by robertinventor »

Thanks that sounds like a good plan. I'm not using winelib. So will need to find a way to run uname.

Perhaps I'll run a hidden console with pipes so my program can send output to it and receive output back again - have done that before in Windows anyway. Then just issue a uname command to the console and then read it to find out the information.

Will give it a go and see if it works.

Cheers,

Robert
jorl17 wrote:If you're using winelib, then you can just use whatever POSIX functions allow you to do this, and that is well documented online.

(You can always use hardcoded sycalls, anyway)

However, if you are not using winelib, you can simply find ways to run commands which tell you which operating system you are on. Think, for example, 'uname'.

Cheers,
João Ricardo Lourenço
robertinventor
Level 1
Level 1
Posts: 7
Joined: Wed Mar 06, 2013 11:52 am

Re: Can I Detect Host OS for Wine from Within Program?

Post by robertinventor »

Sadly just tried it, it doesn't work.

I'm pretty sure that the reason is that the command line I can access from my Windows program usig system(..) or ShellExecute(..) etc. is a Wine emulation of the DOS command prompt, and so doesn't have the uname command. And if I issue any commands to it, then it would just behave as it would under Windows and so not tell me anything about the host OS.

I tried:

Code: Select all

 system("> \"C:\\Programs\\Bounce Metronome\\os.txt\" uname");
 system("> \"C:\\Programs\\Bounce Metronome\\dir.txt\" dir");
 ShellExecute(NULL,"open","cmd.exe", "/C uname > \"C:\\Programs\\Bounce Metronome\\uname.txt\""
     ,NULL,SW_HIDE);
(just for debug purposes which is why I have hard coded paths to the files)

The output files are all created. The dir.txt lists the directory contents as expected so the process is working. But the uname.txt and os.txt files are blank.

While if I open a command prompt myself and then issue

Code: Select all

uname
it shows as response

Code: Select all

Linux
as expected.

Thanks for the idea though! Any other thoughts, or anyone else got any other thoughts?
julliard
Level 2
Level 2
Posts: 11
Joined: Sat Mar 30, 2013 12:22 pm

Re: Can I Detect Host OS for Wine from Within Program?

Post by julliard »

Check out ntdll.wine_get_host_version().
robertinventor
Level 1
Level 1
Posts: 7
Joined: Wed Mar 06, 2013 11:52 am

Re: Can I Detect Host OS for Wine from Within Program?

Post by robertinventor »

Great, that worked!

For anyone else who needs it, here is the c-code:

Code: Select all

HINSTANCE hNTDLL=NULL;
PROC pwine_get_host_version=NULL;
hNTDLL=LoadLibrary("ntdll.dll");
if(hNTDLL)
 pwine_get_host_version=(PROC)GetProcAddress(hNTDLL,"wine_get_host_version");
if(pwine_get_host_version)
{
 const char* sys_name = NULL;
 const char* release_name = NULL;
 pwine_get_host_version(&sys_name,&release_name);
}
Thanks so much!
julliard wrote:Check out ntdll.wine_get_host_version().
Locked