超级难题,请问在delphi语言里跟c语言中extern 等价的词是什么?
解决方案 »
- ListView中的item无法选中,寻找解决方法
- 在Delphi不能用j:=(2^i)来表示2的i次方 (j为Integer类型),问如何表示???!!!!
- 请问三层系统开发策略中的几个问题,高手们帮忙解答一下,万分感激!!!!!!
- Delphi2005测试版已经可以下载了
- 跪求查找各种DELPHI函数的方法以及相关资料!
- sql中判断两个日期之间
- 在TShellTreeView里实现只显示目录的功能,就像“选择目录”对话框的目录树
- 岁末大散分!可用分太多了(9K多呢)!
- 建议程序员消费牛奶制品的时候,尽量选择伊利
- 要DELPHI还是GIRLFRIEND
- 关于XML文件的资源释放的问题,高手指教!
- 如何创建一个TParameter实例?
External declarationsTopic Groups See AlsoThe external directive, which replaces the block in a procedure or function declaration, allows you to call routines that are compiled separately from your program. External routines can come from object files or dynamically loadable libraries.When importing a C function that takes a variable number of parameters, use the varargs directive. For example,function printf(Format: PChar): Integer; cdecl; varargs;The varargs directive works only with external routines and only with the cdecl calling convention.Linking to object filesTo call routines from a separately compiled object file, first link the object file to your application using the $L (or $LINK) compiler directive. For example,On Windows: {$L BLOCK.OBJ}On Linux: {$L block.o}links BLOCK.OBJ (Windows) or block.o (Linux) into the program or unit in which it occurs. Next, declare the functions and procedures that you want to call:procedure MoveWord(var Source, Dest; Count: Integer); external;
procedure FillWord(var Dest; Data: Integer; Count: Integer); external;Now you can call the MoveWord and FillWord routines from BLOCK.OBJ (Windows) or block.o (Linux).Declarations like the ones above are frequently used to access external routines written in assembly language. You can also place assembly-language routines directly in your Delphi source code; for more information, see Inline assembler code.Importing functions from librariesTo import routines from a dynamically loadable library (.so or .DLL), attach a directive of the form external stringConstant;to the end of a normal procedure or function header, where stringConstant is the name of the library file in single quotation s. For example, on Windowsfunction SomeFunction(S: string): string; external 'strlib.dll';imports a function called SomeFunction from strlib.dll.On Linux,function SomeFunction(S: string): string; external 'strlib.so';imports a function called SomeFunction from strlib.so.You can import a routine under a different name from the one it has in the library. If you do this, specify the original name in the external directive: external stringConstant1 name stringConstant2;where the first stringConstant gives the name of the library file and the second stringConstant is the routine's original name. On Windows: The following declaration imports a function from user32.dll (part of the Windows API).function MessageBox(HWnd: Integer; Text, Caption: PChar; Flags: Integer): Integer; stdcall; external 'user32.dll' name 'MessageBoxA'; The function's original name is MessageBoxA, but it is imported as MessageBox.Instead of a name, you can use a number to identify the routine you want to import:external stringConstant index integerConstant; where integerConstant is the routine's index in the export table.On Linux: The following declaration imports a standard system function from libc.so.6.function OpenFile(const PathName: PChar; Flags: Integer): Integer; cdecl; external 'libc.so.6' name 'open'; The function's original name is open, but it is imported as OpenFile.
In your importing declaration, be sure to match the exact spelling and case of the routine's name. Later, when you call the imported routine, the name is case-insensitive.For more information about libraries, see Libraries and packages.