咨询__finally的使用方法?
程序代码:#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
char* MyHookFn2(char* szTxt)
{
char* pBuf = (char*)malloc(strlen(szTxt) + sizeof(char*) * 32);
return pBuf;
__try
{
sprintf(pBuf,"%s\n",szTxt);
printf("%s\n",pBuf);
}
__finally
{
free(pBuf);
pBuf = NULL;
}
}
int main(int argc,char** argv)
{
printf("%s\n", MyHookFn2("test"));
return 0;
}网上看到 __finally后面的复合语句是终止处理语句。无论受保护区域是正常终止还是异常终止(比如 goto,return,leave等),当它退出的时候,终止处理语句都要执行。但是为什么上述函数char* MyHookFn2(char* szTxt)中的__finally没有被执行呢?



