473,473 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

CreateToolhelp32Snapshot

I'm using the following declaration for the PROCESSENTRY32 data
structure obtained from http://pinvoke.net:

<StructLayout(LayoutKind.Sequential)Public Structure PROCESSENTRY32
Public dwSize As Int32
Public cntUsage As Int32
Public th32ProcessID As Int32
Public th32DefaultHeapID As Int32
Public th32ModuleID As Int32
Public cntThreads As Int32
Public th32ParentProcessID As Int32
Public pcPriClassBase As Int32
Public dwFlags As Int32
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)Public
szExeFile As String
End Structure

But when I use it in my API call thus:

Declare Function CreateToolhelp32Snapshot Lib "kernel32.dll" (ByVal
dwFlags As Long, ByVal th32ProcessID As Long) As Long
Dim beforeSnapshot as Long

beforeSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)

I get a run-time error in VB.Net saying "A call to PInvoke function
'CreateToolhelp32Snapshot' has unbalanced the stack. This is likely
because the managed PInvoke signature does not match the unmanaged
target signature. Check that the calling convention and parameters of
the PInvoke signature match the target unmanaged signature."

Does this mean the declarations for the data structure or the API
function are incorrect?
--
______ ___ __
/_ __/_ __/ _ )_______ ___ _/ /_____ ____
/ / / // / _ / __/ -_) _ `/ '_/ -_) __/
/_/ \_, /____/_/ \__/\_,_/_/\_\\__/_/
/___/

There are 10 types of people in this world; those who understand the
binary numbering system and those who don't.

There's no place like 127.0.0.1.

ASCII a silly question, get a silly ANSI.
Sep 17 '06 #1
2 4454
>Does this mean the declarations for the data structure or the API
>function are incorrect?
Yep. The parameters to CreateToolhelp32Snapshot should be Integers and
the return type IntPtr.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Sep 17 '06 #2
Mattias Sjögren wrote:
>Does this mean the declarations for the data structure or the API
function are incorrect?

Yep. The parameters to CreateToolhelp32Snapshot should be Integers and
the return type IntPtr.
Mattias
Thank you, I finally stumbled across that through trial and error. I've
got it working now but I hit a dead end in that I thought I was going to
be able to get a snapshot of CPU usage for each process with this
function but none of the fields in the PROCESSENTRY32 data structure
apparently record that info anyway :).

I already had a managed solution working so looks like I may as well
persevere with that instead. My reading seemed to indicate that I'd
achieve better performance by using the snapshot but I guess that was
primarily for people who are only interested in enumerating basic info
about the processes.

--
______ ___ __
/_ __/_ __/ _ )_______ ___ _/ /_____ ____
/ / / // / _ / __/ -_) _ `/ '_/ -_) __/
/_/ \_, /____/_/ \__/\_,_/_/\_\\__/_/
/___/

There are 10 types of people in this world; those who understand the
binary numbering system and those who don't.

There's no place like 127.0.0.1.

ASCII a silly question, get a silly ANSI.
Sep 17 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: anddos | last post by:
hello fellow coders :D ok what i am trying to do is understand how to get this windows api working.i am trying to get a list of the current process's in task manager then Terminate the process's i...
6
by: Howard Kaikow | last post by:
Given: private struct PROCESSENTRY32 { public int dwSize; public int cntUsage; public int th32ProcessID; public int th32DefaultHeapID; public int th32ModuleID;
3
by: L. L. | last post by:
Hi All, I know using Process class you can get the information of the current processes running on the current computer. Some processes are started by the user. And some processes are started...
1
by: cablitoEscobar | last post by:
The problem lies in the fact that whenever I call CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0) a page fault occurs. The fact is I have a timer set to take a snap-shot per second and the...
3
by: xxs | last post by:
I have writen some codes as follow: #include <windows.h> #include <tlhelp32.h> #include <stdio.h> // Forward declarations: BOOL GetProcessList( ); BOOL ListProcessModules( DWORD dwPID...
7
by: unknownbomb | last post by:
1>------ Build started: Project: TatniumInjector, Configuration: Release Win32 ------ 1>Linking... 1>main.obj : error LNK2019: unresolved external symbol __imp__MessageBoxA@16 referenced in...
2
pablojoshua
by: pablojoshua | last post by:
Ok I have the current processes showing, but it shows the path of the process too. I just want the list to show the .exe or .dll name with the suffix. This is what I have so far (from microsoft) ...
1
by: SVogt83 | last post by:
Is there a way in VB.NET to mimic the "End Process Tree" option found in the task manager? I have searched the process class and can not find any way to determine a relationship between any two...
3
by: entice | last post by:
When I am compiling in visual c++ 2008 express edition I am receiving these two errors main.cpp(224) : error C2664: '_stricmp' : cannot convert parameter 1 from 'WCHAR ' to 'const char *' Types...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.