473,320 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

GetCurrentProcess.Id vs GetCurrentProcessId API

How is the "System.Diagnostics.Process.GetCurrentProcess. Id" different
from the GetCurrentProcessId API (Kernel32.dll)?

I'm trying to convert code from VB6 to VB.NET and supposedly
GetCurrentProcess.Id (.NET) is the equivalent of GetCurrentProcessId
API, but it doesn't work. I placed both in my .NET app to read the
results and I get different numbers. I tried just using the API in .NET
but the function (WD_ConnectPS from ehlapi32.dll) that needs the
process id won't accept it.

How can I get the process id that works in VB6 in VB.NET?

Please help, thank you.

Apr 22 '06 #1
4 13865
> How is the "System.Diagnostics.Process.GetCurrentProcess. Id" different
from the GetCurrentProcessId API (Kernel32.dll)?

I'm trying to convert code from VB6 to VB.NET and supposedly
GetCurrentProcess.Id (.NET) is the equivalent of GetCurrentProcessId
API, but it doesn't work. I placed both in my .NET app to read the
results and I get different numbers. I tried just using the API in .NET
but the function (WD_ConnectPS from ehlapi32.dll) that needs the
process id won't accept it.


Getting the process id works fine for me - x and y are the same below:

Declare Function GetCurrentProcessId Lib "kernel32" () As Integer
Dim x As Integer = System.Diagnostics.Process.GetCurrentProcess.Id
Dim y As Integer = GetCurrentProcessId()

So, the problem is not with the process id, it is with how you call
WD_ConnectPS in ehlapi32.dll. I guess the declare statement is not right.
You may need to talk to the dll authors for some .net advice - is it NetSoft?

Good luck on what sounds like a challenging conversion.
Apr 22 '06 #2
I thought the following was the way to declare APIs in VB.NET:

<DllImport("Kernel32.dll")> Private Shared Function
GetCurrentProcessId() As Long
End Function

I noticed that you declared GetCurrentProcessId as integer and not as
long.
Once I changed every declared function and arguments that were type
"long" in VB6 to "integer" in VB.NET everything worked.

It seems like the difference between VB6 and VB.NET when it comes with
declaring API functions is that when type "long" is used in VB6 and
"integer" is used in VB.NET.

Now, why would GetCurrentProcessId declared as long return a completely
different number than when declared as integer in VB.NET?

Apr 22 '06 #3
> I thought the following was the way to declare APIs in VB.NET:

<DllImport("Kernel32.dll")> Private Shared Function
GetCurrentProcessId() As Long
End Function

I noticed that you declared GetCurrentProcessId as integer and not as
long.
Once I changed every declared function and arguments that were type
"long" in VB6 to "integer" in VB.NET everything worked.

It seems like the difference between VB6 and VB.NET when it comes with
declaring API functions is that when type "long" is used in VB6 and
"integer" is used in VB.NET.

Now, why would GetCurrentProcessId declared as long return a completely
different number than when declared as integer in VB.NET?


Actually, my typical api declaration looks like this:

Friend Declare Function GetDesktopWindow Lib "user32" () As IntPtr

IntPtr (a horrible name for a .net integeral value type) is supposed to cope
with 32-bit and 64 bit issues. The .net doc says this:

"The IntPtr type is designed to be an integer whose size is
platform-specific. That is, an instance of this type is expected to be
32-bits on 32-bit hardware and operating system, and 64-bits on 64-bit
hardware and operating systems."

and this:

"A platform-specific type that is used to represent a pointer or a handle."

I use IntPtr in this context because fxcop suggested it. I suggest you use
fxcop also. It will take a while to get used to it, and some of its
complaints are silly IMO, particularly re naming conventions. But on balance
it points out areas for improvement. I like having no fxcop complaints about
my declare statements.

Apr 22 '06 #4
"johnboy" <jo*********@gmail.com> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.com...
I thought the following was the way to declare APIs in VB.NET:

<DllImport("Kernel32.dll")> Private Shared Function
GetCurrentProcessId() As Long
End Function

I noticed that you declared GetCurrentProcessId as integer and not as
long.
Once I changed every declared function and arguments that were type
"long" in VB6 to "integer" in VB.NET everything worked.

It seems like the difference between VB6 and VB.NET when it comes with
declaring API functions is that when type "long" is used in VB6 and
"integer" is used in VB.NET.
Long in VB6 is 32-bit
Long in VB.NET is 64-bit

Integer in VB6 is 16-bit (IIRC)
Integer in VB.NET is 32-bit

So the correct datatype to use is Integer
Now, why would GetCurrentProcessId declared as long return a completely
different number than when declared as integer in VB.NET?


Why wouldn't it? The return type is part of the declaration to. Using the
wrong one leads to unpredictable results

/claes
Apr 24 '06 #5

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

Similar topics

2
by: CajunCoiler \(http://www.cajuncoiler.tk\) | last post by:
By any chance, would there happen to be an API function available that would allow me to terminate a process by name (as it appears in the task manager list) ?
1
by: Maarten | last post by:
hallow all earlier i posted a question about shutingdown a computer. there was someone who helped me with the code? i don't know anymore who he was. i remember there was an error in the code,...
8
by: Ken Varn | last post by:
Everytime I call Process.GetCurrentProcess() the system goes out to the floppy drive. Why does this happen. I decided to use FileMon to get a log of what is happening when this occurs. Here is...
0
by: GrantS | last post by:
To ensure my C# Winforms application can only have one instance running, I am using the code below: string proc=Process.GetCurrentProcess().ProcessName; // get the list of all processes by that...
0
by: Ken Varn | last post by:
This is a very strange problem that I cannot figure out. It only seems to be happening on my development machine when I browse locally. I have isolated the problem area down to where My ASP.NET...
2
by: eliang | last post by:
after calls to logonuser() impersonateloggedouuser() the call to openprocess() fails with Access is denied. what i need to do to get the access right back to call OpenProcess success.
5
by: Benzi Eilon | last post by:
I have written a C# application which should run as a Windows Service. I must avoid having multiple instances of the application on one machine so I inserted the following code at the beginning of...
99
by: dvdsum | last post by:
Hello, my english is very poor, excuse me. I want that someone explains several things. Ok, Windows, as well as other modern operating systems, gives a set of functions called API. The...
1
by: Matthew Lock | last post by:
Hello, I get some strange behaviour after calling a method on a third party library when I call: System.Diagnostics.Process.GetCurrentProcess().StartTime If I run the following code it works as...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.