اصطلاحات اتصال ومعلمات ونوع إرجاع

نموذج اﻷولى لروتين المساعد هو:

FARPROC WINAPI __delayLoadHelper2( 
   PCImgDelayDescr pidd,
   FARPROC * ppfnIATEntry
);

حيث:

  • pidd
    ثابتة مؤشر إلى ImgDelayDescr (انظر delayimp.h) الذي يحتوي على الإزاحة من بيانات ذات الصلة باستيراد المختلفة وطابع زمني لربط المعلومات التعيين من السمات التي توفر معلومات إضافية حول المحتوى واصف. يوجد حاليا هو سمة واحدة فقط، dlattrRva، والذي يشير إلى أن تكون عناوين عن واصف عناوين الظاهري النسبي (بعكس العناوين الظاهرية).

    راجع بنية و الثابت ملفات تعريف لتعريف بنية PCImgDelayDescr.

  • ppfnIATEntry
    مؤشر للفتحة في تأخير التحميل استيراد عنوان جدول (IAT) بعنوان الخاص بالدالة التي تم استيرادها. يحتاج الروتينية المساعد في sفيre نفس القيمة التي سوف يتم إرجاع في في هذا الموقع.

قيم الراجعه المتوقعة

إذا كانت دالة هو ناجحة، تقوم بإرجاع العنوان الخاص بدالة التي تم استيرادها.

إذا فشلت دالة، تقوم بإصدار استثناء و بإرجاع 0. ثلاثة أنواع من استثناءات يمكن أن يتم مرفوع:

  • معلمة غير صالحة، والذي يحدث إذا السمات في piddلم يتم تحديدها بشكل صحيح.

  • LoadLibrary فشل تشغيل DLL المحددة.

  • GetProcAddress فشل.

هو مسؤولية التحقق لمعالجة هذه الاستثناءات.

ملاحظات

اصطلاح استدعاء دالة المساعد هو __stdcall. نوع القيمة الإرجاع هو غير ذات الصلة، في هذه الحالة FARPROC هو المستخدمة. تحتوي هذه دالة على التوصيل C.

القيمة الإرجاع للتأخير تحميل احتياجات مساعد إلى أن sإلىred في التي تم تمريرها-في موقع مؤشر دالة، إلا إذا كنت تريد الروتين المساعد الخاص بك إلى يمكن استخدامه كموضوعة إعلام. في هذه الحالة، التعليمات البرمجية هو المسؤولة عن البحث عن مؤشر دالة المناسبة للعودة. تعليمة برمجية للتحويل تعليمات برمجية الرابط ينشئ ثم يأخذ تلك القيمة التي يتم إرجاعها كهدف حقيقي للاستيراد وينتقل إليه مباشرة.

النموذج

يلي تعليمات برمجية يوضح كيفية تطبيق دالة ربط بسيطة.

FARPROC WINAPI delayHook(unsigned dliNotify, PDelayLoadInfo pdli)
{
    switch (dliNotify) {
        case dliStartProcessing :

            // If you want to return control to the helper, return 0.
            // Otherwise, return a pointer to a FARPROC helper function
            // that will be used instead, thereby bypassing the rest 
            // of the helper.

            break;

        case dliNotePreLoadLibrary :

            // If you want to return control to the helper, return 0.
            // Otherwise, return your own HMODULE to be used by the 
            // helper instead of having it call LoadLibrary itself.

            break;

        case dliNotePreGetProcAddress :

            // If you want to return control to the helper, return 0.
            // If you choose you may supply your own FARPROC function 
            // address and bypass the helper's call to GetProcAddress.

            break;

        case dliFailLoadLib : 

            // LoadLibrary failed.
            // If you don't want to handle this failure yourself, return 0.
            // In this case the helper will raise an exception 
            // (ERROR_MOD_NOT_FOUND) and exit.
            // If you want to handle the failure by loading an alternate 
            // DLL (for example), then return the HMODULE for 
            // the alternate DLL. The helper will continue execution with 
            // this alternate DLL and attempt to find the
            // requested entrypoint via GetProcAddress.

            break;

        case dliFailGetProc :

            // GetProcAddress failed.
            // If you don't want to handle this failure yourself, return 0.
            // In this case the helper will raise an exception 
            // (ERROR_PROC_NOT_FOUND) and exit.
            // If you choose you may handle the failure by returning 
            // an alternate FARPROC function address.


            break;

        case dliNoteEndProcessing : 

            // This notification is called after all processing is done. 
            // There is no opportunity for modifying the helper's behavior
            // at this point except by longjmp()/throw()/RaiseException. 
            // No return value is processed.

            break;

        default :

            return NULL;
    }

    return NULL;
}

/* 
and then at global scope somewhere
PfnDliHook __pfnDliNotifyHook2 = delayHook;
*/

راجع أيضًا:

المرجع

التعرف وظيفة مساعد