Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 1st, 2003, 10:50 AM
Mozo_Grand Mozo_Grand is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: North Wales UK
Posts: 20 Mozo_Grand User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
kernel32.dll etc info on functions ?

Could anyone tell me where i can find the syntax and other info about these inherent windows libraries (kernel322.dll user32.dll etc) ?

The specific function i require is finding the memory start address and length of a program that is running in Windows NT.

Currently i have the ability to get the process ID by using the FindWindow function, but this is just code pasted on to me. What i need is a resource that i can consult for this type of info.

Thanks

ps. i tried the microsoft site but it's not the most helpful of places !

[edit]
It seems Microsoft dictates there is a difference between Windows NT and Windows 2000, it is Windows 2000 that i'm interested in.
[/edit]

Last edited by Mozo_Grand : March 1st, 2003 at 11:18 AM.

Reply With Quote
  #2  
Old March 1st, 2003, 09:46 PM
customfittech customfittech is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: St. Louis, MO USA
Posts: 43 customfittech User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
What kinds of info will you already have about the running program? Name? Gender...?

In the meantime, here are some helpful functions I've used many times in the past:

Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId As Long
End Type

Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Declare Function GetExitCodeProcess Lib "kernel32" _
(ByVal hProcess As Long, lpExitCode As Long) As Long

Private Declare Function CreateProcess Lib "kernel32" _
Alias "CreateProcessA" _
(ByVal lpApplicationName As String, _
ByVal lpCommandLine As String, _
lpProcessAttributes As Any, _
lpThreadAttributes As Any, _
ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, _
lpEnvironment As Any, _
ByVal lpCurrentDriectory As String, _
lpStartupInfo As STARTUPINFO, _
lpProcessInformation As PROCESS_INFORMATION) As Long

Private Declare Function OpenProcess Lib "kernel32.dll" _
(ByVal dwAccess As Long, _
ByVal fInherit As Integer, _
ByVal hObject As Long) As Long

Private Declare Function TerminateProcess Lib "kernel32" _
(ByVal hProcess As Long, _
ByVal uExitCode As Long) As Long

Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long

Const SYNCHRONIZE = 1048576
Const NORMAL_PRIORITY_CLASS = &H20&

Private pInfo As PROCESS_INFORMATION
Private sInfo As STARTUPINFO

' END OF DECLARATIONS

Public Function RunProgram(sProgram As String, sProgramDir As String)
Dim sNull As String
Dim lSuccess As Long
Dim lRetValue As Long

sInfo.cb = Len(sInfo)
lSuccess = CreateProcess(sNull, _
sProgram, _
ByVal 0&, _
ByVal 0&, _
1&, _
NORMAL_PRIORITY_CLASS, _
ByVal 0&, _
sProgramDir, _
sInfo, _
pInfo)

End Function

Public Function IsRunning() As Boolean
Dim nExitCode As Long
Dim nn As Long
IsRunning = True

nn = GetExitCodeProcess(pInfo.hProcess, nExitCode)
If nExitCode = 0 Then IsRunning = False
End Function

Public Function KillProgram()
Dim lRetValue As Long

lRetValue = TerminateProcess(pInfo.hProcess, 0&)
lRetValue = CloseHandle(pInfo.hThread)
lRetValue = CloseHandle(pInfo.hProcess)
End Function


Public Function ProgramProcess() As Long
ProgramProcess = pInfo.hProcess
End Property
Public Function ProgramThread() As Long
ProgramThread = pInfo.hThread
End Property
__________________
- Chris of Custom Fit Technology
http://www.customfittech.com

Access to MySQL Conversion Tool,
Visual XSLT Conversion Tool

Last edited by customfittech : March 1st, 2003 at 09:49 PM.

Reply With Quote
  #3  
Old March 4th, 2003, 05:02 AM
Mozo_Grand Mozo_Grand is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: North Wales UK
Posts: 20 Mozo_Grand User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
thanks for the reply, lots of info !

what i'm particularly interested in is a resource where i can find out these things. I currently have a method to obtain some info which enables me to read memory contents but i need more info about how else i can use it.


Declare Function ReadProcessMemory Lib "kernel32" (ByVal _
hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal _
nSize As Long, lpNumberOfBytesWritten As Long) As Long
Declare Function GetWindowThreadProcessId Lib "user32" (ByVal _
hwnd As Long, lpdwProcessId As Long) As Long
Declare Function OpenProcess Lib "kernel32" (ByVal _
dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal _
dwProcessId As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As _
Long) As Long
Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetCurrentThreadId Lib "kernel32" () As Long


Function ReadFloat(Offset As Long)

thehwnd = FindWindow(vbNullString, "Prog_Name")
GetWindowThreadProcessId thehwnd, ProcessId
processhandle = OpenProcess(&H10, False, ProcessId)

X = ReadProcessMemory(ByVal processhandle, ByVal Offset, _
nBuffer, 4, 0)
ReadFloat = nBuffer

