Possible Duplicate:
Is there any way to get the size of a c function?
I need to determine the byte size of a c function at runtime. I am working with MSVC and I can use any technique that this compiler offers.
I know this question has been asked a lot, but I could only find people saying “no, its not possible”. Still, maybe I have overseen a solution. If this is the case please point me.
I think this should be possible. A little bit of how you proceed will depend on how accurate a result you need. If some possible inaccuracy is acceptable, my first choice would be
SymEnumSymbols. You supply a call-back function that gets called for each symbol fitting the filter you specify. Your callback function will be given the name and a calculated (guessed) size for each symbol. When you get to the right symbol, you’ve got the size it guesses/calculates for your function (though beware: it can also say the size is 0, so you’ll probably have to do some testing to get a good idea of how well it’s likely to work for what you want).A little testing indicates that this seems to be fairly accurate in the case of functions (I was a bit worried that this might be a case where it would return 0). Note that you do normally want to build with debug information to use this (exporting the function(s) you care about might be sufficient though).
Another possibility (though probably more complex) would be to use
#pragma code_segto put that function you care about in a section by itself with a unique section name, then walk the PE file to find that size of that section.