Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of user32.dll on OS X

I am writing a library which uses a few functions from the windows user32.dll library, but I am compiling it with Mono to see how it fares on OS X. Unfortunately it cannot find the user32.dll library for obvious reasons.

But my question is this ... is there a similar library on OS X which I can use? I am specifically looking for the following functions.

[DllImport("user32.dll")]
static extern IntPtr GetForegroundWindow();

[DllImport("user32.dll")]
static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);

[DllImport("user32.dll")]
static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);

[DllImport("user32.dll")]
static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);

I think installing WINE would help, but I would prefer to avoid that if possible. Using the Ruby win32 wrapper is also an option?

like image 693
Nippysaurus Avatar asked Aug 21 '09 23:08

Nippysaurus


2 Answers

From the Mono website:

If you are calling something that is provided by your platform (usually the win32 API), you will have to find a way to accomplish the same functionality on all your target platforms. This could mean replacing your unmanaged call with a managed equivalent, or it can mean detecting what platform you are running on and calling the Win32/*nix/OSX/etc. equivalent.

(http://pinvoke.net can sometimes help you find the managed equivalent to Win32 API calls.)

If you are calling into your own native library, then it depends on the cross-platform capabilities of your library. If your native library will work on all your target platforms, then your application should be fine. If not, you can make your native library cross-platform compatible, do the operation in managed code, or work around it by detecting what platform you are running on.

And they also link to a page on Interop with Native Libraries.

Looking through pinvoke, one result is that GetForegroundWindow references mwinapi -- at first glance, that doesn't look portable, so you might be out of luck in finding a managed solution.

like image 174
Mark Rushakoff Avatar answered Oct 12 '22 11:10

Mark Rushakoff


Probably there is not a direct mapping. In OS X there exist several environment Cocoa/Carbon/Java/X11 and each environment has its own APIs. Cocoa and Java are object oriented APIs whereas Carbon and X11 are based on functions. Apple recommends using Cocoa for new application. You have to instantiate the Cocoa objects and encapsulate the access through your function call.

like image 27
Freeman Avatar answered Oct 12 '22 10:10

Freeman