Reputation: 24232
I'm trying to access the Wine implementation of some user32 functions on Kubuntu Linux. I have the Wine 1.1.31 package installed. When try running this simple test program in MonoDevelop, I get a System.EntryPointNotFoundException
.
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace PinvokeTesting
{
class MainClass
{
public static void Main(string[] args)
{
Console.WriteLine(GetKeyState((int)Keys.A));
}
[DllImport("user32")]
private static extern short GetKeyState(int vKey);
}
}
This is the output:
Unhandled Exception: System.EntryPointNotFoundException: GetKeyState at (wrapper managed-to-native) PinvokeTesting.MainClass:GetKeyState (int) at PinvokeTesting.MainClass.Main (System.String[] args) [0x00000] in .../Main.cs:11
The function should be there, but it's not finding it. Any ideas? I've done a lot of searching, haven't found anything helpful. The documentation seems to be rather sparse on these issues (either that or I'm searching for the wrong things).
Edit: I'm not trying to use P/Invoke in combination with Winforms, there are some other functions in Wine I need to P/Invoke to. I'm just trying to get Mono P/Invoke to Wine working.
Upvotes: 2
Views: 4696
Reputation: 3963
The wine libs are completely incompatible with mono. If you need to use wine libs on Linux, you need to get the windows version of mono and run it under wine.
This has nothing to do with Winforms specifically, it holds true for any wine library.
As for the actual solution to your problem:
Upvotes: 3
Reputation: 34592
There is a simple moral to the story here as you have discovered...if there's pinvokes used, do not assume the code to be cross-platform portable and wine compatible! The only thing that you could work around on this would be something like this:
using System; using System.Runtime.InteropServices; using System.Windows.Forms; namespace PinvokeTesting { class MainClass { public static void Main(string[] args) { Console.WriteLine(GetKeyState((int)Keys.A)); } #ifdef WIN32API_NT_5 [DllImport("user32")] private static extern short GetKeyState(int vKey); #else private static extern short GetKeyState(int vKey); #endif } }
And create some kind of a wrapper to substitute for the Win32API pinvoke signature. Just because it references System.Windows.Forms
does not mean that WIN32API pinvokes will work under Wine, as the various underlying interfaces in terms of GUI is different and not guaranteed to be portable.
Then define the switch 'WIN32API_NT_5' or whatever you wish to choose of your own accord if you want to make this cross-platform friendly.
Hope this helps, Best regards, Tom.
Upvotes: 1
Reputation: 11495
If you are trying to do this in combination with the managed System.Windows.Forms implementation in Mono on Linux, then I'm fairly certain that pinvoking Wine is not going to help you. SWF is implemented entirely differently/separately from Wine, and the two do not "mix" or in any way interact.
I suggest you find another way to achieve what you're trying to do.
Upvotes: 3