Load function at runtime in C++

1.2k views Asked by At

I have following problem:

My program should decide at runtime to load an function (in this case GetExtendedTcpTable()) or not, because the method is not available in Windows 2000!? (can't start the software only in Windows 2000)

Thank you for your help!

greets leon22

2

There are 2 answers

5
Sasha Goldshtein On BEST ANSWER

You didn't quite specify your question, but I suppose that you want to load the function dynamically based on the OS version.

To determine the OS version, you can use GetVersionEx. To load a function dynamically, first use LoadLibrary to retrieve the module handle of its DLL, and then use GetProcAddress to retrieve a function pointer to the function. You will need to cast that function pointer to the correct prototype.

5
William Pursell On

If the function is not available on a particular platform, you want to determine at compile time whether or not to load it not at runtime. During the configury of the build, you determine if the function is available and compile appropriately.