定义一个C函数:
void CInit()
{
atexit(CExit);
printf("4\n");
}
将一CInit函数指针存放到 ".CRT$XC*"段中 (*为B-Y之间)
typedef void (__cdecl *PVFV)();
#pragma section(".CRT$XCD", long, read)
__declspec(allocate(".CRT$XCD")) PVFV dummy[] = {CInit};
例如:
#include <stdio.h>
class ConstructTest
{
public:
ConstructTest()
{
printf("1\n");
}
~ConstructTest()
{
printf("2\n");
}
};
ConstructTest test;
void CExit()
{
printf("3\n");
}
void CInit()
{
atexit(CExit);
printf("4\n");
}
#define SECNAME ".CRT$XCD"
typedef void (__cdecl *PVFV)();
#pragma section(".CRT$XCD", long, read)
__declspec(allocate(".CRT$XCD")) PVFV dummy[] = {CInit};
int main()
{
return 0;
}