Does Visual C++ runtime has an equivalent to Objective C runtime load method?
http://gcc.gnu.org/onlinedocs/gcc-2.95.3/objc-features_1.html#SEC2
The GNU Objective-C runtime provides a way that allows you to execute code before the executi开发者_Python百科on of the program enters the main function. The code is executed on a per-class and a per-category basis, through a special class method +load.
Yes. Thoroughly read http://www.codeguru.com/cpp/misc/misc/threadsprocesses/article.php/c6945 but here's the basic gist of it:
typedef int cb(void);
#pragma data_seg(".CRT$XIU")
static cb *autostart[] = { PreMain1, PreMain2 };
// Define PreMain1 and PreMain2 somewhere. They will be called before main().
#pragma data_seg()
This is obviously non-portable.
精彩评论