CloseHandle processhandle
End Function


This code which i'm currently using contains a number of calls to outside functions in the kernel32 and user32 dll files. Where can i find out their parameters and a list of what other functions are available ?

thanks

Last edited by Mozo_Grand : March 4th, 2003 at 05:10 AM.

Reply With Quote
  #4  
Old March 4th, 2003, 10:38 AM
customfittech customfittech is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: St. Louis, MO USA
Posts: 43 customfittech User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Oh sure, it's in Visual Studio X(6) Tools > API Text Viewer.

Also, I'm sure there are very good books on the subject.

Reply With Quote
  #5  
Old March 4th, 2003, 04:06 PM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 4,840 Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 2 Days 36 m 16 sec
Reputation Power: 88
Send a message via ICQ to Onslaught

Reply With Quote
  #6  
Old March 5th, 2003, 07:48 AM
Mozo_Grand Mozo_Grand is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: North Wales UK
Posts: 20 Mozo_Grand User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
ok thanks, guess i must be being real stupid but there is no such item on my tools menu ! I can load an API viewer as an addin but that doesn't seem to be much help either and doesn't appear on the tools menu.

The google link lists several books so i guess i'll have to get ordering.

Thanks both anyway for your help.

Reply With Quote
  #7  
Old March 5th, 2003, 08:18 AM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 4,840 Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 2 Days 36 m 16 sec
Reputation Power: 88
Send a message via ICQ to Onslaught
To get the api viewer into the add-ins menu, click on the Add-Ins menu, then click on Add-In Manager... option. This will bring up a dialog box that list all of the add-ins that you can add to the menu. A few entries down the list you will see an entry VB 6 API Viewer.
Click on it.
In the Load Behaivor frame on the dialog in the lower right corner click the Loaded/Unloaded checkbox and the Load on Startup checkbox then click the OK button.

This will put the API Viewer into your add-ins menu.
Once you open the viewer, click on the File -> Load Text File... in the menu and select WIN32API.txt file. This will load the api declarations into the viewer for you.

Reply With Quote
  #8  
Old March 8th, 2003, 05:20 PM
moexu moexu is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 8 moexu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Book on Win32 API

In my opinion, the best book on the subject of Windows APIs for VB programmers is Dan Appleman's aptly named Visual Basic Programmer's Guide to the Win32 API. I'm not sure how updated it is though - I think it's mostly VB6. It could probably be picked up used somewhere pretty cheaply though.

Desaware

Reply With Quote
  #9  
Old March 9th, 2003, 10:30 AM
Mozo_Grand Mozo_Grand is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: North Wales UK
Posts: 20 Mozo_Grand User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
ok thanks all, will see what i can find.

Reply With Quote
  #10  
Old August 27th, 2003, 07:43 AM
pembleton pembleton is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 4 pembleton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
You shouldn't need to buy any books, look for Miscrosoft's Win32.hlp file. Borland for example, bundles MS tech help files with their development tools. I don't use MS stuff much, but I'd expect them to do the same.

Reply With Quote
  #11  
Old August 27th, 2003, 10:21 AM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 12th Plane (10500 - 10999 posts)
 
Join Date: Jun 2003
Posts: 10,959 Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 15 h 59 m 14 sec
Reputation Power: 802

Reply With Quote
  #12  
Old August 27th, 2003, 10:38 AM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 4,840 Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 2 Days 36 m 16 sec
Reputation Power: 88
Send a message via ICQ to Onslaught
Although it is nice to see the link to the msdn library and the mention to the help file (fyi VS help is the msdn library) but if you would re-read the first post the Mozo_Grand stated that (s)he had already been to the microsoft site and didn't find it that helpfull. I would agree that the site is a good reference, but IMHO the poster is looking for something a little different.

Reply With Quote
  #13  
Old August 27th, 2003, 09:59 PM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 12th Plane (10500 - 10999 posts)
 
Join Date: Jun 2003
Posts: 10,959 Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 15 h 59 m 14 sec
Reputation Power: 802
Quote:
Originally posted by Onslaught
Although it is nice to see the link to the msdn library and the mention to the help file (fyi VS help is the msdn library) but if you would re-read the first post the Mozo_Grand stated that (s)he had already been to the microsoft site and didn't find it that helpfull. I would agree that the site is a good reference, but IMHO the poster is looking for something a little different.

Whatever. Is there a point you are trying to make, like don't bother to post or something?
__________________
======
Doug G
======
I didn't attend the funeral, but I sent a nice letter saying I approved
of it. --Mark Twain

Reply With Quote
  #14  
Old August 27th, 2003, 10:07 PM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 4,840 Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 2 Days 36 m 16 sec
Reputation Power: 88
Send a message via ICQ to Onslaught
Yeah, there is a point. Read the thread before you post a response.

Reply With Quote
  #15