Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use GetProcAddress or just include various win32 libraries?

Tags:

c++

c

winapi

Wonder what the difference between:

static PROCESSWALK pProcess32First=(PROCESSWALK)GetProcAddress(hKernel,"Process32First");
...
pProcess32First(...);

what is hKernel? Look in here. You can replace with GetModuleHandle()

and

#include <Tlhelp32.h>
...
Process32First(...);

What are the differences, I wonder which I should use. Is there any difference in terms of best practices then?

like image 277
Zombies Avatar asked Feb 03 '26 23:02

Zombies


1 Answers

NOTE: my answer assumes that the function is available either way, there are other things to consider if you are after non-exported functions.

If you use LoadLibrary and GetProcAddress, then you have the option running with reduced functionality if the required library isn't there. if you use the include and link directly the lib, and dll isn't there (or doesn't have the export due to wrong version) your app will simply fail to load.

It really only makes a difference if you want to use a function that isn't in all versions of a given dll.

like image 142
Evan Teran Avatar answered Feb 05 '26 12:02

Evan Teran



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!