> 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.