How to use native methods instead of com objects ?

Dec 12, 2014 at 2:28 PM
I have been using RAPI2 wrapper and needed to check whether an application is running on a mobile device or not.

I encountered with IRAPISession`s CeGetWindow method on MSDN which i am planning to initialize just like this :
[DllImport("RAPI.dll", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern IntPtr CeGetWindow(IntPtr hWnd, GetWindow_Cmd uCmd);

[DllImport("RAPI.dll", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern int CeGetWindowText(IntPtr hWnd, StringBuilder name, int nMaxCount);

        public enum GetWindow_Cmd : uint
            GW_HWNDFIRST = 0,
            GW_HWNDLAST = 1,
            GW_HWNDNEXT = 2,
            GW_HWNDPREV = 3,
            GW_OWNER = 4,
            GW_CHILD = 5,
            GW_ENABLEDPOPUP = 6
And then use it like that :
public static bool IsAppRunning(string appName)
            IntPtr ptr = CeGetWindow(IntPtr.Zero, GetWindow_Cmd.GW_CHILD);
            ptr = CeGetWindow(ptr, GetWindow_Cmd.GW_HWNDLAST);
My problem is IntPtr is zero.
If i use OpenNetcf.desktop.communications dll it works correctly however, the same approach won't work with RAPI2 wrapper.

Am i doing something wrong ?
Any help would be appreciated.