Krähne
Krähne

Reputation: 185

Need help converting Vb.Net to Delphi (API Stuff (?))

    Dim ThisModule As IntPtr
    Dim Proc As Process() = Process.GetProcessesByName("Sol")

    For i = 0 To Proc(0).Modules.Count - 1
        If (Proc(0).Modules(i).ModuleName.ToString.Contains("UxTheme")) Then
            ThisModule = Proc(0).Modules(i).BaseAddress
        End If
    Next

I have made this code, and works perfectly, but now... i want to make it in Delphi, the problem is... i have not the enough knowledge for make it, and... in google, i haven't found the information i need.

Thanks in advance!.

Upvotes: 1

Views: 525

Answers (2)

Fabricio Araujo
Fabricio Araujo

Reputation: 3820

You could use the free modules form MadCollection (madKernel, if I'm not mistaken) which have such libraries. The coding are very near those of the OP. (I've used it to send messages to the parent process of one of my programs ).

EDIT:
About licensing troubles, see this quote from Madshi.net license agreement page:

FREEWARE PRODUCT(S)

The packages "madBasic", "madKernel", "madShell" and "madSecurity" may be used freely for both non-commercial and commercial use, without buying a license, provided that:

(1) The author Mathias Rauen is given proper credit for his work.

(2) The licensee does not claim that the library was written by him.

(3) If the software is modified, any software containing modifications must prominently state in the modified product or documentation

  (a) that it has been modified,

  (b) the identity of the person or entity that made the modifications

and

  (c) the date the modifications were made.

(4) The mentioned packages must not be transferred to any third party unless such third party receives a copy of this agreement and agrees to be bound by all of its terms and conditions.

Upvotes: 1

David Heffernan
David Heffernan

Reputation: 612794

You need to use a lower level API, the tool help API. A basic outline of how to get what you need is as follows:

  1. Call CreateToolhelp32Snapshot() passing TH32CS_SNAPPROCESS.
  2. Next walk the processes with Process32First() and Process32Next() until you find the process you want.
  3. Call CloseHandle() to close the snapshot.
  4. Call CreateToolhelp32Snapshot() again, this time passing TH32CS_SNAPMODULE and the desired process ID found in step 2.
  5. Walk the modules with Module32First() and Module32Next() until you find the module you want.
  6. Call CloseHandle() to close the snapshot.

Upvotes: 2

Related Questions