Avian Waves : Blog
Topic: All
Search Blog
 
Recent Comments
A Real Future for Windows Phone Classic? (8)
cheap beats by dre: On hyv menn yhdess kaikki vaiheet k tyypillisesti...

Using a Reverse Proxy to Automatically Force External Lync Meeting Guests to Use Silverlight Client (7)
buy facebook fans: I am very much impressed from this excellent...

I've Been Blog-Memed? Who Knew I Was So Popular! (3)
college term papers: Hi there. Truly cool Anime ... I only got into...

Mystery of the Server 2008 + IIS7 + OLE = "MDAC Not Installed" Error (20)
Carlos: great article. I had that setting set to True at...
Last 15 Posts
Archives
Posted By Timothy • Topic: Tech
Mar 15, 2008 6:30 PM EDT

I am writing an application for Windows Mobile 5/6 that needs to enumerate all running processes on the system (in order to find the main window handle of another program). I found example code on MSDN here: http://msdn2.microsoft.com/en-us/library/aa446560.aspx. Half the time it works and half the time it gives me the "Unable to create snapshot" exception.

Well, it turns out the problem has to do with flags being sent to the CreateToolhelp32Snapshot function in toolhelp.dll. I found a great blog post on how to fix it here: http://nativemobile.blogspot.com/2006/01/k-jam-and-toolhelp.html. The author did this to fix a bug for K-Jam (HTC Wizard) phones, but the problem happens at least also on my Sprint Mogul (HTC Mogul/Titan) phone and I suspect other WM5 or WM6 devices.

As a side note, for some reason the developer of the MSDN sample code stores the PID of the process in a property he calls "handle." Do not be confused as I was at first. This is NOT the window handle (hWnd). It is actually the PID of the process! And he stores it in an IntPtr to make it even more confusing (even though he always uses it as the casted "int" value). To get the window handle (if you need it), you have to use the managed .Net "Process" class like this:

Dim p As ToolHelp.Process = ToolHelp.Process.GetProcesses(0)
Dim hWnd as IntPtr = Process.GetProcessById(p.handle.toInt32).MainWindowHandle

Trackbacks :
Send trackbacks to this URL:
http://www.avianwaves.com/Blog/track.aspx?id=76
In your blog post, you must link back to my post using this URL:
http://www.avianwaves.com/Blog/default.aspx?id=76
Comments :
very nice
Comment By paper cutter At 7/30/2009 2:29 AM EDT PermaLink
I tried that code too and it's not working n my device (htc hd2) with 6.5 professional.

If i use the trick not errors occurs but no processes are showed in the listbox.
While if i use the original flag i get the "unable to create snapshot" error.

Any idea ?
Thanks
Comment By MaxD At 12/23/2009 7:13 AM EDT PermaLink
Comment By peter At 2/4/2010 9:43 AM EDT PermaLink
I'm also having the same issue on the htc hd2 that i don't get any errors but the findfirst doesn't find anything. So no process is snapped.
Searching on the internet didn't give me any hints yet.
Somehow the taskmanager on the htc hd2 doesn't have this problem. Does anybody has the sourcecode of the taskmanager, likely not.
Comment By Juan At 2/17/2010 9:44 AM EDT PermaLink
Hello together.

If ist does not work on HTC HD2 or somewhere else try this

var handle = CreateToolhelp32Snapshot(TH32CS_SNAPNOHEAPS + TH32CS_SNAPPROCESS, 0);

Summing the two constants made it work on HD2.

Hope that helps.

;-)
Comment By Distromax At 8/11/2010 9:46 AM EDT PermaLink
Add Comment :
Name :
Email :
URL (Optional) :
       
Comments :
Allowed BBCode Tags : LINK (URL), BOLD, ITALIC, UNDERLINE, QUOTE


By posting a comment to this blog, I agree to the blog rules.

This Avian Waves blog is powered by a modified version of Presstopia Blog




Avian Waves Logo