在Delphi中如何调用C语言的Dll?

解决方案 »

  1.   

    You can call operating system routines directly, but they are not linked to your application until runtime. This means that the library need not be present when you compile your program. It also means that there is no compile-time validation of attempts to import a routine.
    Before you can call routines defined in a shared object, you must import them. This can be done in two ways: by declaring an external procedure or function, or by direct calls to the operating system. Whichever method you use, the routines are not linked to your application until runtime. Object Pascal does not support importing of variables from shared libraries.Static loadingThe simplest way to import a procedure or function is to declare it using the external directive. For example,On Windows:procedure DoSomething; external 'MYLIB.DLL';
    On Linux:  procedure DoSomething; external 'mylib.so';If you include this declaration in a program, MYLIB.DLL (Windows) or mylib.so (Linux) is loaded once, when the program starts. Throughout execution of the program, the identifier DoSomething always refers to the same entry point in the same shared library.
    Declarations of imported routines can be placed directly in the program or unit where they are called. To simplify maintenance, however, you can collect external declarations into a separate 搃mport unit?that also contains any constants and types required for interfacing with the library. Other modules that use the import unit can call any routines declared in it.For more information about external declarations, see External declarations.
      

  2.   

    你如果会使用 Delphi 做的DLL,那么一样用的。
    静态:
    function FuncName(..):ResultType; external 'ADLL.dll' name 'FuncName'; stdcall;
    动态:
      LoadLibrary