Component calling method and device, electronic equipment and storage medium
By adding remote object creation method and proxy interface construction functions to Wine's source code, the problem of remote call of COM components in Wine is solved, and compatibility with DCOM technology applications is achieved, and the operation stability of the application is improved. compatibility.
Patent Information
- Application Number
- CN202510013775.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-06
- Publication Date
- 2025-02-11
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Support for remote calls to COM components is not implemented in Wine, which causes Windows applications using DCOM technology to be unable to be used normally in Wine.
Add the definition of the remote creation object method to Wine's source code, and build a remote creation object request message by calling the RemoteCreateInstance method, and send the message to the remote server to request the creation of a COM object instance. At the same time, the parsing function of the remote server returns messages is added to build a proxy interface to realize remote calls.
It implements remote call support for COM components in Wine, so that Windows applications using DCOM technology can be used normally in Wine, improving the compatibility of Windows applications running in Wine.
Smart Images

Figure CN119415294A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a component calling method, device, electronic device and storage medium. Background Art
[0002] COM (Component Object Model) is a set of component object interface standards based on the Windows platform, consisting of a set of construction specifications and component object libraries.
[0003] COM components have their own interface definitions, which specify the services (methods) and properties that COM components can provide. Applications can use the functions of COM components by calling methods in these interfaces. For example, a COM component can be a component for image editing, which provides functions such as cropping, rotating, and adjusting colors. These functions are exposed to applications through interfaces. COM is based on the local component object model. The application and the COM component it calls must run on the same machine.
[0004] DCOM (Distributed Component Object Model) is a distributed version of COM that supports the development and deployment of distributed applications. DCOM allows applications to remotely call COM components on different machines, thereby extending the functionality of COM and enabling it to be used in a distributed environment.
[0005] Wine is a compatibility layer that allows Windows applications to run on Linux systems. However, Wine does not support remote calls to COM components, which means that Windows applications using DCOM technology cannot be used normally in Wine. Summary of the invention
[0006] In view of the above problems, an embodiment of the present application is proposed to provide a component calling method that overcomes the above problems or at least partially solves the above problems, which can realize remote calling of COM components in Wine and improve the compatibility of Windows applications running in Wine.
[0007] Correspondingly, an embodiment of the present application also provides a component calling device, an electronic device, and a storage medium to ensure the implementation and application of the above method.
[0008] In a first aspect, an embodiment of the present application discloses a component calling method, which is applied to a compatibility layer Wine in a Linux system, and the method includes: Receiving a call request for a target function from an application, wherein the call parameters of the target function include a class identifier of a target COM component, an interface identifier of a target interface of the target COM component, a creation flag, and remote server information; If it is parsed that the creation flag is a remote creation flag, the address information of the remote server is obtained from the remote server information; Sending a remote object creation request message to the remote server according to the address information, wherein the remote object creation request message carries the class identifier and the interface identifier, so as to request the remote server to create a COM object instance for the target COM component according to the class identifier, and to obtain a pointer to the target interface in the COM object instance according to the interface identifier; Receiving a return message sent by the remote server in response to the remote object creation request message, and constructing a proxy interface corresponding to the target interface according to the return message; A pointer to the proxy interface is returned to the application program, so that the application program can remotely call a method in the target interface by calling a method in the proxy interface.
[0009] In a second aspect, an embodiment of the present application discloses a component calling device, which is applied to a compatibility layer Wine in a Linux system, and the device includes: A call receiving module, used for receiving a call request of an application program for a target function, wherein the call parameters of the target function include a class identifier of a target COM component, an interface identifier of a target interface of the target COM component, a creation flag, and remote server information; A parameter parsing module, configured to obtain the address information of the remote server from the remote server information if it is parsed that the creation flag is a remote creation flag; A request message sending module, configured to send a remote object creation request message to the remote server according to the address information, wherein the remote object creation request message carries the class identifier and the interface identifier, so as to request the remote server to create a COM object instance for the target COM component according to the class identifier, and to obtain a pointer to the target interface in the COM object instance according to the interface identifier; A proxy interface construction module, used for receiving a return message sent by the remote server in response to the remote object creation request message, and constructing a proxy interface corresponding to the target interface according to the return message; The interface pointer operation module is used to return the pointer of the proxy interface to the application program, so that the application program can remotely call the method in the target interface by calling the method in the proxy interface.
[0010] In the third aspect, an embodiment of the present application discloses an electronic device, comprising: a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other through the communication bus; the memory is used to store at least one executable instruction, and the executable instruction enables the processor to execute the steps of the component calling method as described in any of the above.
[0011] In a fourth aspect, an embodiment of the present application discloses a readable storage medium, on which a program or instruction is stored, and when the program or instruction is executed by a processor, any component calling method described in the embodiment of the present application can be implemented.
[0012] The component calling method, device, electronic device and storage medium provided by the embodiments of the present application have the following advantages: This application modifies the source code of Wine, and adds the definition of the remote object creation method in the source code of Wine, so that Wine can construct a remote object creation request message by calling the remote object creation method during the execution of the target function, and send the remote object creation request message to the remote server to request the remote server to create a COM object instance. In addition, this application adds a function of parsing the return message of the remote server in Wine, and builds a proxy interface according to the return message of the remote server, so that the Windows application running in Wine can remotely call the method in the target interface of the COM object instance on the remote server by calling the method in the proxy interface, thereby realizing the support for remote calls of COM components in Wine, and then making the Windows application using DCOM technology can be used normally in Wine, improving the compatibility of Windows applications running in Wine. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] Figure 1 It is a flowchart of the steps of an embodiment of a component calling method of the present application; Figure 2 This is a schematic diagram of a remote call to a COM component message interaction in this application; Figure 3 It is a structural block diagram of an embodiment of a component calling device of the present application; Figure 4 It is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0014] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, the present application is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0015] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally a class, and the number of objects is not limited. For example, the first object can be one or more. In addition, the term "and / or" in the specification and claims is used to describe the association relationship of associated objects, indicating that three kinds of relationships can exist, for example, A and / or B can be represented: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the front and back associated objects are a kind of "or" relationship. In the embodiment of the present application, the term "multiple" refers to two or more, and other quantifiers are similar.
[0016] A COM component is a reusable software unit, usually a binary file (such as a DLL or EXE). A COM component contains the definition and implementation code of one or more COM objects, as well as the interface definition for interacting with the outside world. For example, a graphics processing COM component may contain COM object definitions for drawing graphics, editing graphics, saving graphics, and other functions, as well as corresponding interface definitions.
[0017] COM components are the basic modules for building COM applications. They provide an encapsulation mechanism to group related functions together and provide services to the outside through interfaces. Different software systems can reuse these components to reduce the workload of software development. For example, multiple different graphics editing software can use the same graphics processing COM component to implement basic graphics drawing and editing functions.
[0018] A COM object is an instantiation of a COM component in memory, and is a runtime entity with a specific interface. A COM object implements one or more interfaces defined by a COM component. A COM object can be considered an object that complies with the COM specification, hides its internal implementation details, and interacts with the outside world only through interfaces. For example, in a file management COM component, there may be a file reading COM object that implements the function of reading files, but the specific algorithm and data structure for reading files are hidden inside the object.
[0019] COM objects exist in COM components, and a COM component can contain multiple COM objects. Each COM object has its own responsibilities and functions, and provides different services by implementing different interfaces. For example, a multimedia COM component may contain an audio player COM object and a video player COM object, which implement the interfaces related to audio and video playback respectively.
[0020] COM object instances are obtained by instantiating COM objects. For example, after a file reading COM object instance is successfully created, the interface pointer of the COM object instance can be returned. Through this interface pointer, the function of reading the file COM object instance can be accessed and used. In COM applications, specific functions can be implemented by operating COM object instances. After creating a COM object instance, the interface pointer of the COM object instance can be obtained. Using this interface pointer, methods in the interface can be called to complete various tasks, such as reading files, drawing graphics, playing audio, etc.
[0021] Figure 1 A flowchart of a component calling method embodiment of the present application is shown. The method can be applied to the compatibility layer Wine in the Linux system. The method may include the following steps: Step 101: receiving a call request for a target function from an application, wherein the call parameters of the target function include a class identifier of a target COM component, an interface identifier of a target interface of the target COM component, a creation flag, and remote server information; Step 102: if it is determined that the creation flag is a remote creation flag, the address information of the remote server is obtained from the remote server information; Step 103: Send a remote object creation request message to the remote server according to the address information, wherein the remote object creation request message carries the class identifier and the interface identifier, so as to request the remote server to create a COM object instance for the target COM component according to the class identifier, and to obtain a pointer to the target interface in the COM object instance according to the interface identifier; Step 104: receiving a return message sent by the remote server in response to the remote object creation request message, and constructing a proxy interface corresponding to the target interface according to the return message; Step 105: Return a pointer to the proxy interface to the application program, so that the application program can remotely call the method in the target interface by calling the method in the proxy interface.
[0022] The component calling method provided in this application can be applied to electronic devices based on the Linux operating system. The electronic devices may include but are not limited to any of the following: servers, smart phones, voice recorders, tablet computers, e-book readers, MP3 (Moving Picture Experts Group Audio Layer III) players, MP4 (Moving Picture Experts Group Audio Layer IV) players, laptop computers, car computers, desktop computers, set-top boxes, smart TVs, wearable devices, etc.
[0023] This application does not limit the type of the Linux operating system. For example, the Linux operating system may include but is not limited to any one of Debian, Ubuntu, CentOS (Community Enterprise Operating System), UOS (Unicom Desktop Operating System), Kylin Operating System, and Fangde Operating System.
[0024] The Linux system runs a compatibility layer Wine, which can run Windows applications. The component calling method provided in the embodiment of the present application can implement support for remote calling of COM components in Wine, thereby allowing Windows applications using DCOM technology to be used normally in Wine.
[0025] This application modifies the source code of Wine, adds the definition of the remote object creation (RemoteCreateInstance) method to the source code of Wine, and recompiles and runs the modified source code of Wine. After compilation, the RemoteCreateInstance method will be generated, so that the modified Wine can build a RemoteCreateInstance request message by calling the RemoteCreateInstance method, and send the RemoteCreateInstance request message to the remote server to request the remote server to create a COM object instance. In addition, this application adds a function to parse the return message of the remote server in Wine, and builds a proxy interface according to the return message of the remote server, so that the Windows application running in Wine can remotely call the method in the target interface of the COM object instance on the remote server by calling the method in the proxy interface, thereby realizing the support for remote calls to COM components in Wine and realizing DCOM calls in Wine.
[0026] In the embodiment of the present application, the client is the request initiator, that is, the party requesting to call the COM component on the remote server. Specifically, the client refers to the Windows application running in Wine, referred to as the application in this application. The remote server is the service provider, which is another machine different from the client. Various COM components are registered in the remote server, and these COM components can provide the functions required by the client.
[0027] In a specific implementation, when an application needs to use the corresponding function of a COM component (referred to as a target COM component) in a remote server, it is first necessary to obtain the registration information of the target COM component on the remote server, such as the class identifier of the target COM component and the interface identifier of the target interface of the target COM component. In addition, it is also necessary to obtain the remote server information, such as the address information of the remote server.
[0028] A class identifier (CLSID) is a 128-bit globally unique identifier that uniquely identifies a class of COM components.
[0029] The Interface Identifier (IID) is also a 128-bit globally unique identifier used to identify the interface implemented by the COM component. The interface is the way the COM component provides services to the outside world. A COM component can implement multiple interfaces, and different interfaces can implement different functions.
[0030] The target interface refers to an interface of the target COM component that the application needs to use. The application needs to use the methods in this interface to implement the required functions.
[0031] For example, a complex graphics processing COM component includes interfaces for multiple different functions such as graphics drawing, graphics editing, and graphics storage. Each interface corresponds to its own IID, and the entire COM component has only one CLSID. When an application needs to use the graphics drawing function of the graphics processing COM component, the graphics processing COM component is the target COM component, and the interface that provides the graphics drawing function in the graphics processing COM component is called the target interface.
[0032] The remote server information (serverInfo) may include the address information (such as IP address) and the first port number (or DCOM service port number) of the remote server. The DCOM service port usually defaults to port 135. Furthermore, the remote server information may also include authorization information, which is used to authenticate the client identity. Only authenticated clients are allowed to access COM objects.
[0033] After obtaining the above information, the application can call the target function to request the creation of a COM object instance for the target COM component. The calling parameters of the target function include the class identifier (CLSID) of the target COM component, the interface identifier (IID) of the target interface of the target COM component, the creation flag and the remote server information (serverInfo).
[0034] The creation flag is used to indicate the method of creating a COM object instance. For example, if the creation flag is the remote creation flag CLSCTX_REMOTE_SERVER, it indicates that the COM object instance is to be created on a remote server instead of locally. If the creation flag is CLSCTX_INPROC_SERVER, it indicates that the COM object instance is to be created in the same local process. If the creation flag is CLSCTX_LOCAL_SERVER, it indicates that the COM object instance is to be created in a different local process.
[0035] The target function refers to the CoCreateInstanceEx function, which is an API (Application Programming Interface) function provided by the Windows system. It is used to locate the registered COM component according to the passed CLSID and create a COM object instance for the COM component. After successfully creating the COM object instance, the pointer to the target interface in the COM object instance is obtained according to the passed IID. The application can call the method in the COM object instance through the pointer of the target interface to implement the corresponding function.
[0036] Wine simulates and implements the CoCreateInstanceEx function. In the related art, the CoCreateInstanceEx function implemented in Wine only supports the creation of COM objects locally, for example, it can create COM object instances in the same local process or in different local processes, but does not support the creation of COM object instances on remote servers.
[0037] This application expands the functionality of the CoCreateInstanceEx function implemented in Wine, and adds a call to the RemoteCreateInstance method inside the CoCreateInstanceEx function. This application has implemented the RemoteCreateInstance method by modifying the source code of Wine, which can be called.
[0038] In an optional embodiment of the present application, the method may further include: The definition of the remote object creation method is added to the source code of Wine, and the modified Wine source code is recompiled and run, so that the modified Wine, in the process of executing the target function, constructs the remote object creation request message by calling the remote object creation method, and sends the remote object creation request message to the remote server.
[0039] Exemplarily, the present application adds a .idl file to the source code of Wine, and adds a definition of the RemoteCreateInstance method to the .idl file. In this way, the RemoteCreateInstance method will be generated when the source code of Wine is recompiled. During the execution of the target function, the modified Wine can construct a RemoteCreateInstance request message by calling the RemoteCreateInstance method, and send the RemoteCreateInstance request message to the remote server.
[0040] In an example, the RemoteCreateInstance method is defined as follows: HRESULT RemoteCreateInstance( [in] handle_t rpc, [in] ORPCTHIS *orpcthis, [out] ORPCTHAT *orpcthat, [in,unique] MInterfacePointer *pUnkOuter, [in,unique] MInterfacePointer *pActProperties, [out] MInterfacePointer **ppActProperties ); [in] indicates the data carried when the RemoteCreateInstance request message is sent, and [out] indicates the data carried when the remote server returns after receiving the RemoteCreateInstance request message.
[0041] The data structure pActProperties is used to store the data carried when sending the RemoteCreateInstance request message, which may include COM call related data such as the CLSID of the target COM component and the IID of the target interface.
[0042] The data structure ppActProperties is used to store the data carried by the remote server when returning the RemoteCreateInstance request message, which may include COM interface related data such as the pointer identifier (IPID) of the target interface, the object identifier (OID) of the COM object instance, and the object external identifier (OXID) of the COM object instance.
[0043] OID is used to uniquely identify a COM object instance. OXID is used to indicate which exporter (process or machine) the object instance is in and is responsible for managing and exporting the object instance. IPID is used to indicate the specific interface of the object instance, through which remote calls can be made.
[0044] Furthermore, ppActProperties may include the following data structures: ScmReplyInfoData and PropsOutInfo, wherein ScmReplyInfoData is used to store the COM component listening port information, and PropsOutInfo is used to store identifier information such as IPID, OID, and OXID.
[0045] The COM component listening port is a port opened by the Windows DCOM service for each COM component, which is used to receive call-related data of the corresponding COM component.
[0046] Specifically, after Wine receives the application's call request for the target function, it parses the target function's call parameters, including the CLSID, IID, creation flag, and remote server information passed in by the application when calling the target function. If the creation flag is parsed to be the remote creation flag CLSCTX_REMOTE_SERVER, indicating that a COM object instance is to be created on a remote server, the address information (such as an IP address) of the remote server is obtained from the remote server information. When executing the CoCreateInstanceEx function, based on the parsed CLSID and IID, a RemoteCreateInstance request message is constructed by calling the RemoteCreateInstance method, and based on the remote server's address information, a RemoteCreateInstance request message is sent to the remote server to request the remote server to create a COM object instance for the target COM component and return a pointer to the target interface.
[0047] Therefore, through the embodiment of the present application, when the application calls the target function CoCreateInstanceEx, the RemoteCreateInstance method is automatically called inside CoCreateInstanceEx. Through the newly added processing logic, Wine can send a RemoteCreateInstance request message to the remote server to request the remote creation of a COM object instance, providing a basis for implementing DCOM calls in Wine.
[0048] In an optional embodiment of the present application, after parsing that the creation flag is a remote creation flag and before sending a remote object creation request message to the remote server, the method may further include: Step S11, calling a first function, wherein the calling parameters of the first function include a specified transmission protocol, the address information of the remote server and a first port number; the first function is used to establish an RPC connection with the remote server; Step S12: If the RPC connection is established successfully, obtain the handle of the RPC connection.
[0049] The first function may be a get_rpc_handle function, which can be used to obtain a handle for a remote procedure call (RPC) connection. By calling the first function, a communication link between the client and the remote server can be established, and a handle that can be used for subsequent RPC operations is returned. Through this handle, the client can send requests and receive responses to achieve cross-machine communication.
[0050] When calling the first function get_rpc_handle, the parameters passed in may include the specified transmission protocol (such as recorded as protseq), the address information of the remote server (such as recorded as NetworkAddr) and the first port number (such as recorded as endpoint, such as endpoint may be port 135), etc.
[0051] It should be noted that the embodiments of the present application do not limit the specified transmission protocol. For example, TCP (Transmission Control Protocol) can be used. RPC connection needs to rely on the underlying transmission protocol to transmit data in the network, and TCP is a reliable transmission protocol. When the RPC connection selects TCP as the underlying transmission protocol, the data to be sent (such as function call requests and responses) is handed over to the TCP layer for sending. Of course, in the specific implementation, other transmission protocols such as http can also be used.
[0052] In the get_rpc_handle function, an RPC connection is established with the remote server based on the passed address information (the remote server's IP address) and the first port number (such as port 135). If the RPC connection is successfully established, the get_rpc_handle function returns the handle (rpc_handle) of the RPC connection. This handle can be used for subsequent interactive operations with the remote server, such as requesting remote creation of object instances and requesting remote calls to interface methods of COM object instances.
[0053] Furthermore, sending the remote object creation request message to the remote server may include: sending the remote object creation request message to the first port number of the remote server through the handle of the RPC connection in accordance with the data format specified by the designated transmission protocol.
[0054] The embodiment of the present application implements the function of sending a remote object creation request message through a specified transmission protocol in Wine by calling the first function.
[0055] Specifically, if the specified transmission protocol is the TCP protocol, the remote object creation request message is sent to the remote server, specifically to the first port of the remote server, through the handle of the RPC connection, in accordance with the data format specified by the specified transmission protocol (such as TCP data packet) and based on the address information (IP address) of the remote server.
[0056] In an optional embodiment of the present application, after obtaining the handle of the RPC connection, the method may further include: Step S21, calling a second function, wherein the calling parameters of the second function include the handle and authorization information of the RPC connection; Step S22: Send an authorization information verification request to the remote server, where the authorization information verification request carries the authorization information; Step S23, receiving the authorization information verification result returned by the remote server. If the authorization information verification result indicates that the verification failed, the remote server rejects subsequent requests received based on the handle of the RPC connection; if the authorization information verification result indicates that the verification is successful, the remote server allows subsequent requests received based on the handle of the RPC connection.
[0057] The second function may be a RpcBindingSetAuthInfoW function, which may be used to set authorization information in RPC communication. Through the second function, the client may bind authorization information to an established RPC connection so that the remote server may verify the authorization information of the client, thereby ensuring secure communication between the remote server and the client.
[0058] The calling parameters of the second function may include the handle and authorization information of the RPC connection. The authorization information may be obtained from the remote server information passed in by calling the target function CoCreateInstanceEx. The authorization information may include the user name and password of the remote server.
[0059] The embodiment of the present application establishes an RPC (remote procedure call) communication connection between the client and the remote server by calling the first function get_rpc_handle, and obtains a handle for identifying the RPC connection. Then, the second function RpcBindingSetAuthInfoW is called to bind the authorization information to the established RPC connection to ensure the security of communication.
[0060] After binding the authorization information, Wine will first send the authorization information when sending messages related to calling COM components to the remote server, so that the remote server can verify the authorization information. Only when the authorization information passes the verification of the remote server will the remote server respond to the request received based on the handle of the RPC connection. Among them, messages related to calling COM components include messages requesting to create COM object instances and messages requesting to call interface methods of COM object instances.
[0061] Reference Figure 2 , shows a schematic diagram of remote calling COM component message interaction in this application. Figure 2 As shown in the figure, the DCOM application (client) in Wine refers to the Windows application running in Wine that needs to use the COM component function in the remote server. Wine is the compatibility layer in the Linux system. The operating system of the remote server is the Windows system, in which the COM component is registered. The order of several main steps of the DCOM application in Wine to remotely call the COM component in the remote server is as follows: 1. Send authorization information; 2. Send RemoteCreateInstance request message; 3. Return message; 4. Call the interface method of the COM object instance.
[0062] like Figure 2 As shown, when the DCOM application in Wine remotely calls the COM component in the remote server, the interaction is carried out by transmitting TCP data packets through the TCP protocol.
[0063] In the embodiment of the present application, after the application calls the target function CoCreateInstanceEx, Wine parses the calling parameters of the target function, extracts CLSID, IID, creation flag and remote server information (serverInfo), and if the creation flag is parsed to be CLSCTX_REMOTE_SERVER, the remote server information (serverInfo) is saved, and the address information and authorization information of the remote server are obtained from the remote server information (serverInfo). Since the creation flag is parsed to be CLSCTX_REMOTE_SERVER, indicating that a COM object instance is to be created on the remote server, the target function CoCreateInstanceEx automatically calls the first function get_rpc_handle to establish an RPC connection between the client and the remote server. If the first function is executed successfully, the handle of the RPC connection is returned. To ensure secure communication with the remote server, after the first function is executed successfully, the second function RpcBindingSetAuthInfoW is called to bind the authorization information to the established RPC connection, and send an authorization information verification request to the remote server. If the authorization information verification is successful, CoCreateInstanceEx automatically calls the RemoteCreateInstance method to build a RemoteCreateInstance request message based on the passed CLSID and IID, and send it to the first port of the remote server through the established RPC connection.
[0064] The embodiment of the present application implements the RemoteCreateInstance method in Wine, and calls the method inside the target function to construct and send a RemoteCreateInstance request message, thereby realizing the client's request to create a COM object instance of a specified type on the remote server, so that the client can access and use the functions of the COM component on the remote server.
[0065] The remote server listens to the first port (such as port 135) through the network communication layer and receives the request message from the client. After receiving the RemoteCreateInstance request message from the client, the remote server searches for the registered COM component according to the CLSID carried in the message, thereby creating the corresponding COM object instance.
[0066] After the COM object instance is successfully created, the remote server assigns it an OID (object identifier), IPID (interface pointer identifier), and OXID (object external identifier). These identifiers are used to identify and manage COM object instances in a distributed environment. The remote server then packages these identifiers and other related information into a return message and sends it to the client.
[0067] After receiving the return message sent by the remote server in response to the remote object creation request message, Wine constructs a proxy interface according to the return message; the proxy interface has a mapping relationship with the target interface. Wine returns a pointer to the proxy interface to the application, so that the application calls the method in the proxy interface through the pointer of the proxy interface, and then calls the method in the target interface of the target COM component, thereby realizing interaction with the COM object instance on the remote server, just like calling it locally.
[0068] In an optional embodiment of the present application, the return message includes definition information of the target interface, the definition information includes the method name, parameter type, and return value type of each method in the target interface; the constructing a proxy interface corresponding to the target interface according to the return message may include: According to the definition information of the target interface, a proxy interface having a mapping relationship with the target interface is created, wherein the method name, parameter type, and return value type of each method in the proxy interface are consistent with those in the target interface; the specific implementation of each method in the proxy interface is to convert the call request of the method and send it to the remote server.
[0069] The proxy interface is an interface built on the client side, which is used to represent the interface of the real COM component in a distributed environment. The implementation of the proxy interface focuses on communication and call forwarding. The proxy interface is created in the client process, and its methods are used to package the client's call request into a suitable message format (for example, serialized parameters), and then send it to the real COM interface on the remote server through the DCOM communication mechanism (such as remote procedure call RPC). After receiving the return result sent by the remote server, the proxy interface parses the return result (for example, deserializes) and returns it to the client. The implementation of the proxy interface does not need to understand the business logic details of the real COM interface, but only needs to correctly pass the call request and return result. The proxy interface hides the complexity of distributed calls, allowing the client to call remote COM components just like calling local COM components.
[0070] In addition to the identifier information, the definition information of the target interface of the COM object instance in the remote server can also be obtained from the remote server or known in advance, including the method name, parameter type, return value type, etc. in the target interface. Based on the obtained interface definition information, a proxy interface can be created, and the method name, parameter type, return value type, etc. in the proxy interface are consistent with those in the target interface.
[0071] In the specific implementation, the proxy interface corresponds one-to-one with the interface of the COM object instance. When the application calls the method in the proxy interface, the proxy interface packages the passed-in parameters and the COM component where the interface to be called is located and sends them to the remote server.
[0072] Exemplarily, the CoUnmarshalInterface function can be used to build a proxy interface, which is an API function provided by the Windows system and performs corresponding operations with the CoMarshalInterface function. After the remote server uses the CoMarshalInterface function to serialize the interface pointer of a COM object instance and transmits it to the client through the specified transmission protocol, the client can use the CoUnmarshalInterface function to convert the serialized interface pointer into a usable proxy interface.
[0073] In an optional embodiment of the present application, the return message may include identifier information and a second port number, the identifier information including a pointer identifier (IPID) of the target interface, an object identifier (OID) of the COM object instance, and an object external identifier (OXID) of the COM object instance; The application program calling the method in the target interface by calling the method in the proxy interface may include: Step S31, receiving a call request from the application program for a first method in the proxy interface; Step S32: construct a remote call request message, where the remote call request message carries the call parameters of the first method, the name of the first method, and the identifier information; Step S33, sending the remote call request message to the second port number of the remote server to request the remote server to call the COM object instance to execute the second method in the target interface; the second method has a mapping relationship with the first method; Step S34: Receive the execution result of the second method returned by the remote server.
[0074] The return message returned by the remote server in response to the RemoteCreateInstance request message includes at least identifier information and a second port number. The identifier information includes IPID, OID and OXID.
[0075] IPID (Interface Pointer Identifier) is an identifier that uniquely identifies an interface pointer. In a distributed environment, when the interface pointer of a COM object is transmitted in the network or passed between different processes, IPID plays the role of tracking and distinguishing different interface pointers. Each interface pointer is assigned a unique IPID. For example, if there are multiple clients connected to a DCOM server (remote server), each client will have a different IPID for the pointer to the same interface. When the client calls the interface method, it can determine which client's request it is based on the IPID, thereby ensuring that the request can be correctly processed and returned to the corresponding client.
[0076] OID (Object Identifier), uniquely identifies a COM object instance.
[0077] OXID (Object Export Identifier) indicates in which exporter (process or machine) the COM object instance is located and is responsible for managing and exporting the COM object instance.
[0078] The second port number is the listening port number corresponding to the target component. The Windows DCOM service opens a port for each COM component to receive call-related data of the corresponding COM component. The call-related data includes CLSID and IID.
[0079] In the embodiment of the present application, the proxy interface and the target interface have a mapping relationship, the method contained in the proxy interface is called the first method, the method contained in the target interface is called the second method, and each first method in the proxy interface corresponds to each second method in the target interface. The target interface is the real interface of the COM object instance on the remote server, and the specific implementation of the second method is to perform specific operation steps to achieve the corresponding function. The specific implementation of the first method in the proxy interface is to package the call request and send it to the real interface on the remote server.
[0080] In one example, in a distributed database application, the database server (remote server) creates a COM object instance for a database service COM component, and the COM object instance implements an IDatabaseAccess interface (target interface). After the client creates a proxy interface corresponding to the target interface, the IDatabaseAccess interface has a Query method for querying data. The proxy interface also has a Query method for packaging the call request and sending it to the IDatabaseAccess interface on the remote server.
[0081] When the proxy interface receives a call request for its Query method (first method), it constructs a remote call request message, which carries the call parameters of the first method, the name of the first method, and the identifier information (IPID, OID and OXID); and sends the remote call request message to the second port number of the remote server to request the remote server to call the COM object instance to execute the Query method (second method) in the target interface, and return the execution result of the second method.
[0082] It should be noted that in the embodiments of the present application, the interaction between the client and the remote server is carried out through a specified transmission protocol (such as the TCP protocol). For example, the COM call-related data sent by the client to the remote server, the COM interface-related data returned by the remote server to the client, the call request sent by the client to the remote server, the execution result returned by the remote server to the client, etc., can be sent through TCP data packets.
[0083] In an optional embodiment of the present application, the method further includes: If it is parsed that the creation flag is a local creation flag, the COM call related data is sent to the specified pipe address.
[0084] The local creation flag indicates that the COM object instance needs to be created locally, and the local creation flag may include CLSCTX_INPROC_SERVER or CLSCTX_LOCAL_SERVER.
[0085] CLSCTX_INPROC_SERVER indicates that the COM object to be created runs in the same process space as the client application, and there is no cross-process communication.
[0086] CLSCTX_LOCAL_SERVER indicates that the COM object to be created is in a different process space from the client application and requires cross-process communication.
[0087] Furthermore, transmission parameters may be set according to the parsed creation flag, and the transmission parameters may include a specified transmission protocol (protseq), a target address (NetworkAddr), and a target port (endpoint). The transmission parameters are passed in when calling the first function get_rpc_handle.
[0088] For example, if the creation flag parsed is CLSCTX_REMOTE_SERVER, indicating that a COM object instance is to be created on a remote server, the address information (IP address) and the first port number (such as port 135) of the remote server are obtained from the remote server information (serverInfo). The transmission parameters can be set as follows: the value of the specified transmission protocol protseq is set to ncacn_ip_tcp, indicating that the specified transmission protocol is the TCP protocol; the value of the target address NetworkAddr is set to the IP address of the remote server; the value of the target port endpoint is set to 135.
[0089] For example, if the creation flag parsed is CLSCTX_INPROC_SERVER or CLSCTX_LOCAL_SERVER, it indicates that the COM object instance is to be created locally, and the remote server information (serverInfo) is empty. The transmission parameters can be set as follows: set the value of the specified transmission protocol protseq to ncalrpc, indicating that the specified transmission protocol is a pipe protocol; set the value of the target port endpoint to the specified pipe address.
[0090] In an embodiment of the present application, during the execution of the CoCreateInstanceEx function by Wine, when the CoCreateInstanceEx function internally calls get_rpc_handle, the above-mentioned transmission parameters are passed in. When executing get_rpc_handle internally, the transmission method of the COM call-related data can be determined according to the value of protseq. Exemplarily, if the value of protseq is ncacn_ip_tcp, indicating that the specified transmission protocol is the TCP protocol, the COM call-related data is sent using the TCP protocol, and the COM call-related data is sent to the IP address pointed to by NetworkAddr and the port pointed to by endpoint. If the value of protseq is ncalrpc, indicating that the specified transmission protocol is the pipe protocol, the COM call-related data is sent using the pipe protocol, and the COM call-related data is sent to the pipe address pointed to by endpoint.
[0091] Local COM calls use pipes to transmit data by default, so local COM calls can only be used in the same container. DCOM calls (also known as remote COM calls) use TCP networks to transmit data, allowing remote calls to be made across containers and machines.
[0092] In summary, the present application modifies the source code of Wine, and adds the definition of the remote object creation method in the source code of Wine, so that Wine can construct a remote object creation request message by calling the remote object creation method during the execution of the target function, and send the remote object creation request message to the remote server to request the remote server to create a COM object instance. In addition, the present application adds a function of parsing the return message of the remote server in Wine, and builds a proxy interface according to the return message of the remote server, so that the Windows application running in Wine can remotely call the method in the target interface of the COM object instance on the remote server by calling the method in the proxy interface, thereby realizing the support for remote calls of COM components in Wine, and then making the Windows application using DCOM technology can be used normally in Wine, improving the compatibility of Windows applications running in Wine.
[0093] It should be noted that, for the method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present application are not limited by the described order of actions, because according to the embodiments of the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present application.
[0094] Reference Figure 3 , shows a structural block diagram of an embodiment of a component calling device of the present application, the device is applied to the compatibility layer Wine in the Linux system, and the device may include: A call receiving module 301 is used to receive a call request from an application program for a target function, wherein the call parameters of the target function include a class identifier of a target COM component, an interface identifier of a target interface of the target COM component, a creation flag, and remote server information; The parameter parsing module 302 is used to obtain the address information of the remote server from the remote server information if it is parsed that the creation flag is a remote creation flag; A request message sending module 303 is used to send a remote object creation request message to the remote server according to the address information, wherein the remote object creation request message carries the class identifier and the interface identifier, so as to request the remote server to create a COM object instance for the target COM component according to the class identifier, and to obtain a pointer to the target interface in the COM object instance according to the interface identifier; The proxy interface construction module 304 is used to receive a return message sent by the remote server in response to the remote object creation request message, and to construct a proxy interface corresponding to the target interface according to the return message; The interface pointer operation module 305 is used to return the pointer of the proxy interface to the application program, so that the application program can remotely call the method in the target interface by calling the method in the proxy interface.
[0095] Optionally, the device further comprises: A definition module is used to add a definition of a remote object creation method in the source code of Wine, and to recompile and run the modified source code of Wine, so that the modified Wine, in the process of executing the target function, constructs the remote object creation request message by calling the remote object creation method, and sends the remote object creation request message to the remote server.
[0096] Optionally, the device further comprises: A connection establishment module, configured to call a first function, wherein the calling parameters of the first function include a specified transmission protocol, the address information of the remote server and a first port number; the first function is configured to establish a remote procedure call (RPC) connection with the remote server; if the RPC connection is successfully established, a handle of the RPC connection is obtained; The request message sending module is specifically used for: The remote object creation request message is sent to the first port number of the remote server through the handle of the RPC connection in accordance with the data format specified by the specified transmission protocol.
[0097] Optionally, the device further comprises: An authorization binding module, used to call a second function, wherein the calling parameters of the second function include a handle of the RPC connection and authorization information; An authorization verification module is used to send an authorization information verification request to the remote server, wherein the authorization information verification request carries the authorization information; receive an authorization information verification result returned by the remote server, and if the authorization information verification result indicates that the verification failed, the remote server rejects subsequent requests received based on the handle of the RPC connection; if the authorization information verification result indicates that the verification is successful, the remote server allows subsequent requests received based on the handle of the RPC connection.
[0098] Optionally, the return message includes definition information of the target interface, and the definition information includes a method name, a parameter type, and a return value type of each method in the target interface; The proxy interface building module is specifically used for: According to the definition information of the target interface, a proxy interface having a mapping relationship with the target interface is created, wherein the method name, parameter type, and return value type of each method in the proxy interface are consistent with those in the target interface; the specific implementation of each method in the proxy interface is to convert the call request of the method and send it to the remote server.
[0099] Optionally, the return message includes identifier information and a second port number, the identifier information includes a pointer identifier of the target interface, an object identifier of the COM object instance, and an object external identifier of the COM object instance; The interface pointer operation module includes: A first receiving submodule, configured to receive a call request from the application program for a first method in the proxy interface; A message construction submodule, used to construct a remote call request message, wherein the remote call request message carries the call parameters of the first method, the name of the first method, and the identifier information; A request sending submodule, used for sending the remote call request message to the second port number of the remote server to request the remote server to call the COM object instance to execute the second method in the target interface; the second method has a mapping relationship with the first method; The result receiving submodule is used to receive the execution result of the second method returned by the remote server.
[0100] The interface calling device provided by the present application is applied to Wine. The definition of the remote object creation method is added to the source code of Wine, so that Wine can construct a remote object creation request message by calling the remote object creation method during the execution of the target function, and send the remote object creation request message to the remote server to request the remote server to create a COM object instance. In addition, the present application adds a function of parsing the return message of the remote server in Wine, and builds a proxy interface according to the return message of the remote server, so that the Windows application running in Wine can remotely call the method in the target interface of the COM object instance on the remote server by calling the method in the proxy interface, thereby realizing the support for remote calling of COM components in Wine, and then making the Windows application using DCOM technology can be used normally in Wine, thereby improving the compatibility of Windows applications running in Wine.
[0101] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0102] Reference Figure 4 , is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 4 As shown, the electronic device includes: a processor, a memory, a communication interface and a communication bus, and the processor, the memory and the communication interface communicate with each other through the communication bus; the memory is used to store at least one executable instruction, and the executable instruction enables the processor to execute the steps of the component calling method of the aforementioned embodiment.
[0103] An embodiment of the present application provides a non-temporary computer-readable storage medium. When the instructions in the storage medium are executed by a program or processor of a terminal, the terminal is enabled to execute the steps of the component calling method of the aforementioned embodiment.
[0104] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0105] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, devices, or computer program products. Therefore, the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0106] The embodiments of the present application are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0107] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing terminal device to operate in a predictable manner, so that the instructions stored in the computer readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0108] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable terminal device. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0109] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.
[0110] Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for those skilled in the art, according to the idea of the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A component calling method, characterized in that: Applied to the compatibility layer Wine in the Linux system, the method comprises: Receiving a call request for a target function from an application, wherein the call parameters of the target function include a class identifier of a target COM component, an interface identifier of a target interface of the target COM component, a creation flag, and remote server information; If it is parsed that the creation flag is a remote creation flag, the address information of the remote server is obtained from the remote server information; Sending a remote object creation request message to the remote server according to the address information, wherein the remote object creation request message carries the class identifier and the interface identifier, so as to request the remote server to create a COM object instance for the target COM component according to the class identifier, and to obtain a pointer to the target interface in the COM object instance according to the interface identifier; Receiving a return message sent by the remote server in response to the remote object creation request message, and constructing a proxy interface corresponding to the target interface according to the return message; A pointer to the proxy interface is returned to the application program, so that the application program can remotely call a method in the target interface by calling a method in the proxy interface.
2. The method according to claim 1, characterized in that: Before receiving the call request of the application program for the target function, the method further includes: The definition of the remote object creation method is added to the source code of Wine, and the modified Wine source code is recompiled and run, so that the modified Wine, in the process of executing the target function, constructs the remote object creation request message by calling the remote object creation method, and sends the remote object creation request message to the remote server.
3. The method according to claim 1, characterized in that After parsing that the creation flag is a remote creation flag and before sending a remote object creation request message to the remote server, the method further includes: Calling a first function, wherein the calling parameters of the first function include a specified transmission protocol, the address information of the remote server and a first port number; the first function is used to establish a remote procedure call (RPC) connection with the remote server; If the RPC connection is established successfully, obtain the handle of the RPC connection; The sending of a remote object creation request message to the remote server comprises: The remote object creation request message is sent to the first port number of the remote server through the handle of the RPC connection in accordance with the data format specified by the specified transmission protocol.
4. The method according to claim 3, characterized in that After obtaining the handle of the RPC connection, the method further includes: Calling a second function, wherein the calling parameters of the second function include the handle and authorization information of the RPC connection; Sending an authorization information verification request to the remote server, wherein the authorization information verification request carries the authorization information; Receive the authorization information verification result returned by the remote server. If the authorization information verification result indicates that the verification failed, the remote server rejects subsequent requests received based on the handle of the RPC connection; if the authorization information verification result indicates that the verification is successful, the remote server allows subsequent requests received based on the handle of the RPC connection.
5. The method according to claim 1, characterized in that The return message includes definition information of the target interface, and the definition information includes method name, parameter type, and return value type of each method in the target interface; The step of constructing a proxy interface corresponding to the target interface according to the returned message includes: According to the definition information of the target interface, a proxy interface having a mapping relationship with the target interface is created, wherein the method name, parameter type, and return value type of each method in the proxy interface are consistent with those in the target interface; the specific implementation of each method in the proxy interface is to convert the call request of the method and send it to the remote server.
6. The method according to claim 1, characterized in that The return message includes identifier information and a second port number, wherein the identifier information includes a pointer identifier of the target interface, an object identifier of the COM object instance, and an object external identifier of the COM object instance; The application remotely calls the method in the target interface by calling the method in the proxy interface, including: receiving a call request from the application program for a first method in the proxy interface; Constructing a remote call request message, wherein the remote call request message carries the call parameters of the first method, the name of the first method, and the identifier information; Sending the remote call request message to the second port number of the remote server to request the remote server to call the COM object instance to execute a second method in the target interface; the second method has a mapping relationship with the first method; Receive the execution result of the second method returned by the remote server.
7. A component calling device, characterized in that: The device is applied to the compatibility layer Wine in the Linux system, and comprises: A call receiving module, used for receiving a call request of an application program for a target function, wherein the call parameters of the target function include a class identifier of a target COM component, an interface identifier of a target interface of the target COM component, a creation flag, and remote server information; A parameter parsing module, configured to obtain the address information of the remote server from the remote server information if it is parsed that the creation flag is a remote creation flag; A request message sending module, configured to send a remote object creation request message to the remote server according to the address information, wherein the remote object creation request message carries the class identifier and the interface identifier, so as to request the remote server to create a COM object instance for the target COM component according to the class identifier, and to obtain a pointer to the target interface in the COM object instance according to the interface identifier; A proxy interface construction module, used for receiving a return message sent by the remote server in response to the remote object creation request message, and constructing a proxy interface corresponding to the target interface according to the return message; The interface pointer operation module is used to return the pointer of the proxy interface to the application program, so that the application program can remotely call the method in the target interface by calling the method in the proxy interface.
8. The device according to claim 7, characterized in that The device also includes: A definition module is used to add a definition of a remote object creation method in the source code of Wine, and to recompile and run the modified source code of Wine, so that the modified Wine, in the process of executing the target function, constructs the remote object creation request message by calling the remote object creation method, and sends the remote object creation request message to the remote server.
9. An electronic device, characterized in that: include: A processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus; The memory is used to store at least one executable instruction, and the executable instruction enables the processor to execute the steps of the component calling method as described in any one of claims 1 to 6.
10. A readable storage medium, characterized in that: The readable storage medium stores a program or instruction, and when the program or instruction is executed by the processor, the steps of the component calling method as described in any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Remote calling method and device, electronic equipment and storage medium
CN116932245A
Touch method and device for WPF application, equipment and medium
CN118466816A
Cited By
Component object model calling method and device, equipment and storage medium
CN120560738A