簡體   English   中英

如何顯式調用CRT啟動功能

[英]How to explicitly call CRT startup functions

我有什么方法可以在代碼中顯式調用通常在mainCRTStartup函數中調用的函數? 我對initterminitterm_e函數特別感興趣。 甚至以為我的程序與crt鏈接(必須是吧?),我不能只調用initterm-我試圖聲明並只是調用而得到未定義的引用。

有什么辦法嗎?

_initterm_initterm_e (msdn _initterm_e注釋聲明錯誤-實際上使用的是_PIFV類型)是由不同的CRT dll導出的。 並且它也在lib文件中聲明。 該功能的實現非常簡單:

typedef void (__cdecl *_PVFV)();

void _initterm(const _PVFV *ppfn, const _PVFV *end)
{
    do 
    {
        if (_PVFV pfn = *++ppfn)
        {
            pfn();
        }
    } while (ppfn < end);
}

typedef int  (__cdecl *_PIFV)();

int _initterm_e(const _PIFV *ppfn, const _PIFV *end)
{
    do 
    {
        if (_PIFV pfn = *++ppfn)
        {
            if (int err = pfn()) return err;
        }
    } while (ppfn < end);

    return 0;
}

因此您可以使用自己的實現將其導入。 這是更快的問題-什么是輸入參數?

說出c ++CL編譯器的最低要求)使用( ".CRT$XCA", ".CRT$XCZ" )部分進行c ++全局初始化。 所以我們可以下一步:

extern "C"
{
#pragma const_seg(".CRT$XCA")
  const _PVFV __xc_a = 0;
#pragma const_seg(".CRT$XCZ")
  const _PVFV __xc_z = 0;

#pragma const_seg(".CRT$XIA")
  const _PVFV __xi_a = 0;
#pragma const_seg(".CRT$XIZ")
  const _PVFV __xi_z = 0;
}

    /*
     * do initializations
     */
    initret = _initterm_e( &__xi_a, &__xi_z );
    if ( initret != 0 )
        return initret;

    /*
     * do C++ initializations
     */
    _initterm( &__xc_a, &__xc_z );

但是這里需要非常了解-我們做什么以及為什么要做

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM