WO2008110111A1 - Method and device to call dynamic library and dynamic library server and master program implementing device - Google Patents

Method and device to call dynamic library and dynamic library server and master program implementing device Download PDF

Info

Publication number
WO2008110111A1
WO2008110111A1 PCT/CN2008/070462 CN2008070462W WO2008110111A1 WO 2008110111 A1 WO2008110111 A1 WO 2008110111A1 CN 2008070462 W CN2008070462 W CN 2008070462W WO 2008110111 A1 WO2008110111 A1 WO 2008110111A1
Authority
WO
WIPO (PCT)
Prior art keywords
dynamic library
function
calling
main program
parameter
Prior art date
Application number
PCT/CN2008/070462
Other languages
French (fr)
Chinese (zh)
Inventor
Zhen Liang
Chunfeng Xie
Qingfeng Deng
Jing Wang
Weibao Luo
Xiaochuan Ke
Chenming Liu
Original Assignee
Huawei Technologies Co., Ltd.
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Huawei Technologies Co., Ltd. filed Critical Huawei Technologies Co., Ltd.
Publication of WO2008110111A1 publication Critical patent/WO2008110111A1/en

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/448Execution paradigms, e.g. implementations of programming paradigms
    • G06F9/4482Procedural
    • G06F9/4484Executing subprograms

Definitions

  • the present invention relates to the field of operating systems, and in particular, to a method, apparatus, and dynamic library server and main program execution apparatus for calling a dynamic library.
  • dynamic libraries are used to decompose a complex program into multiple different parts and provide them to different developers/factories.
  • the way to call a dynamic library is usually to put the dynamic library and the executable program on a computer, link when compiling the executable program, or load the specified file when the executable program runs, thereby implementing the executable program to call the dynamic library.
  • the inventors have found that the use of existing such dynamic libraries has also brought about some problems.
  • the first is that it may cause instability in the main program.
  • the dynamic library may be provided by a third party, it is difficult for the provider of the main program to control its quality. Serious defects such as memory leaks and pointer abnormal access may occur in the dynamic library, which will directly cause the main program to run abnormally. And once the main program is abnormal, the location of the problem is more difficult due to its complicated and large structure.
  • the purpose of the embodiments of the present invention is to provide a method for calling a dynamic library, which is used to accurately locate problems when an abnormality occurs in a dynamic library, and improve portability of the dynamic library.
  • Another object of embodiments of the present invention is to provide an apparatus for invoking a dynamic library for improving the accuracy of dynamic library problem location and portability of dynamic libraries.
  • a third object of the embodiments of the present invention is to provide a dynamic library server for implementing separation of a main program from a dynamic library function call.
  • a fourth object of the embodiments of the present invention is to provide a main program execution apparatus for realizing separation of a main program from a dynamic library function call.
  • An embodiment of the present invention provides a method for invoking a dynamic library, including: a dynamic library server receiving a request message sent by a main program and calling a function in a dynamic library, where the request message carries a parameter of a calling function;
  • the dynamic library server calls the function in the dynamic library according to the parameter, and returns the function execution result to the main program in the response message.
  • An embodiment of the present invention further provides an apparatus for calling a dynamic library, including:
  • a main program execution unit configured to send a request message for calling a function in a dynamic library, where the request message carries a parameter of the calling function
  • a dynamic library server configured to complete a function of the function in the dynamic library unit according to the parameter, and return an execution result of the function to the main program execution unit in the response message;
  • the dynamic library unit is configured to run the function according to the call request of the dynamic library server, and report the execution result to the dynamic library server.
  • An embodiment of the present invention further provides a dynamic library server, including:
  • a message processing module configured to receive a request message sent by the main program and carrying a parameter of the calling function, and send a call instruction according to the parameter; return the execution result to the main program through the response message; and call the module, according to the call
  • the function name and the parameter list in the instruction call the corresponding function, and the execution result of the function is reported to the message processing module.
  • An embodiment of the present invention further provides a main program execution apparatus, including: a request message sending module, configured to send, to the dynamic library server, a request message for calling a function in the dynamic library, where the request message carries a parameter of the calling function;
  • a receiving module configured to receive, by the dynamic database server, a function in the dynamic library according to the parameter, and return a response message carrying the result of the function execution to the main program.
  • the embodiment of the present invention executes the calling of the main program to the dynamic library through the dynamic library server, and uses the message mechanism to transfer parameters and data between the main program and the dynamic library server, thereby realizing that the error of the dynamic library only affects the dynamic library server. And the main program only obtains the error information in the response message, and does not affect the operation of the main program; on the other hand, since the main program and the dynamic library server are two independent individuals, the embodiment of the present invention allows the main program Compared with the dynamic library server based on different operating systems, it can be set on different computers, which improves the portability of dynamic libraries.
  • FIG. 1 is a flowchart of a method for calling a dynamic library in an embodiment of the present invention
  • FIG. 2 is a schematic diagram showing the relationship between a main program, a dynamic library server, and a dynamic library in an embodiment of the present invention
  • FIG. 3 is a structural diagram of an apparatus for calling a dynamic library in an embodiment of the present invention.
  • the embodiment of the present invention executes the calling of the main program to the dynamic library through the dynamic library server, and uses the message mechanism to transfer parameters and data between the main program and the dynamic library server, so that the error of the dynamic library only affects the dynamic library server.
  • the main program only obtains the error information in the response message, and does not affect the operation of the main program; on the other hand, since the main program and the dynamic library server are two independent individuals, the embodiment of the present invention allows the main program and The dynamic library server can be set on different computers based on different operating systems, which improves the portability of dynamic libraries. Moreover, when the main program is transplanted to other systems for execution, it is not necessary to transplant all the dynamic libraries. Reduced product migration time.
  • FIG. 1 it is a flowchart of a method for calling a dynamic library in an embodiment of the present invention.
  • the method may be divided into two parts: an initialization and a function call, and specifically includes the following steps:
  • Step 101 The dynamic library server loads the dynamic library.
  • the dynamic library server starts after the deployment is complete, and the step is executed at startup to get the dynamic library that it manages.
  • the statements used to load the dynamic library function are different.
  • the load library function is used, while on Unix systems, the dlopen function is used.
  • the dynamic library server obtains a handle to its own managed dynamic library.
  • the dynamic library server and the dynamic library loaded thereon can be set on the same device, because the load library function and the dlopen function can only be loaded based on the existing Windows and Unix operating system architecture.
  • a dynamic library of local computers can be set on the same device, because the load library function and the dlopen function can only be loaded based on the existing Windows and Unix operating system architecture.
  • Step 102 The main program requests to obtain a dynamic library list that the dynamic library server has successfully loaded.
  • the dynamic library server is capable of loading and managing multiple dynamic libraries.
  • the dynamic library server obtains the handles of all the dynamic libraries managed by itself, and at this time, the main program does not know which dynamic library is specifically loaded by the dynamic library server, so this step is used to obtain the successfully loaded. Dynamic library list.
  • Step 103 The dynamic library server returns a dynamic library list that has been successfully loaded to the main program.
  • the list contains the names of the loaded dynamic libraries, such as a.dll, b.dll and other dynamic libraries.
  • the relationship between the main program and the dynamic library server is many-to-many, that is, one main program can send a function call request to multiple dynamic library servers, and a dynamic library managed by a dynamic library server can be Called by the main program.
  • the relationship between the main program, the dynamic library server, and the dynamic library is shown in Figure 2.
  • the main program 1 can call the dynamic library servers 1, 2 and n, and the dynamic library managed by the dynamic library server 1 includes a.dll, and so on.
  • Step 104 The main program calls to call a function in the dynamic library.
  • a.dll is the dynamic library name
  • funcl is the function name.
  • Step 105 The main program sends a request message of the function call to the dynamic library server.
  • the request message carries a parameter of the calling function, and the parameter includes a dynamic library name, a function name, and a parameter list.
  • the main program refers to the dynamic library list, and sends a request message to the dynamic library server to which the a.dll dynamic library belongs, and the message carries the dynamic library name, the function name, and the parameter list.
  • the parameter list includes the type, length, and parameter values of each parameter.
  • the called function may have a sequential relationship in the dynamic library.
  • some dynamic libraries require an initialization (init) function to complete the function of allocating the buffer (buffer), initializing variables, and then calling the execute (exe) function to complete the function call.
  • the execution order is fixed, that is, the init function must be called before the exe function. If the function is not initialized and the exe is called directly, the execution of the function will be wrong.
  • a state is stored in the dynamic library. Calls of different functions will cause changes to the state, such as opening the file (open), writing (do), and closing the file (close).
  • embodiments of the present invention propose a concept of a session group, which sets a set of functions having successive calling relationships as a session, having the same session-id, and a group having the same session-id.
  • the function is loaded into the dynamic library list of the same dynamic library server, and is saved and managed by the dynamic library server.
  • the main program calls the set of functions having successive calling relationships, the main program sends a call request to the same dynamic library server according to the session_id of the function.
  • Step 106 After receiving the request message, the dynamic library server invokes the corresponding function execution according to the dynamic library name and the function name.
  • the statements of the dynamic library server calling function based on different operating systems are different.
  • the Windows and Unix operating systems are still taken as an example.
  • the dynamic library server obtains the result obtained in step 101 according to the name of the dynamic library a.dll.
  • the handle of the dynamic library and the function name to be called are input parameters, using the get proc address statement.
  • the dlsym statement is used.
  • the dynamic library server obtains the address of the function to be called. Based on this address, the dynamic library server executes the function using the parameters of the corresponding function in the request message as input parameters. When executed correctly, the dynamic library server obtains the execution result and output parameter list of the function.
  • Step 107 The dynamic library server returns a response message to the main program, where the message carries the execution result of the function.
  • the execution result includes a return value of the function execution and a list of output parameters.
  • the two can be set on the same computer or on different computers.
  • the two deliver messages over a network connection.
  • the data transmitted in the network connection uses the network byte order, and the endian used by different operating systems may be different from the network byte order.
  • the trick is to use the Windows byte order with the opposite network byte order. Assuming that the network byte order of the four-byte data is 01, 02, 03, 04, the Windows byte order is 04, 03, 02, 01.
  • the embodiment of the present invention uses a scheme in which the byte order of data is unified as a network endian when the main program is used as a transmitting end or a dynamic library server, that is, at the sending end of the message. Cast the endianness of the data into a network endian.
  • the operating system of the sending end uses Windows byte order, and the transmitted data has an explicit parameter type, such as a single-byte integer, a single-byte integer pointer, and a two-byte integer (short), Two-byte integer pointer (short*), four-byte integer (long), four-byte integer pointer (long*), double-precision floating-point (double), double-precision floating-point pointer (double*)
  • the operating system uses a specific conversion statement, such as for short and short * data, using htons statement to convert to network byte order, for long and long * data, using htonl statement conversion.
  • the byte order of the data is also restored by the ntohs and ntohl statements.
  • the conversion mode is implemented by the message mechanism.
  • the sender constructs the message, it determines whether the parameter or data carried in the message is of the foregoing type. If yes, it converts it into a network byte order through the corresponding statement, and the receiving end receives the message. After the message, the parameters or data are converted to the native byte order as needed.
  • the function of the struct MYSTRUCT * statement is to cast the parameter pStmct to the MYSTRUCT structure agreed by the dynamic library and the user. This conversion is done at the transmitting end and the endian is restored at the receiving end. Unsigned short usReal Value;
  • the function of the memcpy statement is to copy the contents of one buffer to another.
  • the first two parameters are the buffer address
  • the third parameter is the size of the copied content.
  • the usRealValue is short and has a size of 2 bytes, so the 2-byte data in the pStmct buffer is copied into usRealValue, which also converts the data type of the pStmct buffer to the data type of the usRealValue buffer.
  • the exception of the dynamic library does not affect the main program, ensuring the stability of the main program running. Since the dynamic library is loaded and executed by the dynamic library server, even if the dynamic inventory is executed incorrectly, the error is transferred to the dynamic library server, and the main program only receives the error response message, and the main program is not caused by the error. The operation is abnormal, and through the error response message, the main program can accurately know which dynamic library has an error, thereby realizing rapid fault location. Finally, since there may be multiple dynamic library servers in the embodiment of the present invention, one of the exceptions does not affect other dynamic database servers, which also ensures the stability of the service operation.
  • a device structure diagram for calling a dynamic library in an embodiment of the present invention specifically includes: a main program execution unit 31, configured to invoke a function in a dynamic library by sending a request message during a process of running a main program.
  • the request message carries a parameter of the calling function.
  • the dynamic library server 32 is configured to complete the calling of the function according to the parameter, and return a function execution result and an output parameter to the main program execution unit in the response message;
  • the dynamic library unit 33 is configured to run the function according to the request of the dynamic library server 32, and report the function execution result and the output parameter to the dynamic library server.
  • the main program execution unit 31 and the dynamic library server 32 may be disposed on different computer devices, and the dynamic library server 32 and the dynamic library 33 are disposed on the same computer device.
  • the dynamic library server 32 may specifically include:
  • the loading module 321 is configured to load the dynamic library managed by the dynamic library server to the local when the dynamic library server starts.
  • the load module loads the dynamic library when the dynamic library server starts, and the result of the loading is to obtain the handle of the dynamic library. And through the initialization process, the list of dynamically loaded dynamic libraries is sent to the main program.
  • the message processing module 322 is configured to receive a request message sent by the main program execution unit, and send a call instruction according to the dynamic library name, the function name, and the parameter list carried in the message; and return the execution result and the output parameter of the function through the response message.
  • the unit is executed by the main program.
  • the end program is converted by the main program module and the message processing module, and the parameters or data are transmitted using a unified network byte order.
  • the calling module 323 is configured to invoke a corresponding function according to the function name and the parameter list in the calling instruction, and report the execution result and the return parameter to the message processing module.
  • FIG. 3 only the internal structure of one dynamic library server is described, and the other is the same, and the correspondence between the main program execution unit, the dynamic library server, and the dynamic library is similar to that of FIG. 2.
  • the device for calling the dynamic library provided by the embodiment of the present invention performs the calling of the main program to the dynamic library through the dynamic library server, and the message system and the dynamic database server use the message mechanism to transmit parameters and data, thereby realizing the dynamic library.
  • the error only affects the dynamic library server, and the main program only gets the error information in the response message, which does not affect the running of the main program.
  • the device for calling the dynamic library provided by the embodiment of the present invention allows the main program and the dynamic library server to be set on different computers based on different operating systems, thereby improving the portability of the dynamic library.
  • a dynamic library server including:
  • a loading module configured to load a dynamic library managed by itself to a local device at startup, and return a list of dynamically loaded dynamic libraries to the main program;
  • a message processing module configured to receive a request message sent by the main program, and send a call instruction according to a parameter such as a dynamic library name, a function name, and a parameter list of the function carried in the message; returning the execution result of the function to the main program through the response message ;
  • the calling module is configured to invoke a corresponding function according to the function name and the parameter list in the calling instruction, and report the execution result and the output parameter to the message processing module.
  • the implementation of the dynamic library server adopts a modular manner, and the functions and structures are relatively simple, and can be easily compiled and executed under different operating systems, so that dynamic libraries under different operating systems are It can be loaded by the corresponding dynamic library server, which realizes the purpose that different dynamic libraries can be called by the main program under various system environments.
  • a main program execution apparatus including: a request message sending module, configured to send a request message to a dynamic library server to call a function in a dynamic library, where the request message carries a call The argument of the function;
  • a receiving module configured to receive, by the dynamic database server, a function in the dynamic library according to the parameter, and return a response message carrying the result of the function execution to the main program.
  • the main program execution device achieves the purpose of separating the main program from the dynamic library function by sending a request message to the dynamic library server and calling a function in the dynamic library.
  • the dynamic library has an error, Does not affect the operation of the main program.
  • the calling of the main program to the dynamic library is performed by the dynamic library server, and the parameter and the data are transmitted between the main program and the dynamic database server, thereby realizing the error of the dynamic library.
  • the main program only gets error information in the response message, does not affect the operation of the main program; on the other hand, since the main program and the dynamic library server are two independent individuals, the present invention
  • the dynamic library server provided by the embodiment allows the main program and the dynamic library server to be set on different computers based on different operating systems, thereby improving the portability of the dynamic library.

