定义带有 dllexport 和 dllimport 的内联 C 函数Defining Inline C Functions with dllexport and dllimport

Microsoft 专用Microsoft Specific

可以定义为将函数与 dllexport 特性内联。You can define as inline a function with the dllexport attribute. 在这种情况下,将始终实例化并导出该函数,无论程序中是否有模块引用该函数。In this case, the function is always instantiated and exported, whether or not any module in the program references the function. 假定该函数由另一个程序导入。The function is presumed to be imported by another program.

还可以定义为将声明的函数与 dllimport 特性内联。You can also define as inline a function declared with the dllimport attribute. 在这种情况下,函数可以展开(遵从 /Ob(内联)编译器选项规范),但决不实例化。In this case, the function can be expanded (subject to the /Ob (inline) compiler option specification) but never instantiated. 具体而言,如果采用内联导入函数的地址,则返回驻留在 DLL 中的函数地址。In particular, if the address of an inline imported function is taken, the address of the function residing in the DLL is returned. 此行为与采用非内联导入函数的地址相同。This behavior is the same as taking the address of a non-inline imported function.

内联函数中的静态本地数据和字符串在 DLL 和客户端之间保持的标识与它们在单一程序(即,没有 DLL 接口的可执行文件)中保持的一样。Static local data and strings in inline functions maintain the same identities between the DLL and client as they would in a single program (that is, an executable file without a DLL interface).

在提供导入的内联函数时谨慎操作。Exercise care when providing imported inline functions. 例如,如果更新 DLL,请不要假定该客户端将使用更改后的 DLL 版本。For example, if you update the DLL, don't assume that the client will use the changed version of the DLL. 若要确保加载 DLL 的适当版本,请重新生成 DLL 的客户端。To ensure that you are loading the proper version of the DLL, rebuild the DLL's client as well.

结束 Microsoft 专用END Microsoft Specific

另请参阅See Also

DLL 导入和导出函数DLL Import and Export Functions