举例:
有一个动态库add.dll,实现对输入的数据进行加一的操作
希望在调用该动态库时完成对某变量的初始化,在释放该动态库时将某变量清零希望能看懂:)
就是想在LoadLibrary或FreeLibrary时完成一些功能,不用再进行调用

解决方案 »

  1.   

    你查一下DLL入口函数和出口函数的资料,具体我也没用过,这是从D6开发指南的一个例子
    library DLLEntryLib;
    uses
      SysUtils,
      Windows,
      Dialogs,
      Classes;procedure DLLEntryPoint(dwReason: DWord);
    begin
      case dwReason of
        DLL_PROCESS_ATTACH: ShowMessage('Attaching to process');
        DLL_PROCESS_DETACH: ShowMessage('Detaching from process');
        DLL_THREAD_ATTACH:  MessageBeep(0);
        DLL_THREAD_DETACH:  MessageBeep(0);
      end;
    end;begin
      { First, assign the procedure to the DLLProc variable }
      DllProc := @DLLEntryPoint;
      { Now invoke the procedure to reflect that the DLL is attaching to the
        process }
      DLLEntryPoint(DLL_PROCESS_ATTACH);
    end.