Abstract

A method and device to call the dynamic library, and the dynamic library server and the master program implementing device are disclosed, relating to the operation system, for resolving the problem of prone to making mistake when calling the dynamic library which is a part of master program, and the poor portability. The method to call the dynamic library includes: the dynamic library server receives the request information of calling the function in the dynamic library sent from the master program, the request information carries the parameter of the calling function; the dynamic library server returns the function executing result to the master program in the response information according to the function in the parameter call dynamic library. The method and device to call the dynamic library, and the dynamic library server are applicable to calling the dynamic library by the master program in any operation systems.

Description

调用动态库的方法、 装置及动态库服务器和主程序执行装置 技术领域  Method, device and dynamic library server and main program execution device for calling dynamic library
本发明涉及操作系统领域, 特别是调用动态库的方法、 装置及动态库服 务器和主程序执行装置。  The present invention relates to the field of operating systems, and in particular, to a method, apparatus, and dynamic library server and main program execution apparatus for calling a dynamic library.
背景技术 Background technique
动态库作为操作系统结构中必不可少的一部分, 用于将一个复杂的程序 分解为多个不同的部分, 提供给不同开发者 /厂家来完成。  As an indispensable part of the operating system structure, dynamic libraries are used to decompose a complex program into multiple different parts and provide them to different developers/factories.
目前, 调用动态库的方式通常为将动态库与可执行程序放在一台计算机 上, 在编译可执行程序时链接, 或在可执行程序运行时加载指定文件, 从而 实现可执行程序调用动态库中的一个或多个函数的功能。 不管是釆用链接的 方式还是釆用动态加载的方式, 动态库都是作为可执行程序的一部分, 被加 载到可执行程序的某段地址空间中, 并像调用本地函数一样地调用。  Currently, the way to call a dynamic library is usually to put the dynamic library and the executable program on a computer, link when compiling the executable program, or load the specified file when the executable program runs, thereby implementing the executable program to call the dynamic library. The function of one or more functions in . Regardless of whether the link is used or dynamically loaded, the dynamic library is loaded as part of the executable, loaded into an address space of the executable, and called as if it were a native function.
然而, 在实现本发明的过程中, 发明人发现釆用现有的这种动态库的调 用方式, 也带来了一些问题。 首先就是有可能会造成主程序的不稳定。 因为 动态库可能是第三方提供的, 主程序的提供者难以控制其质量, 在动态库中 可能会出现诸如内存泄露、 指针异常访问等严重缺陷, 将直接导致主程序的 运行异常。 并且一旦主程序出现异常, 由于其复杂而庞大的结构, 问题的定 位也较为困难。  However, in the process of implementing the present invention, the inventors have found that the use of existing such dynamic libraries has also brought about some problems. The first is that it may cause instability in the main program. Because the dynamic library may be provided by a third party, it is difficult for the provider of the main program to control its quality. Serious defects such as memory leaks and pointer abnormal access may occur in the dynamic library, which will directly cause the main program to run abnormally. And once the main program is abnormal, the location of the problem is more difficult due to its complicated and large structure.
其次, 现有的动态库也不能灵活配置。 基于某个操作系统的主程序, 其 只能调用该系统下的动态库, 如果想要调用其它操作系统下的动态库, 则需 要将该动态库重新编译并移植到本操作系统中。 有时甚至在与主程序基于不 同版本的操作系统或编译器的情况下, 都有可能需要重新编译动态库。 并且, 一个 Windows下的主程序,如果要将其移植到 Unix下, 其相应的动态库也要 同时被移植, 否则该程序将无法正常运行, 反之亦然。  Second, existing dynamic libraries cannot be flexibly configured. Based on the main program of an operating system, it can only call the dynamic library under the system. If you want to call the dynamic library under other operating systems, you need to recompile and port the dynamic library to the operating system. Sometimes it is possible to recompile a dynamic library even when the main program is based on a different version of the operating system or compiler. Also, if a main program under Windows is to be ported to Unix, its corresponding dynamic library must be migrated at the same time, otherwise the program will not work properly, and vice versa.
发明内容 有鉴于此, 本发明实施例的目的在于提供调用动态库的方法, 用于实现 动态库发生异常时的问题准确定位, 并提高动态库的可移植性。 Summary of the invention In view of this, the purpose of the embodiments of the present invention is to provide a method for calling a dynamic library, which is used to accurately locate problems when an abnormality occurs in a dynamic library, and improve portability of the dynamic library.
本发明实施例的另一目的在于提供调用动态库的装置, 用于提高动态库 问题定位准确性和动态库的可移植性。  Another object of embodiments of the present invention is to provide an apparatus for invoking a dynamic library for improving the accuracy of dynamic library problem location and portability of dynamic libraries.
本发明实施例的第三目的在于提供一种动态库服务器, 用于实现主程序 与动态库函数调用相分离。  A third object of the embodiments of the present invention is to provide a dynamic library server for implementing separation of a main program from a dynamic library function call.
本发明实施例的第四目的在于提供一种主程序执行装置, 用于实现主程 序与动态库函数调用相分离。  A fourth object of the embodiments of the present invention is to provide a main program execution apparatus for realizing separation of a main program from a dynamic library function call.
本发明的实施例提供了一种调用动态库的方法, 包括: 动态库服务器接 收主程序发送的调用动态库中函数的请求消息, 所述请求消息中携带有调用 函数的参量;  An embodiment of the present invention provides a method for invoking a dynamic library, including: a dynamic library server receiving a request message sent by a main program and calling a function in a dynamic library, where the request message carries a parameter of a calling function;
动态库服务器根据所述参量调用动态库中的函数, 并在响应消息中向主 程序返回函数执行结果。  The dynamic library server calls the function in the dynamic library according to the parameter, and returns the function execution result to the main program in the response message.
本发明的实施例还提供了一种调用动态库的装置, 包括:  An embodiment of the present invention further provides an apparatus for calling a dynamic library, including:
主程序执行单元, 用于发送调用动态库中函数的请求消息, 所述请求消 息中携带有调用函数的参量;  a main program execution unit, configured to send a request message for calling a function in a dynamic library, where the request message carries a parameter of the calling function;
动态库服务器, 用于根据所述参量完成动态库单元中函数的调用, 并在 响应消息中向所述主程序执行单元返回函数的执行结果;  a dynamic library server, configured to complete a function of the function in the dynamic library unit according to the parameter, and return an execution result of the function to the main program execution unit in the response message;
动态库单元, 用于根据所述动态库服务器的调用请求运行所述函数, 并 向动态库服务器上报执行结果。  The dynamic library unit is configured to run the function according to the call request of the dynamic library server, and report the execution result to the dynamic library server.
本发明的实施例还提供了一种动态库服务器, 包括:  An embodiment of the present invention further provides a dynamic library server, including:
消息处理模块, 用于接收主程序发送的携带有调用函数的参量的请求消 息, 并根据所述参量发送调用指令; 将执行结果通过响应消息返回给主程序; 调用模块, 用于根据所述调用指令中的函数名及参数列表调用对应的函 数, 并将函数的执行结果上报给所述消息处理模块。  a message processing module, configured to receive a request message sent by the main program and carrying a parameter of the calling function, and send a call instruction according to the parameter; return the execution result to the main program through the response message; and call the module, according to the call The function name and the parameter list in the instruction call the corresponding function, and the execution result of the function is reported to the message processing module.
本发明的实施例还提供了一种主程序执行装置, 包括: 请求消息发送模块, 用于向动态库服务器发送调用动态库中函数的请求 消息, 所述请求消息中携带有调用函数的参量; An embodiment of the present invention further provides a main program execution apparatus, including: a request message sending module, configured to send, to the dynamic library server, a request message for calling a function in the dynamic library, where the request message carries a parameter of the calling function;
接收模块, 用于接收所述动态库服务器根据所述参量调用动态库中的函 数, 并向主程序返回的携带函数执行结果的响应消息。  And a receiving module, configured to receive, by the dynamic database server, a function in the dynamic library according to the parameter, and return a response message carrying the result of the function execution to the main program.
本发明的实施例将主程序对动态库的调用通过动态库服务器来执行, 主 程序与动态库服务器间釆用消息机制传送参数和数据, 从而实现了动态库的 错误仅会影响到动态库服务器, 而主程序仅仅在响应消息中得到出错信息, 不会影响主程序的运行; 另一方面, 由于所述主程序与动态库服务器为两个 独立的个体, 所以本发明的实施例允许主程序与动态库服务器基于不同的操 作系统, 可以设置于不同的计算机上, 提高了动态库的可移植性。  The embodiment of the present invention executes the calling of the main program to the dynamic library through the dynamic library server, and uses the message mechanism to transfer parameters and data between the main program and the dynamic library server, thereby realizing that the error of the dynamic library only affects the dynamic library server. And the main program only obtains the error information in the response message, and does not affect the operation of the main program; on the other hand, since the main program and the dynamic library server are two independent individuals, the embodiment of the present invention allows the main program Compared with the dynamic library server based on different operating systems, it can be set on different computers, which improves the portability of dynamic libraries.
附图说明 DRAWINGS
图 1为本发明的实施例中调用动态库的方法流程图;  1 is a flowchart of a method for calling a dynamic library in an embodiment of the present invention;
图 2 为本发明的实施例中主程序、 动态库服务器及动态库三者间的关系 示意图;  2 is a schematic diagram showing the relationship between a main program, a dynamic library server, and a dynamic library in an embodiment of the present invention;
图 3为本发明的实施例中调用动态库的装置结构图。  FIG. 3 is a structural diagram of an apparatus for calling a dynamic library in an embodiment of the present invention.
具体实施方式 detailed description
本发明的实施例将主程序对动态库的调用通过动态库服务器来执行, 主 程序与动态库服务器间釆用消息机制传送参数和数据, 实现了动态库的错误 仅会影响到动态库服务器, 而主程序仅仅在响应消息中得到出错信息, 不会 影响主程序的运行; 另一方面, 由于所述主程序与动态库服务器为两个独立 的个体, 所以本发明的实施例允许主程序与动态库服务器基于不同的操作系 统, 可以设置于不同的计算机上, 提高了动态库的可移植性; 并且, 将主程 序移植到其它系统上执行时, 不必将动态库全部也移植过来, 从而也减少了 产品移植的时间。  The embodiment of the present invention executes the calling of the main program to the dynamic library through the dynamic library server, and uses the message mechanism to transfer parameters and data between the main program and the dynamic library server, so that the error of the dynamic library only affects the dynamic library server. The main program only obtains the error information in the response message, and does not affect the operation of the main program; on the other hand, since the main program and the dynamic library server are two independent individuals, the embodiment of the present invention allows the main program and The dynamic library server can be set on different computers based on different operating systems, which improves the portability of dynamic libraries. Moreover, when the main program is transplanted to other systems for execution, it is not necessary to transplant all the dynamic libraries. Reduced product migration time.
为使本发明的目的、 技术方案和优点更加清楚, 下面结合附图对本发明 作进一步的详细描述。 如图 1 所示, 为本发明的实施例中调用动态库的方法流程图, 该方法可 分为初始化和函数调用两个部分, 具体包括以下步骤: In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention will be further described in detail with reference to the accompanying drawings. As shown in FIG. 1 , it is a flowchart of a method for calling a dynamic library in an embodiment of the present invention. The method may be divided into two parts: an initialization and a function call, and specifically includes the following steps:
步骤 101、动态库服务器加载动态库。 动态库服务器在部署完成后便会启 动, 启动时即执行该步骤, 以获取自身管理的动态库。  Step 101: The dynamic library server loads the dynamic library. The dynamic library server starts after the deployment is complete, and the step is executed at startup to get the dynamic library that it manages.
在目前通用的操作系统 Windows和 Unix中,用于完成加载动态库功能的 语句有所不同, 在 Windows系统中, 使用 load library函数, 而在 Unix系统 中, 则是使用 dlopen函数。 通过执行加载语句, 动态库服务器获得了自身管 理的动态库的句柄。  In the current common operating systems Windows and Unix, the statements used to load the dynamic library function are different. In Windows systems, the load library function is used, while on Unix systems, the dlopen function is used. By executing the load statement, the dynamic library server obtains a handle to its own managed dynamic library.
在本发明的实施例中, 动态库服务器与其加载的动态库可以设置于同一 台设备上, 这是因为基于现有的 Windows和 Unix操作系统架构, 所述 load library函数和 dlopen函数都只能加载本地计算机的动态库。  In the embodiment of the present invention, the dynamic library server and the dynamic library loaded thereon can be set on the same device, because the load library function and the dlopen function can only be loaded based on the existing Windows and Unix operating system architecture. A dynamic library of local computers.
步骤 102、 主程序请求获得动态库服务器已加载成功的动态库列表。  Step 102: The main program requests to obtain a dynamic library list that the dynamic library server has successfully loaded.
在本发明的实施例中, 动态库服务器能够加载并管理多个动态库。 通过 执行步骤 101 , 动态库服务器获取了自身管理的所有动态库的句柄, 而此时主 程序还不知道动态库服务器具体加载了哪个 /些动态库, 因此要通过本步骤来 获取已加载成功的动态库列表。  In an embodiment of the invention, the dynamic library server is capable of loading and managing multiple dynamic libraries. By performing step 101, the dynamic library server obtains the handles of all the dynamic libraries managed by itself, and at this time, the main program does not know which dynamic library is specifically loaded by the dynamic library server, so this step is used to obtain the successfully loaded. Dynamic library list.
步骤 103、动态库服务器向主程序返回已加载成功的动态库列表。 该列表 中包含了加载的动态库的名称, 例如 a.dll、 b.dll等动态库。  Step 103: The dynamic library server returns a dynamic library list that has been successfully loaded to the main program. The list contains the names of the loaded dynamic libraries, such as a.dll, b.dll and other dynamic libraries.
在本发明的实施例中, 主程序与动态库服务器的关系为多对多, 即一个 主程序可以向多个动态库服务器发送函数调用请求, 而一个动态库服务器所 管理的动态库可以被多个主程序所调用。 主程序、 动态库服务器及动态库三 者间的关系如图 2所示。 其中, 主程序 1可以调用动态库服务器 1、 2和 n, 动态库服务器 1管理的动态库包括 a.dll, 依此类推。  In the embodiment of the present invention, the relationship between the main program and the dynamic library server is many-to-many, that is, one main program can send a function call request to multiple dynamic library servers, and a dynamic library managed by a dynamic library server can be Called by the main program. The relationship between the main program, the dynamic library server, and the dynamic library is shown in Figure 2. The main program 1 can call the dynamic library servers 1, 2 and n, and the dynamic library managed by the dynamic library server 1 includes a.dll, and so on.
通过以上步骤, 就完成了对于动态库服务器的初始化, 主程序也获得了 各动态库服务器加载成功的动态库列表, 下面的流程则是执行具体的函数调 用。 步骤 104、主程序要求调用动态库中的函数。假设此处要求调用的是 a.dll 动态库中的 funcl函数, a.dll为动态库名, funcl为函数名。 Through the above steps, the initialization of the dynamic library server is completed, and the main program also obtains a list of dynamic libraries that each dynamic library server loads successfully. The following process is to execute a specific function call. Step 104: The main program calls to call a function in the dynamic library. Suppose that the func function in the a.dll dynamic library is called here, a.dll is the dynamic library name, and funcl is the function name.
步骤 105、主程序向动态库服务器发送函数调用的请求消息。请求消息中 携带有调用函数的参量, 所述参量包括动态库名、 函数名及参数列表。  Step 105: The main program sends a request message of the function call to the dynamic library server. The request message carries a parameter of the calling function, and the parameter includes a dynamic library name, a function name, and a parameter list.
主程序查阅动态库列表, 向所述 a.dll动态库所隶属的动态库服务器发送 请求消息, 消息中携带动态库名、 函数名及参数列表。 参数列表中包括各参 数的类型、 长度及参数值等。  The main program refers to the dynamic library list, and sends a request message to the dynamic library server to which the a.dll dynamic library belongs, and the message carries the dynamic library name, the function name, and the parameter list. The parameter list includes the type, length, and parameter values of each parameter.
在实际的应用过程中, 主程序向动态库服务器发送函数调用请求时, 所 调用的函数在动态库中可能是有先后关系的。 比如一些动态库要求先要调用 一个初始化(init ) 函数, 完成分配緩存(buffer ), 初始化变量等功能, 然后 再调用执行(exe ) 函数, 完成该函数的调用。 对于这两个函数而言, 其执行 顺序是固定的, 即 init函数一定在 exe函数前被调用, 如果该函数未被初始化 而直接调用 exe, 则会导致该函数的执行出错。 另一种情况是动态库中保存有 某种状态, 不同函数的调用会导致该状态的变更, 例如打开文件(open )、 写 入(do )和关闭文件(close )这三个函数, 执行 open打开了一个文件, 执行 do向该文件中写入, 执行 close关闭该文件, 该执行顺序一旦出错, 必然会导 致对该文件操作的失败。 正确的执行顺序是由动态库的使用者来保证的, 该 用者无法决定的问题, 当具有先后执行顺序的各函数分配给了不同的动态库 服务器, 例如 init函数和 exe函数被分配给了不同动态库服务器, 即使使用者 按照正确的顺序调用这两个函数, 这两个调用请求被发送给了不同的动态库 服务器, 执行 init函数的动态库服务器获得了该函数的句柄, 然而调用 exe函 数的另一动态库服务器由于没有该函数句柄, 导致无法正确执行该函数。 对 于文件操作的情况也类似, 如果 open、 do和 close这三个函数由不同的动态 库服务器管理, 而这些动态库服务器可能设置于不同的物理设备上, 那么即 使使用者按照正确的顺序去调用这三个函数, 这些函数也无法针对同一文件 进行操作。 In the actual application process, when the main program sends a function call request to the dynamic library server, the called function may have a sequential relationship in the dynamic library. For example, some dynamic libraries require an initialization (init) function to complete the function of allocating the buffer (buffer), initializing variables, and then calling the execute (exe) function to complete the function call. For these two functions, the execution order is fixed, that is, the init function must be called before the exe function. If the function is not initialized and the exe is called directly, the execution of the function will be wrong. Another situation is that a state is stored in the dynamic library. Calls of different functions will cause changes to the state, such as opening the file (open), writing (do), and closing the file (close). Open a file, execute do to write to the file, and execute close to close the file. If the execution order is wrong, it will inevitably lead to failure of the file operation. The correct execution order is guaranteed by the user of the dynamic library. The user cannot decide the problem. When the functions with sequential execution order are assigned to different dynamic library servers, for example, the init function and the exe function are assigned. Different dynamic library servers, even if the user calls these two functions in the correct order, the two call requests are sent to different dynamic library servers. The dynamic library server executing the init function obtains the handle of the function, but calls exe Another dynamic library server for the function cannot execute the function correctly because there is no such function handle. The same is true for file operations. If the three functions open, do, and close are managed by different dynamic library servers, and these dynamic library servers may be set on different physical devices, then even if the users are called in the correct order. These three functions, these functions also cannot target the same file Take action.
为了解决前述问题, 本发明的实施例提出了会话组(session )的概念, 将 具有先后调用关系的一组函数设置为一个 session, 具有相同的 session— id, 而 具有相同 session— id的一组函数被加载到同一动态库服务器的动态库列表中, 由所述动态库服务器进行保存管理。 当主程序调用所述具有先后调用关系的 一组函数时,所述主程序会根据所述函数的 session— id向同一动态库服务器发 出调用请求。  In order to solve the foregoing problems, embodiments of the present invention propose a concept of a session group, which sets a set of functions having successive calling relationships as a session, having the same session-id, and a group having the same session-id. The function is loaded into the dynamic library list of the same dynamic library server, and is saved and managed by the dynamic library server. When the main program calls the set of functions having successive calling relationships, the main program sends a call request to the same dynamic library server according to the session_id of the function.
步骤 106、动态库服务器接收到请求消息后,根据动态库名及函数名调用 相应函数执行。  Step 106: After receiving the request message, the dynamic library server invokes the corresponding function execution according to the dynamic library name and the function name.
基于不同操作系统的动态库服务器调用函数的语句有所不同, 依然以 Windows和 Unix操作系统为例,在 Windows系统中,动态库服务器根据动态 库的名称 a.dll, 以步骤 101中获得的该动态库的句柄及要调用的函数名 fund 为输入参数, 使用 get proc address语句, 在 Unix系统中, 则是使用 dlsym语 句, 执行该语句后, 动态库服务器获得了欲调用函数的地址。 根据该地址, 动态库服务器使用请求消息中对应该函数的参数作为输入参数, 执行该函数。 在执行正确的情况下, 动态库服务器获得该函数的执行结果和输出参数列表。  The statements of the dynamic library server calling function based on different operating systems are different. The Windows and Unix operating systems are still taken as an example. In the Windows system, the dynamic library server obtains the result obtained in step 101 according to the name of the dynamic library a.dll. The handle of the dynamic library and the function name to be called are input parameters, using the get proc address statement. On Unix systems, the dlsym statement is used. After executing the statement, the dynamic library server obtains the address of the function to be called. Based on this address, the dynamic library server executes the function using the parameters of the corresponding function in the request message as input parameters. When executed correctly, the dynamic library server obtains the execution result and output parameter list of the function.
步骤 107、动态库服务器向主程序返回响应消息, 消息中携带函数的执行 结果。 该执行结果包括函数执行的返回值及输出参数列表。  Step 107: The dynamic library server returns a response message to the main program, where the message carries the execution result of the function. The execution result includes a return value of the function execution and a list of output parameters.
在本发明的实施例中, 主程序和动态库服务器之间由于是釆用消息机制 来传送数据的, 因此二者可以设置于同一台计算机上, 也可以设置在不同的 计算机上。 当设置在不同计算机上时, 二者通过网络连接来传递消息。 网络 连接中传送的数据釆用的是网络字节序, 而不同操作系统所使用的字节序则 可能与网络字节序不同。 以 Windows操作系统为例, 其釆用的就是网络字节 序相反的 Windows字节序。假设四字节数据的网络字节序为 01 , 02, 03 , 04, 则其 Windows字节序为 04 , 03 , 02, 01。 非网络字节序的数据在网络中传输 时, 会导致传输出错; 同样, 当主程序基于的操作系统与动态库服务器基于 的操作系统使用不同字节序时, 也会导致对端接收到的数据出错。 为解决以上问题, 本发明的实施例釆用了将数据的字节序在主程序作为 发送端或动态库服务器作为发送端时, 统一为网络字节序的方案, 即在消息 的发送端, 把数据的字节序强制转换为网络字节序。 In the embodiment of the present invention, since the main program and the dynamic library server transmit data by using a message mechanism, the two can be set on the same computer or on different computers. When set up on different computers, the two deliver messages over a network connection. The data transmitted in the network connection uses the network byte order, and the endian used by different operating systems may be different from the network byte order. Take the Windows operating system as an example. The trick is to use the Windows byte order with the opposite network byte order. Assuming that the network byte order of the four-byte data is 01, 02, 03, 04, the Windows byte order is 04, 03, 02, 01. When non-network byte order data is transmitted in the network, it will cause transmission errors; similarly, when the main program is based on the operating system and the dynamic library server is based on When the operating system uses different endianness, it will also cause errors in the data received by the peer. In order to solve the above problem, the embodiment of the present invention uses a scheme in which the byte order of data is unified as a network endian when the main program is used as a transmitting end or a dynamic library server, that is, at the sending end of the message. Cast the endianness of the data into a network endian.
具体包括: 如果发送端的操作系统釆用的是 Windows字节序, 并且传输 的数据具有明确的参数类型, 如单字节整型、 单字节整型指针、 二字节整型 ( short ), 二字节整型指针(short* )、 四字节整型 (long )、 四字节整型指针 ( long* ), 双精度浮点型 (double ), 双精度浮点型指针( double* ), 则操作系 统使用特定的转换语句, 例如针对 short和 short*数据, 使用 htons语句转换 为网络字节序, 针对 long和 long*数据, 则使用 htonl语句转换。 在将网络字 节序数据传送到对端后, 如果对端支持 Windows 字节序, 则还要通过 ntohs 和 ntohl语句将数据的字节序恢复。 这种转换方式通过消息机制来实现, 发送 端在构造消息时, 判断消息中携带的参数或数据是否为前述类型, 如果是, 则通过相应语句将其转换为网络字节序, 接收端接收到该消息后, 再根据需 要将参数或数据转换为本机字节序。  Specifically, it includes: If the operating system of the sending end uses Windows byte order, and the transmitted data has an explicit parameter type, such as a single-byte integer, a single-byte integer pointer, and a two-byte integer (short), Two-byte integer pointer (short*), four-byte integer (long), four-byte integer pointer (long*), double-precision floating-point (double), double-precision floating-point pointer (double*) , the operating system uses a specific conversion statement, such as for short and short * data, using htons statement to convert to network byte order, for long and long * data, using htonl statement conversion. After the network byte order data is transferred to the peer, if the peer supports Windows byte order, the byte order of the data is also restored by the ntohs and ntohl statements. The conversion mode is implemented by the message mechanism. When the sender constructs the message, it determines whether the parameter or data carried in the message is of the foregoing type. If yes, it converts it into a network byte order through the corresponding statement, and the receiving end receives the message. After the message, the parameters or data are converted to the native byte order as needed.
然而在实际应用中, 还存在另一种情形, 就是传输的数据没有明确的参 数类型, 动态库与动态库的使用者使用了非通用的字节序。 此时, 则要由动 态库的使用者和动态库约定字节序的实现。 例如: However, in practical applications, there is another case where the transmitted data has no explicit parameter type, and the dynamic library and the dynamic library user use a non-universal endian. At this point, the user of the dynamic library and the dynamic library agree on the implementation of the endian. E.g:
Figure imgf000009_0001
struct MYSTRUCT *pstr = (struct MYSTRUCT *)pStruct;
Figure imgf000009_0001
Struct MYSTRUCT *pstr = (struct MYSTRUCT *)pStruct;
struct MYSTRUCT *语句的功能是将参数 pStmct强制转换为动态库与使 用者约定的 MYSTRUCT 结构, 这一转换在发送端完成, 在接收端将字节序 恢复。 unsigned short usReal Value; The function of the struct MYSTRUCT * statement is to cast the parameter pStmct to the MYSTRUCT structure agreed by the dynamic library and the user. This conversion is done at the transmitting end and the endian is restored at the receiving end. Unsigned short usReal Value;
memcpy(&usRealValue,pStmct,sizeof(usRealValue))  Memcpy(&usRealValue,pStmct,sizeof(usRealValue))
memcpy语句的功能是将一个緩存器的内容复制到另一緩存器中,其三个 输入参数中, 前两个参数是緩存器地址, 第三个参数为复制内容的大小。 usRealValue为 short型, 大小为 2字节, 因此将 pStmct緩存器中的 2字节数 据复制到 usRealValue 中, 从而也将 pStmct緩存器的数据类型也转换为了 usRealValue緩存器的数据类型。 The function of the memcpy statement is to copy the contents of one buffer to another. Among the three input parameters, the first two parameters are the buffer address, and the third parameter is the size of the copied content. The usRealValue is short and has a size of 2 bytes, so the 2-byte data in the pStmct buffer is copied into usRealValue, which also converts the data type of the pStmct buffer to the data type of the usRealValue buffer.
通过以上方法, 就实现了对网络字节序与非网络字节序的转换, 在一定 程度上保证了主程序与动态库服务器间网络数据传输的准确性。  Through the above method, the conversion of the network byte order and the non-network byte order is realized, and the accuracy of the network data transmission between the main program and the dynamic library server is ensured to some extent.
釆用如图 1 所示的调用动态库的方法, 实现了不论动态库处于哪种系统 环境下, 都可以被主程序所调用, 使得系统整体架构更为灵活。 如果出于市 场需求的考虑, 要将主程序移植到不同的操作系统下运行, 利用图 1 所示的 方法, 就避免了第三方的动态库没有移植而导致的程序无法运行的问题, 从 而降低了不同厂家产品的移植风险, 并且由于一些动态库没有移植, 也节省 了产品的移植时间。 而由于存在着兼容性的问题, 有些技术是很难被移植到 别的操作系统下的,比如 Windows下的 Com技术,此时可把它们做成动态库, 仍然放在 Windows系统下运行, 这样就又降低了产品移植的技术风险。  Using the method of calling the dynamic library as shown in Figure 1, it can be called by the main program regardless of the system environment of the dynamic library, making the overall architecture of the system more flexible. If the main program is ported to a different operating system for market demand, using the method shown in Figure 1, it avoids the problem that the third-party dynamic library is not transplanted and the program cannot run, thus reducing The migration risks of different manufacturers' products, and because some dynamic libraries are not transplanted, also save the product migration time. Because of the compatibility problem, some technologies are difficult to be ported to other operating systems, such as Com technology under Windows. At this time, they can be made into dynamic libraries and still run under Windows system. This reduces the technical risk of product migration.
另外, 釆用图 1 所示的方法, 动态库的异常不会影响到主程序, 保证了 主程序运行的稳定性。 由于动态库是被动态库服务器加载与执行的, 即使动 态库存在执行错误, 该错误被转移到了动态库服务器上, 而主程序仅仅会收 到出错的响应消息, 不会因为该错误导致主程序运行异常, 并且通过该出错 的响应消息, 主程序能够准确获知哪个动态库发生错误, 从而实现了故障快 速定位。 最后, 由于本发明的实施例中动态库服务器可以有多个, 其中的一个发 生异常不会影响到其它动态库服务器, 这也从另一方面保证了业务运行的稳 定性。 In addition, using the method shown in Figure 1, the exception of the dynamic library does not affect the main program, ensuring the stability of the main program running. Since the dynamic library is loaded and executed by the dynamic library server, even if the dynamic inventory is executed incorrectly, the error is transferred to the dynamic library server, and the main program only receives the error response message, and the main program is not caused by the error. The operation is abnormal, and through the error response message, the main program can accurately know which dynamic library has an error, thereby realizing rapid fault location. Finally, since there may be multiple dynamic library servers in the embodiment of the present invention, one of the exceptions does not affect other dynamic database servers, which also ensures the stability of the service operation.
如图 3所示, 为本发明的实施例中调用动态库的装置结构图, 具体包括: 主程序执行单元 31 , 用于在运行主程序的过程中, 通过发送请求消息调 用动态库中的函数, 所述请求消息中携带有调用函数的参量。  As shown in FIG. 3, a device structure diagram for calling a dynamic library in an embodiment of the present invention specifically includes: a main program execution unit 31, configured to invoke a function in a dynamic library by sending a request message during a process of running a main program. The request message carries a parameter of the calling function.
动态库服务器 32 , 用于根据所述参量完成所述函数的调用, 并在响应消 息中向所述主程序执行单元返回函数执行结果及输出参数;  The dynamic library server 32 is configured to complete the calling of the function according to the parameter, and return a function execution result and an output parameter to the main program execution unit in the response message;
动态库单元 33 , 用于根据动态库服务器 32的请求运行所述函数, 并向动 态库服务器上报函数执行结果及输出参数。  The dynamic library unit 33 is configured to run the function according to the request of the dynamic library server 32, and report the function execution result and the output parameter to the dynamic library server.
所述主程序执行单元 31与动态库服务器 32可以设置于不同的计算机设 备上, 而动态库服务器 32与动态库 33则设置于同一台计算机设备上。  The main program execution unit 31 and the dynamic library server 32 may be disposed on different computer devices, and the dynamic library server 32 and the dynamic library 33 are disposed on the same computer device.
其中, 所述动态库服务器 32又可以具体包括:  The dynamic library server 32 may specifically include:
加载模块 321 ,用于在所述动态库服务器启动时将自身管理的动态库加载 到本地。 加载模块在动态库服务器启动时加载动态库, 加载的结果是获得动 态库的句柄。 并通过初始化流程, 将加载成功的动态库的列表发送给主程序。  The loading module 321 is configured to load the dynamic library managed by the dynamic library server to the local when the dynamic library server starts. The load module loads the dynamic library when the dynamic library server starts, and the result of the loading is to obtain the handle of the dynamic library. And through the initialization process, the list of dynamically loaded dynamic libraries is sent to the main program.
消息处理模块 322 , 用于接收所述主程序执行单元发送的请求消息, 并根 据消息中携带的动态库名、 函数名及参数列表发送调用指令; 将函数的执行 结果及输出参数通过响应消息返回给所述主程序执行单元。 在消息创建的过 程中, 由主程序模块和消息处理模块完成字节序的转换, 使用统一的网络字 节序来传输参数或数据。  The message processing module 322 is configured to receive a request message sent by the main program execution unit, and send a call instruction according to the dynamic library name, the function name, and the parameter list carried in the message; and return the execution result and the output parameter of the function through the response message. The unit is executed by the main program. In the process of message creation, the end program is converted by the main program module and the message processing module, and the parameters or data are transmitted using a unified network byte order.
调用模块 323 ,用于根据所述调用指令中的函数名及参数列表调用相应的 函数, 并将执行结果及返回参数上报给所述消息处理模块。  The calling module 323 is configured to invoke a corresponding function according to the function name and the parameter list in the calling instruction, and report the execution result and the return parameter to the message processing module.
为简便起见, 在图 3 中, 仅仅对一个动态库服务器描述了其内部结构, 其它与此相同, 并且主程序执行单元、 动态库服务器及动态库三者之间的对 应关系与图 2相似。 本发明实施例所提供的调用动态库的装置, 将主程序对动态库的调用通 过动态库服务器来执行, 主程序与动态库服务器间釆用消息机制传送参数和 数据, 从而实现了动态库的错误仅会影响到动态库服务器, 而主程序仅仅在 响应消息中得到出错信息, 不会影响主程序的运行; 另一方面, 由于所述主 程序与动态库服务器为两个独立的个体, 所以本发明实施例所提供的调用动 态库的装置允许主程序与动态库服务器基于不同的操作系统, 可以设置于不 同的计算机上, 提高了动态库的可移植性。 For the sake of simplicity, in FIG. 3, only the internal structure of one dynamic library server is described, and the other is the same, and the correspondence between the main program execution unit, the dynamic library server, and the dynamic library is similar to that of FIG. 2. The device for calling the dynamic library provided by the embodiment of the present invention performs the calling of the main program to the dynamic library through the dynamic library server, and the message system and the dynamic database server use the message mechanism to transmit parameters and data, thereby realizing the dynamic library. The error only affects the dynamic library server, and the main program only gets the error information in the response message, which does not affect the running of the main program. On the other hand, since the main program and the dynamic library server are two independent individuals, The device for calling the dynamic library provided by the embodiment of the present invention allows the main program and the dynamic library server to be set on different computers based on different operating systems, thereby improving the portability of the dynamic library.
在本发明的另一实施例中, 提供了一种动态库服务器, 包括:  In another embodiment of the present invention, a dynamic library server is provided, including:
加载模块, 用于在启动时将自身管理的动态库加载到本地, 并向主程序 返回加载成功的动态库的列表;  a loading module, configured to load a dynamic library managed by itself to a local device at startup, and return a list of dynamically loaded dynamic libraries to the main program;
消息处理模块, 用于接收主程序发送的请求消息, 并根据消息中携带的 动态库名、 函数名及该函数的参数列表等参量发送调用指令; 将函数的执行 结果通过响应消息返回给主程序;  a message processing module, configured to receive a request message sent by the main program, and send a call instruction according to a parameter such as a dynamic library name, a function name, and a parameter list of the function carried in the message; returning the execution result of the function to the main program through the response message ;
调用模块, 用于根据所述调用指令中的函数名及参数列表调用对应的函 数, 并将执行结果及输出参数上报给所述消息处理模块。  The calling module is configured to invoke a corresponding function according to the function name and the parameter list in the calling instruction, and report the execution result and the output parameter to the message processing module.
所述动态库服务器的实现釆用了模块化的方式, 功能与结构都相对简单, 可以较为容易地做到在不同的操作系统下都可以编译执行, 这样就使得不同 操作系统下的动态库都可以有相应的动态库服务器将其加载, 实现了不同动 态库处于多种系统环境下也能被主程序调用的目的。  The implementation of the dynamic library server adopts a modular manner, and the functions and structures are relatively simple, and can be easily compiled and executed under different operating systems, so that dynamic libraries under different operating systems are It can be loaded by the corresponding dynamic library server, which realizes the purpose that different dynamic libraries can be called by the main program under various system environments.
在本发明的再一实施例中, 提供了一种主程序执行装置, 包括: 请求消息发送模块, 用于向动态库服务器发送调用动态库中函数的请求 消息, 所述请求消息中携带有调用函数的参量;  In a further embodiment of the present invention, a main program execution apparatus is provided, including: a request message sending module, configured to send a request message to a dynamic library server to call a function in a dynamic library, where the request message carries a call The argument of the function;
接收模块, 用于接收所述动态库服务器根据所述参量调用动态库中的函 数, 并向主程序返回的携带函数执行结果的响应消息。  And a receiving module, configured to receive, by the dynamic database server, a function in the dynamic library according to the parameter, and return a response message carrying the result of the function execution to the main program.
所述主程序执行装置通过向动态库服务器发送请求消息, 调用动态库中 的函数, 实现了主程序与动态库函数相分离的目的, 当动态库出现错误时, 不会影响主程序的运行。 The main program execution device achieves the purpose of separating the main program from the dynamic library function by sending a request message to the dynamic library server and calling a function in the dynamic library. When the dynamic library has an error, Does not affect the operation of the main program.
本发明实施例所提供的动态库服务器, 将主程序对动态库的调用通过动 态库服务器来执行, 主程序与动态库服务器间釆用消息机制传送参数和数据, 从而实现了动态库的错误仅会影响到动态库服务器, 而主程序仅仅在响应消 息中得到出错信息, 不会影响主程序的运行; 另一方面, 由于所述主程序与 动态库服务器为两个独立的个体, 所以本发明实施例所提供的动态库服务器 允许主程序与动态库服务器基于不同的操作系统, 可以设置于不同的计算机 上, 提高了动态库的可移植性。  In the dynamic library server provided by the embodiment of the present invention, the calling of the main program to the dynamic library is performed by the dynamic library server, and the parameter and the data are transmitted between the main program and the dynamic database server, thereby realizing the error of the dynamic library. Will affect the dynamic library server, and the main program only gets error information in the response message, does not affect the operation of the main program; on the other hand, since the main program and the dynamic library server are two independent individuals, the present invention The dynamic library server provided by the embodiment allows the main program and the dynamic library server to be set on different computers based on different operating systems, thereby improving the portability of the dynamic library.
以上所述, 仅为本发明较佳的具体实施方式, 但本发明的保护范围并不 局限于此, 任何熟悉本技术领域的技术人员在本发明揭露的技术范围和不脱 离本发明的技术思想范围内, 可轻易想到的变化或替换, 都应涵盖在本发明 的保护范围之内。 因此, 本发明的保护范围应该以权利要求的保护范围为准。  The above is only a preferred embodiment of the present invention, but the scope of the present invention is not limited thereto, and any technical person skilled in the art can disclose the technical scope of the present invention and the technical idea of the present invention. Variations or substitutions that are conceivable within the scope of the invention are intended to be included within the scope of the invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.

