| Author |
Message |
chemelli
Joined: 15 Apr 2008 Posts: 2
|
Posted: Tue Apr 15, 2008 2:35 pm Post subject: IsWow64() and C# |
|
|
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 |
|
 |
Robert
Joined: 30 Oct 2006 Posts: 428 Location: Cambridge, UK
|
Posted: Tue Apr 15, 2008 3:36 pm Post subject: |
|
|
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 |
|
 |
Robert
Joined: 30 Oct 2006 Posts: 428 Location: Cambridge, UK
|
Posted: Tue Apr 15, 2008 3:41 pm Post subject: |
|
|
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 |
|
 |
chemelli
Joined: 15 Apr 2008 Posts: 2
|
Posted: Tue Apr 15, 2008 3:58 pm Post subject: |
|
|
Thx Robert,
you code fixed my issue
Simone |
|
| Back to top |
|
 |
Robert
Joined: 30 Oct 2006 Posts: 428 Location: Cambridge, UK
|
Posted: Tue Apr 15, 2008 3:58 pm Post subject: |
|
|
Good stuff, glad to help!  _________________ Robert Chipperfield
Developer, Red Gate Software Ltd |
|
| Back to top |
|
 |
|