Red Gate forums :: View topic - IsWow64() and C#
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
PInvoke.Net
PInvoke.Net forum

IsWow64() and C#

Search in PInvoke.Net forum
Post new topic   Reply to topic
Jump to:  
Author Message
chemelli



Joined: 15 Apr 2008
Posts: 2

PostPosted: Tue Apr 15, 2008 2:35 pm    Post subject: IsWow64() and C# Reply with quote

Hi all,

I just noticed a small error in the sample of IsWow64() and I have correct it.

The main issue in anycase is that I cannot compile my sample program because of those messages from the compiler (VS2005):

Error 1:
'Microsoft.Win32.SafeHandles.SafeProcessHandle' is inaccessible due to its protection level

Error 2:
Inconsistent accessibility: parameter type 'Microsoft.Win32.SafeHandles.SafeProcessHandle' is less accessible than method 'WindowsApplication1.Form1.IsWow64Process(Microsoft.Win32.SafeHandles.SafeProcessHandle, out bool)'


Any help will be much appreciated.

Simone
Back to top
View user's profile Send private message
Robert



Joined: 30 Oct 2006
Posts: 428
Location: Cambridge, UK

PostPosted: Tue Apr 15, 2008 3:36 pm    Post subject: Reply with quote

Hi,

I've just had a quick look at this (purely a look - I haven't tested any of this in code), and it looks like the problem is that SafeProcessHandle is an internal type, so you can't access it in your code. The second error you're seeing is because you're declaring a method as being public, but with a parameter that is internal (less accessible) than the method.

I suspect that you can probably just change it to taking an IntPtr, which is what process.Handle returns:

Code:

[DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool IsWow64Process(
     [In] IntPtr hProcess,       
     [Out] out bool lpSystemInfo
     );


Then something like:

Code:

Process p = Process.GetCurrentProcess();
IntPtr handle = p.Handle;
bool isWow64;
bool success = IsWow64Process (handle, out isWow64);
if (!success)
    throw new Win32Exception();
else
    return isWow64;


Hope that helps, or at least gives you a pointer in the right direction.

Regards,
Robert
_________________
Robert Chipperfield
Developer, Red Gate Software Ltd
Back to top
View user's profile Send private message MSN Messenger
Robert



Joined: 30 Oct 2006
Posts: 428
Location: Cambridge, UK

PostPosted: Tue Apr 15, 2008 3:41 pm    Post subject: Reply with quote

Sorry, another thought I've just had. If you're trying to just check whether the current process is running Wow64, you can do so by checking the value of some environment variables instead: http://msdn2.microsoft.com/en-us/library/aa384274.aspx.

Hope that helps,
Robert
_________________
Robert Chipperfield
Developer, Red Gate Software Ltd
Back to top
View user's profile Send private message MSN Messenger
chemelli



Joined: 15 Apr 2008
Posts: 2

PostPosted: Tue Apr 15, 2008 3:58 pm    Post subject: Reply with quote

Thx Robert,

you code fixed my issue Wink

Simone
Back to top
View user's profile Send private message
Robert



Joined: 30 Oct 2006
Posts: 428
Location: Cambridge, UK

PostPosted: Tue Apr 15, 2008 3:58 pm    Post subject: Reply with quote

Good stuff, glad to help! Smile
_________________
Robert Chipperfield
Developer, Red Gate Software Ltd
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group