Claims

权 利 要求 书 Claim
1、 一种调用动态库的方法, 其特征在于, 包括:  A method for calling a dynamic library, comprising:
动态库服务器接收主程序发送的调用动态库中函数的请求消息, 所述请求 消息中携带有调用函数的参量;  The dynamic library server receives a request message sent by the main program and calls a function in the dynamic library, where the request message carries a parameter of the calling function;
动态库服务器根据所述参量调用动态库中的函数, 并在响应消息中向主程 序返回函数执行结果。  The dynamic library server calls the function in the dynamic library according to the parameter, and returns the function execution result to the main program in the response message.
2、 根据权利要求 1所述的调用动态库的方法, 其特征在于, 该方法还进一 步包括以下步骤: 动态库服务器在启动时加载所述动态库服务器自身管理的动 态库, 并根据主程序的请求, 向主程序返回加载成功的动态库列表。  2. The method of calling a dynamic library according to claim 1, further comprising the steps of: loading, by the dynamic library server, a dynamic library managed by the dynamic library server itself at startup, and according to the main program Request, return to the main program a list of dynamically loaded libraries.
3、 根据权利要求 2所述的调用动态库的方法, 其特征在于, 所述动态库服 务器在加载自身管理的动态库时, 将多个具有先后调用关系的函数调用设置于 同一会话组中, 对于隶属于同一会话组的多个调用, 只发送给同一动态库服务 器。  The method for calling a dynamic library according to claim 2, wherein the dynamic library server sets a plurality of function calls having successive calling relationships in the same session group when loading the dynamic library managed by the dynamic library server. Multiple calls belonging to the same session group are only sent to the same dynamic library server.
4、 根据权利要求 1所述的调用动态库的方法, 其特征在于, 所述携带的参 量包括动态库名、 函数名及该函数的参数列表。  4. The method of calling a dynamic library according to claim 1, wherein the carried parameter comprises a dynamic library name, a function name, and a parameter list of the function.
5、根据权利要求 1至 4中任意一项所述的调用动态库的方法,其特征在于, 所述向主程序返回函数执行结果进一步包括:  The method of calling a dynamic library according to any one of claims 1 to 4, wherein the returning the function execution result to the main program further comprises:
动态库服务器将函数执行的输出参数通过所述响应消息返回给主程序。 The dynamic library server returns the output parameters of the function execution to the main program through the response message.
6、 根据权利要求 5所述的调用动态库的方法, 其特征在于, 在所述请求消 息及所述响应消息中携带的函数返回值及参数使用网络字节序, 当所述主程序 或动态库服务器使用非网络字节序时, 则将所述函数返回值及参数转换为网络 字节序。 The method for calling a dynamic library according to claim 5, wherein a function return value and a parameter carried in the request message and the response message use a network byte order, when the main program or the dynamic When the library server uses non-network byte order, the function return value and parameters are converted to network byte order.
7、 根据权利要求 6所述的调用动态库的方法, 其特征在于, 所述将所述函 数返回值及参数转换为网络字节序包括以下步骤:  7. The method of calling a dynamic library according to claim 6, wherein the converting the function return value and the parameter into a network byte order comprises the following steps:
所述函数返回值及参数具有明确的参数类型, 由动态库服务器或主程序的 消息发送与接受机制完成本机字节序与网络字节序的转换; 或 所述返回值及参数不具有明确的参数类型, 由动态库的使用者与动态库协 商实现字节序的统一。 The function return value and the parameter have an explicit parameter type, and the dynamic byte server or the main program's message sending and receiving mechanism completes the conversion of the native byte order and the network byte order; or The return value and the parameter do not have an explicit parameter type, and the user of the dynamic library negotiates with the dynamic library to realize the unification of the endian.
8、 一种调用动态库的装置, 其特征在于, 包括:  8. A device for invoking a dynamic library, comprising:
主程序执行单元, 用于发送调用动态库中函数的请求消息, 所述请求消息 中携带有调用函数的参量;  a main program execution unit, configured to send a request message for calling a function in the dynamic library, where the request message carries a parameter of the calling function;
动态库服务器, 用于根据所述参量完成动态库单元中函数的调用, 并在响 应消息中向所述主程序执行单元返回函数的执行结果;  a dynamic library server, configured to complete a function call in the dynamic library unit according to the parameter, and return an execution result of the function to the main program execution unit in the response message;
动态库单元, 用于根据所述动态库服务器的调用请求运行所述函数, 并向 动态库服务器上报执行结果。  a dynamic library unit, configured to run the function according to the call request of the dynamic library server, and report the execution result to the dynamic library server.
9、 根据权利要求 8所述的调用动态库的装置, 其特征在于, 所述动态库服 务器具体包括:  The device for invoking a dynamic library according to claim 8, wherein the dynamic library server comprises:
加载模块, 用于在所述动态库服务器启动时将自身管理的动态库加载到本 地;  a loading module, configured to load a dynamic library managed by the dynamic library server to the local site when the dynamic library server starts;
消息处理模块, 用于接收所述主程序执行单元发送的请求消息, 并根据消 息中携带的动态库名、 函数名及参数列表发送调用指令; 将函数的执行结果及 输出参数通过响应消息返回给所述主程序执行单元;  a message processing module, configured to receive a request message sent by the main program execution unit, and send a call instruction according to the dynamic library name, the function name, and the parameter list carried in the message; return the execution result and the output parameter of the function to the response message The main program execution unit;
调用模块, 用于根据所述调用指令中的函数名及参数列表调用相应的函数, 并将执行结果及返回参数上报给所述消息处理模块。  The calling module is configured to call a corresponding function according to the function name and the parameter list in the calling instruction, and report the execution result and the return parameter to the message processing module.
10、 根据权利要求 8或 9所述的调用动态库的装置, 其特征在于, 所述主 程序执行单元调用一个或一个以上的动态库服务器, 所述动态库服务器管理一 个或一个以上的动态库单元。  10. The apparatus for calling a dynamic library according to claim 8 or 9, wherein the main program execution unit calls one or more dynamic library servers, and the dynamic library server manages one or more dynamic libraries. unit.
11、 根据权利要求 8或 9所述的调用动态库的装置, 其特征在于, 所述动 态库服务器与动态库设置于同一台计算机上。  The apparatus for calling a dynamic library according to claim 8 or 9, wherein the dynamic library server and the dynamic library are disposed on the same computer.
12、 一种动态库服务器, 其特征在于, 包括:  12. A dynamic library server, comprising:
消息处理模块, 用于接收主程序发送的携带有调用函数的参量的请求消息, 并根据所述参量发送调用指令; 将执行结果通过响应消息返回给主程序; 调用模块, 用于根据所述调用指令中的函数名及参数列表调用对应的函数, 并将函数的执行结果上报给所述消息处理模块。 a message processing module, configured to receive a request message sent by the main program and carry a parameter of the calling function, and send a call instruction according to the parameter; return the execution result to the main program through the response message; The calling module is configured to invoke a corresponding function according to the function name and the parameter list in the calling instruction, and report the execution result of the function to the message processing module.
13、 根据权利要求 12所述的动态库服务器, 其特征在于, 还包括: 加载模块, 用于在启动时将自身管理的动态库加载到本地。  The dynamic library server according to claim 12, further comprising: a loading module, configured to load the dynamic library managed by itself to the local at startup.
14、 一种主程序执行装置, 其特征在于, 包括:  14. A main program execution device, comprising:
请求消息发送模块, 用于向动态库服务器发送调用动态库中函数的请求消 息, 所述请求消息中携带有调用函数的参量;  a request message sending module, configured to send, to the dynamic library server, a request message for calling a function in the dynamic library, where the request message carries a parameter of the calling function;
接收模块, 用于接收所述动态库服务器根据所述参量调用动态库中的函数, 并向主程序返回的携带函数执行结果的响应消息。  The receiving module is configured to receive a response message that the dynamic library server invokes a function in the dynamic library according to the parameter, and returns a result of carrying the function execution to the main program.
PCT/CN2008/070462 2007-03-13 2008-03-11 Method and device to call dynamic library and dynamic library server and master program implementing device WO2008110111A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN200710086755.8 2007-03-13
CNB2007100867558A CN100464305C (en) 2007-03-13 2007-03-13 Method and apparatus for calling dynamic library and dynamic library server

