I want to get the ControlName of .NET properties in VB6 code, just like described in this article. But unfortunately, it doesn't work for me. I always got 0 for bufferMem. - bufferMem = VirtualAllocEx(processHandle, 0, size,
-
MEM_RESERVE Or MEM_COMMIT, PAGE_READWRITE)
-
If bufferMem = 0 Then
-
Error Err, "VirtualAllocEx API Failed"
-
End If
What am I doing wrong?
1 2726
Hi All,
I have managed VirtualAllocEx. Before I declared this function as Private. Then when I moved it to Module file and changed it to Public, I don't get 0 anymore for bufferMem. Also I need to set lpAddress as ByVal. Otherwise, the length of controlName that given is twice than correct length (I don't know exactly how this happens). - Declare Function VirtualAllocEx Lib "kernel32" _
-
(ByVal hProcess As Long, _
-
ByVal lpAddress As Long, _
-
ByVal dwSize As Long, _
-
ByVal flAllocationType As Long, _
-
ByVal flProtect As Long) As Long
Now I got the correct retLength, but unfortunately retVal is 0, return the error description: Invalid procedure call or argument. - If retLength <> 0 Then
-
'Now read the component's name from the shared memory location.
-
retVal = ReadProcessMemory(processHandle, bufferMem, bytearray, size, VarPtr(written))
-
If retVal = 0 Then
-
Error Err 'ReadProcessMemory API Failed
-
End If
-
End If
My declaration of ReadProcessMemory is: - Declare Function ReadProcessMemory Lib "kernel32" _
-
(ByVal hProcess As Long, _
-
ByVal lpBaseAddress As Long, _
-
lpBuffer As Any, _
-
ByVal nSize As Long, _
-
lpNumberOfBytesRead As Long) As Long
And when I run the whole thing (ignore the retVal value), I got error in WideCharToMultiByte: - Function ByteArrayToString(bytes As String, length As Long) As String
-
Dim retValStr As String
-
Dim l As Long
-
-
If IsWin9x() Then
-
retValStr = Left(bytes, InStr(1, bytes, Chr(0)) - 1)
-
Else
-
retValStr = String$(length + 1, Chr(0))
-
l = WideCharToMultiByte(CP_ACP, 0, bytes, -1, retValStr, length + 1, Null, Null)
-
End If
-
-
ByteArrayToString = retValStr
-
End Function
The error is saying: - Run-time error '94':
-
-
Invalid use of Null
Any idea?
Here is the code: - Function GetWindowsFormsID(ByVal wnd As Long) As String
-
Dim PID As Long 'pid of the process that contains the control
-
Dim msg As Long
-
-
' Define the buffer that will eventually contain the desired
-
' component's name.
-
Dim bytearray As String * 65526
-
-
' Allocate space in the target process for the buffer as shared
-
' memory.
-
Dim bufferMem As Long
-
' Base address of the allocated region for the buffer.
-
Dim size As Long
-
' The amount of memory to be allocated.
-
Dim written As Long
-
' Number of bytes written to memory.
-
Dim retLength As Long
-
Dim retVal As Long
-
Dim errNum As Integer
-
Dim errDescription As String
-
-
size = 65527 'Len(bytearray)
-
-
' Creating and reading from a shared memory region is done
-
' differently in Win9x than in newer Oss.
-
Dim processHandle As Long
-
Dim fileHandle As Long
-
-
msg = RegisterWindowMessage("WM_GETCONTROLNAME")
-
-
If Not IsWin9x() Then
-
On Local Error GoTo Error_Handler_NT
-
Dim dwResult As Long
-
Call GetWindowThreadProcessId(wnd, PID)
-
-
processHandle = OpenProcess(PROCESS_VM_OPERATION Or PROCESS_VM_READ Or PROCESS_VM_WRITE, 0, PID)
-
If processHandle = 0 Then
-
Error Err 'OpenProcess API Failed
-
End If
-
-
bufferMem = VirtualAllocEx(processHandle, 0, size, MEM_RESERVE Or MEM_COMMIT, PAGE_READWRITE)
-
If bufferMem = 0 Then
-
Error Err 'VirtualAllocEx API Failed
-
End If
-
-
' Send message to the control's HWND for getting the
-
' Specified control name.
-
retLength = SendMessage(wnd, msg, size, ByVal bufferMem)
-
-
If retLength <> 0 Then
-
' Now read the component's name from the shared memory location.
-
retVal = ReadProcessMemory(processHandle, bufferMem, bytearray, size, VarPtr(written))
-
If retVal = 0 Then
-
Error Err 'ReadProcessMemory API Failed
-
End If
-
End If
-
-
Error_Handler_NT:
-
errNum = Err
-
errDescription = Error$
-
' Free the memory that was allocated.
-
retVal = VirtualFreeEx(processHandle, bufferMem, 0, MEM_RELEASE)
-
If retVal = 0 Then
-
Error Err 'VirtualFreeEx API Failed
-
End If
-
CloseHandle (processHandle)
-
If errNum <> 0 Then
-
On Local Error GoTo 0
-
Error errNum 'errDescription
-
End If
-
On Local Error GoTo 0
-
-
-
Else
-
On Local Error GoTo Error_Handler_9x
-
-
Dim SA As SECURITY_ATTRIBUTES
-
-
fileHandle = CreateFileMapping(INVALID_HANDLE_VALUE, SA, PAGE_READWRITE, 0, size, Null)
-
If fileHandle = 0 Then
-
Error Err 'CreateFileMapping API Failed
-
End If
-
bufferMem = MapViewOfFile(fileHandle, FILE_MAP_ALL_ACCESS, 0, 0, 0)
-
If bufferMem = 0 Then
-
Error Err 'MapViewOfFile API Failed
-
End If
-
-
Call CopyMemory(bufferMem, bytearray, size)
-
-
' Send message to the treeview control's HWND for
-
' getting the specified control's name.
-
retLength = SendMessage(wnd, msg, size, bufferMem)
-
-
' Read the control's name from the specific shared memory
-
' for the buffer.
-
Call CopyMemoryA(bytearray, bufferMem, 1024)
-
-
Error_Handler_9x:
-
errNum = Err
-
errDescription = Error$
-
-
' Unmap and close the file.
-
UnmapViewOfFile (bufferMem)
-
CloseHandle (fileHandle)
-
-
If errNum <> 0 Then
-
On Local Error GoTo 0
-
Error errNum 'errDescription
-
End If
-
On Local Error GoTo 0
-
-
End If
-
-
If retLength <> 0 Then
-
' Get the string value for the Control name.
-
GetWindowsFormsID = ByteArrayToString(bytearray, retLength)
-
End If
-
-
End Function
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Kate Gibbs |
last post by:
I need to write a simple utility in VB.NET that reads an
Excel file, gets some data from a sheet, then...it needs
to automate internet explorer in a robot manner.
I know that Application Centre...
|
by: Helen W |
last post by:
The Knowledge Base article below explains how to talk to a running instance
of an Office program:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;316126
Is there any way I can talk...
|
by: Elhanan |
last post by:
hi.. all
a client of ours is considering to move from a dos application to
windows desktop application.
the application is for traveling agency, the database is rather large.
their current...
|
by: Segfahlt |
last post by:
I need a little help here please.
I have 2 win forms user controls in 2 different projects that I'm hosting in
2 different virtual directories. The controls have been test and operate okay
in...
|
by: Pieter |
last post by:
Hi,
In my application VB.NET 2005 application I placed a ReportViewer, and link
it to a server-report:
Me.ReportViewer1.ProcessingMode =
Microsoft.Reporting.WinForms.ProcessingMode.Remote...
| |
by: 3Cooks |
last post by:
I have a windows application written in Visual Basic 6.0 that is going
to be redeveloped in dotNET. We are trying to decide if we should
deploy using Webforms or Winforms and I need advice from...
|
by: brian.wilson4 |
last post by:
Our group is currently comparing winforms vs webforms.....app is Corp
LAN based - we have control of desktops.....Below is pros and cons list
we have come up with - if anything strikes you as...
|
by: gert365 |
last post by:
I'm working on a scirpt to be used on a windows machine and I need to
automate a user's input on the command prompt. For example I'm using
os.system('mycommand') to excute the commands I want. ...
|
by: =?Utf-8?B?QWxleGFuZGVyIFd5a2Vs?= |
last post by:
Is it possible to automate a COM object ebmeded in an excel document run the
process and return the results in a C# .NET application? Or better yet
extract the com object some how and just run it...
|
by: raylopez99 |
last post by:
Here I am learning WinForms and two months into it I learn there's a
WPF API that is coming out. Is this WPF out yet, and is it a threat
to WinForms, in the sense that all the library routines I...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
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...
|
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...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |