Quantcast
Channel: Visual C forum
Viewing all articles
Browse latest Browse all 15302

How to get function address from current process?

$
0
0

My test process:

test.exe which depends on test.dll and test2.dll. And test.dll exports a function test_fun.

As we known, we can use the following in the test2.dll to get the test_fun address at runtime:

hmod = LoadLibrary("test.dll")

testPtr=GetProcAddress(hmod, "test_fun");

However, the test.dll can change it's name. Then the above code can't work when that happen.

(When this will happen? If the test.dll is provided by a company, but the test2.dll is provide by the other company.)

 

However, if I can use the following to get the test_fun address, then everything works right:

hmainmod= GetModuleHandle(NULL);//get the current process module

testPtr=GetProcAddress(hmainmod, "test_fun"); //this will return NULL

//In fact, the linux so api works like this, it works fine.

 

Is there any simple way to do this?

 

(I think if i can enumerate the dlls loaded by current process, and  try each dll to find the right dll which define test_fun.

But it seems too complicated )

 

 

 

 

 

 


Sorry for my English skill.I try my best to make the question clear.

Viewing all articles
Browse latest Browse all 15302

Trending Articles