Publications (1)

Publication Number Publication Date
WO2008110111A1 true WO2008110111A1 (en) 2008-09-18

Family

ID=38709578

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2008/070462 WO2008110111A1 (en) 2007-03-13 2008-03-11 Method and device to call dynamic library and dynamic library server and master program implementing device

Country Status (2)

Country Link
CN (1) CN100464305C (en)
WO (1) WO2008110111A1 (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111382076A (en) * 2020-03-10 2020-07-07 北京字节跳动网络技术有限公司 Application program testing method and device, electronic equipment and computer storage medium

Families Citing this family (18)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN100464305C (en) * 2007-03-13 2009-02-25 华为技术有限公司 Method and apparatus for calling dynamic library and dynamic library server
CN101770394B (en) * 2008-12-29 2012-10-03 上海科泰世纪科技有限公司 Asynchronous invoking method based on component interface
CN102402455A (en) * 2010-09-14 2012-04-04 北大方正集团有限公司 Method and device for calling dynamic link library (DLL)
CN102780997B (en) * 2012-06-29 2018-06-26 深圳市赛格导航科技股份有限公司 The communication means and device of wireless communication module
CN103034501B (en) * 2012-12-25 2016-08-03 广东威创视讯科技股份有限公司 The function calling method of a kind of linux platform and function call device
CN103324542B (en) * 2013-07-17 2017-04-12 天脉聚源(北京)传媒科技有限公司 Method and device for inter-module calls
CN105487849A (en) * 2014-12-22 2016-04-13 哈尔滨安天科技股份有限公司 Method and system for calling unknown export functions of DLL
CN104539506A (en) * 2015-01-27 2015-04-22 浪潮集团有限公司 Network transmission service component and network transmission system
CN104699485A (en) * 2015-03-19 2015-06-10 神华集团有限责任公司 Massive program management method and massive program construction method
CN105068791B (en) * 2015-07-15 2018-10-23 贵阳朗玛信息技术股份有限公司 A kind of method and device for realizing bottom library
CN106959870B (en) * 2017-02-20 2020-09-29 北京数字联盟网络科技有限公司 Nginx dynamic module loading method and device
CN108595218B (en) * 2018-04-17 2021-08-27 网宿科技股份有限公司 Method and device for loading dynamic library of system
CN109271414B (en) * 2018-12-05 2021-08-13 北京安华金和科技有限公司 IPC-based database local communication auditing method
CN111209056B (en) * 2020-01-02 2021-02-19 北京东土科技股份有限公司 Method and device for loading function, readable storage medium and electronic equipment
CN111459489B (en) * 2020-02-27 2023-09-26 湖南大学 Automatic service packaging method, system and application of dynamic library
CN111506357A (en) * 2020-02-27 2020-08-07 湖南大学 Automatic dynamic library loading method, system and application
CN111708704A (en) * 2020-06-19 2020-09-25 腾讯科技(深圳)有限公司 Cloud real machine testing method and device, terminal and storage medium
CN113448655B (en) * 2021-07-09 2022-06-17 赞同科技股份有限公司 C standard dynamic library calling method and device

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6006278A (en) * 1997-07-18 1999-12-21 Electronic Data Systems Corporation Method and system for importing remote functions to a network computer
CN1470988A (en) * 2002-07-25 2004-01-28 梁肇新 Inter-process calling gate technique
CN101021804A (en) * 2007-03-13 2007-08-22 华为技术有限公司 Method and apparatus for calling dynamic library and dynamic library server

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CA2329891A1 (en) * 2000-12-29 2002-06-29 Subsecond Technology Inc. Method and apparatus for remote database maintenance and access
US7100172B2 (en) * 2002-11-27 2006-08-29 Microsoft Corporation System and method for changing operation of an application without recompiling
US7814471B2 (en) * 2004-12-16 2010-10-12 Microsoft Corporation Method and apparatus for providing DLL compatibility
CN100389572C (en) * 2005-04-11 2008-05-21 华为技术有限公司 System and method for long-distance calling communication assembly
CN100521691C (en) * 2005-09-21 2009-07-29 烽火通信科技股份有限公司 Method for realizing relocation based on EML-NML interface of CORBA

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6006278A (en) * 1997-07-18 1999-12-21 Electronic Data Systems Corporation Method and system for importing remote functions to a network computer
CN1470988A (en) * 2002-07-25 2004-01-28 梁肇新 Inter-process calling gate technique
CN101021804A (en) * 2007-03-13 2007-08-22 华为技术有限公司 Method and apparatus for calling dynamic library and dynamic library server

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111382076A (en) * 2020-03-10 2020-07-07 北京字节跳动网络技术有限公司 Application program testing method and device, electronic equipment and computer storage medium
CN111382076B (en) * 2020-03-10 2023-04-25 抖音视界有限公司 Application program testing method and device, electronic equipment and computer storage medium

Also Published As

Publication number Publication date
CN101021804A (en) 2007-08-22
CN100464305C (en) 2009-02-25

Similar Documents

Publication Publication Date Title
WO2008110111A1 (en) Method and device to call dynamic library and dynamic library server and master program implementing device
Pyarali et al. Design and Performance of an Object-Oriented Framework for High-Performance Electronic Medical Imaging.
US11537409B2 (en) System and method for managing system configuration data models
US10476767B2 (en) Communication between independent containers
US8010973B2 (en) Class loader for managing a network
US6393497B1 (en) Downloadable smart proxies for performing processing associated with a remote procedure call in a distributed system
EP2843552B1 (en) Method and system for executing callback functions delivered via a communication between a user-space application and the operating system kernel
US20030037174A1 (en) Common adapter/connector architecture
US20030009539A1 (en) Distributed object middleware connection method
JPH1083308A (en) Subsystem, method, and recording medium for stab retrieval and loading
US11860796B2 (en) Execution space agnostic device drivers
GB2491694A (en) Inherited transaction context for legacy software applications
US10725890B1 (en) Program testing service
JP3319764B2 (en) Method and apparatus for synchronizing software functions between software systems
US7487137B2 (en) Apparatus, system, and method for java bean delta generation
EP1057113B1 (en) Deferred reconstruction of objects and remote loading for event notification in a distributed system
Schmidt et al. Applying patterns to develop a pluggable protocols framework for orb middleware
US7337447B2 (en) Information handling system featuring a single pipe string driven architecture for bridging data of heterogeneous object source in native subsystems to java using native invocation interfaces
Dantam et al. Unix philosophy and the real world: Control software for humanoid robots
US11494197B2 (en) Enabling a pre-boot screen to be accessed remotely
JP3007340B1 (en) Function calling method, parallel distributed processing system and computer
Pyarali et al. Conference on Object-Oriented Technologies (COOTS) Toronto, Ontario, Canada, June 1996.
JP2006127399A (en) Application platform provision system, method, and program for it
KR20080106188A (en) Object-oriented discovery framework
CN113849449A (en) Communication system and information interaction method, device and medium

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 08715198

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 08715198

Country of ref document: EP

Kind code of ref document: A1