473,321 Members | 1,669 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,321 software developers and data experts.

How do you handle AddressOf MethodName in old Win32 API code

Hello All,

When a Win32 API method allows AddressOf MethodName to be resolved to a Long, how do you handle that in .Net? See example code below which works fine in VB but throws an error when I try to convert it.

Old VB Code

Declare Function EnumThreadWindows Lib "user32" (ByVal dwThreadId As Long, ByVal lpfn As Long, ByVal lParam As Long) As Long

Public Sub MySub(ByVal hWnd As Long)

Dim ThreadID As Long, ProcessID As Long
ThreadID = GetWindowThreadProcessId(hWnd, ProcessID)

' Use the callback function to list all of the enumerated thread windows
Call EnumThreadWindows(ThreadID, AddressOf EnumThreadWndProc, 0)

End Sub

Public Function EnumThreadWndProc(ByVal hWnd As Long, ByVal lParam As Long) As Long
' My code goes here
' Continue the enumeration.
EnumThreadWndProc = 1
End Function

I get errors with the AddressOf EnumThreadWndProc because it cannot be converted to a Long because it is a delegate type. Thanks in advance for any ideas and/or suggestions!
Oct 11 '07 #1
2 1739
Plater
7,872 Expert 4TB
You're looking for the windows process id?
I think you can do a Me.hWND or something like that to get a window handle?
Oct 11 '07 #2
Hello,

Use the following declaration instead:

Declare Function EnumThreadWindows(ByVal threadId As Integer, ByVal callback As EnumThreadWindowsDelegate, ByVal lParam As IntPtr) As Integer

Note that VB6 Longs are VB.Net Integers. Good Luck!
Jan 29 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Joshua Beall | last post by:
Hi All, I have been trying to dynamically call a static member function, as follows: $className = 'MyClass'; $methodName = 'MyMethod' $result = $className::$methodName(); However, I get a...
28
by: Grant Edwards | last post by:
I finally figured out why one of my apps sometimes fails under Win32 when it always works fine under Linux: Under Win32, the pickle module only works with a subset of floating point values. In...
3
by: Fred Hebert | last post by:
I am trying to use a 3rd party DLL that requires the main window handle as a parameter. e.g. MyFunc(WHND MyHandle); The example looks something like this: Result = MyFunc(Handle); Where...
4
by: Fred Heida | last post by:
Hi All, maybe this is a sill question..but if i have TextBox and use the SendMessage(..) to send a character the control.. the KeyDown event is not triggered.... in would need to check in the...
13
by: DraguVaso | last post by:
Hi, I have a Generic List, for instance: Public MyPersonnesDeContact As New System.Collections.Generic.List(Of clsPersonne) My clsPersonne raises some events, and I want to be able to handle...
2
by: mlc | last post by:
I have a server (in win32 C++, TCP) that listens and accepts socket calls, then via CreateProcess and handle inheritence over the command line starts up a process to handle the client request. Is...
7
by: Ken Varn | last post by:
I am working in managed C++. I have a Mutex object in which I need to replace the Handle property with a new handle. The new handle is being constructed using Win32 CreateMutex call. I need to...
1
by: Stan Sainte-Rose | last post by:
Hi How to know if a control has an handle. To be more clear, sometimes I have to remove handle using RemoveHandler MyControl.Leave, addressOf MyControl_Leave and use AddHandler MyControl.Leave,...
0
by: wmihelpme | last post by:
Hi All, I have written a WMI Program which changes the network settings like ip address, subnet mask, gateway and dns addresses for given adapter number. when I call that function for adapter...
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...

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.