Interface calling method and device

By parsing and standardizing C++ interface data, C++ dynamic link libraries and C++/CLI dynamic link libraries are constructed, enabling efficient and flexible interface calls between C# and C++. This solves the problems of complexity and inflexibility in the process of C# calling C++ interfaces, and reduces development costs and maintenance difficulty.

CN120973441APending Publication Date: 2025-11-18BEIJING HUAHANG WEISHI IND SOFTWARE TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510985066.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-17
Publication Date
2025-11-18

AI Technical Summary

Technical Problem

In existing technologies, calling C++ interfaces from C# is a complex and inflexible process, resulting in high development costs and instability, making it difficult to meet diverse application needs.

Method used

By parsing the original C++ interface data, extracting the target C++ interface data and standardizing it, a C++ dynamic link library and a C++/CLI dynamic link library are constructed. Static variables are used to store call pointers and reflection to bind functions, thereby achieving interoperability between C# and C++. Interface calls are performed at the program call time according to the configuration file.

Benefits of technology

It improves the efficiency and flexibility of interface calls, reduces development costs and maintenance difficulty, and enables C# to easily call C++ functions, supporting flexible extensions and modifications without recompiling the code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120973441A_ABST
    Figure CN120973441A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides an interface calling method and device, and the method comprises the steps: analyzing an original C + + interface, extracting an interface C + + function and a structural body, constructing a target C + + interface, standardizing the target C + + interface, and constructing a C + + dynamic link library based on a calling pointer of original C + + interface data and a standardized interface; constructing a C + + / CLI dynamic link library in the C + + application program; when a user uses C # function configuration, the C + + / CLI dynamic link library obtains a corresponding program calling opportunity and a target C # function from the configuration file for initial configuration, and when the program calling opportunity is met, the C # function corresponding to the C + + function called by the current program is determined according to the C + + / CLI dynamic link library; the C # function is called, the original C + + function is called back through the C + + dynamic link library in the C # function, interface calling is achieved, and the efficiency and flexibility of interface calling can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of data processing, in particular to an interface calling method and device. BACKGROUND

[0002] In the field of software development, interface calling between different programming languages has always been a significant technical challenge. This problem is particularly prominent when it is necessary to wrap C++ interfaces into C# interfaces or call C++ interfaces from C#. Currently, existing solutions on the market are often cumbersome, requiring a large amount of hand-written code and lacking flexibility, making it difficult to meet the increasingly diverse application requirements.

[0003] Traditional methods usually involve complex code conversion and manual wrapping processes, which not only increase development costs but also may lead to potential errors and instability factors. In addition, these methods often limit the flexibility and scalability of interface calling, making it inconvenient in subsequent development and maintenance processes.

[0004] Specifically, traditional C# calling C++ methods usually rely on COM interfaces, which require all interfaces to be encapsulated into class objects and implemented through header file import and C++ class inheritance for calling. However, this design approach has obvious limitations because C# programs cannot directly inherit C++ class objects, resulting in a complex and inflexible calling process.

[0005] Therefore, there is an urgent need for a new interface calling method to solve the above problems, achieve efficient and flexible interface calling, and reduce development costs and maintenance difficulty. SUMMARY

[0006] To address the problems in the prior art, the present application provides an interface calling method and device that can improve the efficiency and flexibility of interface calling.

[0007] To solve at least one of the above problems, the present application provides the following technical solutions:

[0008] In a first aspect, the present application provides an interface calling method, comprising:

[0009] parsing original C++ interface data, extracting corresponding target C++ interface data, standardizing the function type of the target C++ interface data according to a preset C# function type conversion rule, determining corresponding standardized C++ interface data, storing the calling entry of the original C++ interface data as a calling pointer in the form of a static variable, and determining a corresponding C++ dynamic link library according to the calling pointer and the standardized C++ interface data, wherein the target C++ interface data includes C++ functions and structures;

[0010] constructing a C++ / CLI dynamic link library, wherein the C++ / CLI dynamic link library initializes a common language runtime environment operation at startup of the C++ application, ensures interoperability of C# functions and C++ functions by dynamically loading C# functions and reflecting binding functions;

[0011] when the user configures using the C# function, receiving a configuration file of the user, the C++ / CLI dynamic link library obtains a corresponding program calling time and a target C# function from the configuration file to perform initialization configuration, when the program calling time is met, determining a C# function corresponding to the current program calling time according to the C++ / CLI dynamic link library, calling the C# function and calling the original C++ function through the C++ dynamic link library inside the C# function to realize interface calling, wherein the program calling time is a trigger condition for the C++ application to call the C# function.

[0012] Further, the original C++ interface data is parsed, and corresponding target C++ interface data is extracted, including:

[0013] identifying functions and structures in the original C++ interface data;

[0014] extracting definition information of the functions and structures to determine corresponding target C++ interface data, wherein the definition information of the functions and structures includes function names, parameter types, return value types, and member variable types and names of structures.

[0015] Further, the calling entry of the original C++ interface data is stored as a calling pointer in the form of a static variable, including:

[0016] defining a static variable for storing a calling entry of the original C++ interface data;

[0017] constructing an initialization function to initialize the static variable to determine a corresponding calling pointer, so that the C# interface can access the original C++ interface through the calling pointer.

[0018] Further, the corresponding C++ dynamic link library is determined according to the calling pointer and the standardized C++ interface data, including:

[0019] determining a C#-compatible intermediate layer function declaration according to the standardized C++ interface data;

[0020] binding the calling pointer to the intermediate layer function declaration to generate a C++ exported function with a unified calling specification, and determining a corresponding C++ dynamic link library based on the exported function.

[0021] Further, the C++ / CLI dynamic link library is used to determine the C# function corresponding to the current program calling opportunity according to the C++ / CLI dynamic link library when the program calling opportunity is met, and the method comprises the steps of:

[0022] When the program calling opportunity is met, the C++ / CLI dynamic link library receives a calling request, and determines a corresponding calling identifier, wherein the calling request is a C++ calling request of a C++ application program;

[0023] According to the reflection mechanism, a C# function associated with the calling identifier is queried in a preset C# dynamic link library.

[0024] Further, the C++ / CLI dynamic link library is used to determine the C# function corresponding to the current program calling opportunity according to the C++ / CLI dynamic link library when the program calling opportunity is met, and the method comprises the steps of:

[0025] According to the reflection mechanism, a C# function associated with the calling identifier is queried in a preset C# dynamic link library.

[0026] According to the reflection mechanism, a C# function associated with the calling identifier is queried in a preset C# dynamic link library.

[0027] Further, the C++ / CLI dynamic link library is used to determine the C# function corresponding to the current program calling opportunity according to the C++ / CLI dynamic link library when the program calling opportunity is met, and the method comprises the steps of:

[0028] A class library project is created by using Visual Studio, a C++ / CLI language type is selected, and a corresponding C++ / CLI dynamic link library is determined;

[0029] When the C++ application program is started, the C++ / CLI dynamic link library is loaded to initialize a common language runtime environment, so that the C# code can be executed in the C++ process.

[0030] In a second aspect, the application provides an interface calling device, which comprises:

[0031] A C++ dynamic link library determination module is configured to parse original C++ interface data, extract corresponding target C++ interface data, standardize the function type of the target C++ interface data according to a preset C# function type conversion rule, determine corresponding standardized C++ interface data, store the calling entry of the original C++ interface data in the form of a static variable as a calling pointer, and determine a corresponding C++ dynamic link library according to the calling pointer and the standardized C++ interface data, wherein the target C++ interface data comprises a C++ function and a structure;

[0032] The C++ / CLI dynamic link library determining module is configured to build a C++ / CLI dynamic link library, wherein the C++ / CLI dynamic link library is configured to initialize a common language runtime environment operation at the start of the C++ application, and ensure interoperability between C# functions and C++ functions by dynamically loading C# functions and reflecting binding functions.

[0033] The interface calling module is configured to receive a configuration file of a user when the user uses a C# function configuration, and the C++ / CLI dynamic link library is configured to obtain a corresponding program calling time and a target C# function from the configuration file to perform initialization configuration, and when the program calling time is met, the C++ / CLI dynamic link library is configured to determine a C# function corresponding to the current program calling time according to the C++ / CLI dynamic link library, call the C# function, and call the original C++ function in the C# function through the C++ dynamic link library to realize interface calling, wherein the program calling time is a trigger condition for the C++ application to call the C# function.

[0034] In a third aspect, the present application provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the interface calling method when executing the program.

[0035] In a fourth aspect, the present application provides a computer readable storage medium, which stores a computer program, wherein the computer program is executable on a processor to implement the steps of the interface calling method.

[0036] In a fifth aspect, the present application provides a computer program product, comprising a computer program / instruction, wherein the computer program / instruction is executable on a processor to implement the steps of the interface calling method.

[0037] According to the above technical solution, the present application provides an interface calling method and device, which analyzes an original C++ interface, extracts an interface C++ function and a structure to build a target C++ interface, standardizes the target C++ interface, and builds a C++ dynamic link library based on a calling pointer of the original C++ interface data and the standardized interface; builds a C++ / CLI dynamic link library in a C++ application; when a user uses a C# function configuration, the C++ / CLI dynamic link library obtains a corresponding program calling time and a target C# function from a configuration file to perform initialization configuration, and when the program calling time is met, the C++ / CLI dynamic link library determines a C# function corresponding to the current program calling time according to the C++ / CLI dynamic link library, calls the C# function, and calls the original C++ function in the C# function through the C++ dynamic link library to realize interface calling, thereby improving the efficiency and flexibility of interface calling. BRIEF DESCRIPTION OF DRAWINGS

[0038] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings needed to be used in the embodiments or prior art description. Obviously, the drawings in the following description are some embodiments of the present application, and other drawings can be obtained by those of ordinary skill in the art without any creative effort based on these drawings.

[0039] Figure 1 One of the flowcharts of the interface calling method in the embodiments of the present application;

[0040] Figure 2 The structural diagram of the interface calling device in the embodiments of the present application;

[0041] Figure 3 The structural diagram of the electronic device in the embodiments of the present application.

[0042] Reference signs:

[0043] Electronic device 9600, central processor 9100, memory 9140, communication module 9110, input unit 9120, audio processor 9130, display 9160, power supply 9170, buffer memory 9141, application / function storage unit 9142, data storage unit 9143, driver program storage unit 9144, antenna 9111, speaker 9131, microphone 9132. DETAILED DESCRIPTION

[0044] In order to make the purposes, technical solutions and advantages of the embodiments of the present application more clear, the following will combine the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are some of the embodiments of the present application, not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without any creative effort belong to the scope of protection of the present application.

[0045] The acquisition, storage, use, processing and the like of data in the technical solutions of the present application all conform to the relevant provisions of national laws and regulations.

[0046] In view of the problem that traditional C# calling C++ interface involves complex code conversion and manual wrapping process. The application provides an interface calling method and device, which analyzes the original C++ interface, extracts the interface C++ function and structure to build a target C++ interface, standardizes the target C++ interface, and builds a C++ dynamic link library based on the calling pointer of the original C++ interface data and the standardized interface; a C++ / CLI dynamic link library is built in the C++ application; when the user uses the C# function configuration, the C++ / CLI dynamic link library obtains the corresponding program calling occasion and target C# function from the configuration file for initialization configuration, when the program calling occasion is met, the C++ / CLI dynamic link library determines the C# function corresponding to the C++ function of the current program calling, calls the C# function, and calls back the original C++ function in the C++ dynamic link library, realizes the interface calling, and thus the efficiency and flexibility of the interface calling can be improved.

[0047] In order to improve the efficiency and flexibility of the interface calling, an embodiment of the interface calling method is provided, referring to Figure 1 , the interface calling method specifically includes the following contents:

[0048] Step S101: analyzing the original C++ interface data, extracting the corresponding target C++ interface data, standardizing the function type of the target C++ interface data according to the preset C# function type conversion rule, determining the corresponding standardized C++ interface data, storing the calling entry of the original C++ interface data as a calling pointer in the form of a static variable, and determining the corresponding C++ dynamic link library according to the calling pointer and the standardized C++ interface data, wherein the target C++ interface data includes C++ functions and structures;

[0049] Optionally, in this embodiment, the original C++ interface is wrapped and data converted, so that C# can call C++ functions.

[0050] Optionally, in this embodiment, for C# calling C++ method, C# runtime itself supports calling native method. However, the C# interface of the prior art is a COM interface, and all interfaces are encapsulated into class objects, and the calling is realized by header file introduction and C++ class inheritance. Under this design, the C# program cannot directly inherit the C++ class object.

[0051] Based on the above problems, we first encapsulate a pure C++ DLL (dynamic link library) to provide for C# calling. Only functions and structures are stored in this C++ DLL, so there is no problem of C# inheriting C++ class objects.

[0052] Specifically, the original C++ interface data is usually provided in the form of header files or dynamic link libraries, which contain detailed descriptions of functions, structures, and other elements that can be called externally. This solution first parses these data and uses regular expressions and other text parsing techniques to identify key information such as function declarations and structure definitions from the read text. For example, when encountering a function declaration, the regular expression can identify the return type, function name, and parameter list of the function; for structure definitions, it can extract the structure name and the member variables it contains.

[0053] After extracting the target interface data that needs to be exposed to C# (function name, parameter type, return value type, etc.), the interface data that needs to be wrapped (i.e., target C++ interface data) is selected from the parsed results, including:

[0054] C++ functions: functions that need to be exposed to C# calls.

[0055] Structures: composite types used for cross-language data transmission.

[0056] This step needs to determine which functions and structures are needed according to the pre-set requirements. For example, assuming our goal is to implement a simple mathematical operation function, we may select the addition function and the structure for representing two-dimensional points from the numerous C++ interfaces. By searching for these specific names in the parsed data, we can accurately extract the required function declarations and structure definitions for further processing.

[0057] According to the pre-set C# function type conversion rules, the function types of the target C++ interface data are standardized to obtain standardized interfaces.

[0058] It can be understood that in order to enable C++ interfaces to be successfully called by C#, we need to convert the data types in C++ to types that C# can recognize and process. This requires us to develop a detailed type conversion rule in advance, which clearly defines the type of each type in C++ in C#.

[0059] For example, the int type in C++ also corresponds to int in C#; the char* string type in C++ needs to be converted to the string type in C#; handle pointer types, convert them to IntPtr or safe reference types in C#; align the memory layout of the structure (StructLayout feature) to ensure compatibility when transmitting across languages.

[0060] According to these rules, we convert the parameter types and return types of the extracted C++ functions one by one, ensuring they have the correct type representation in C#. After completing the type conversion, we can generate interface code that conforms to C# syntax and specifications based on the converted type information, preparing for C# to call C++ functions.

[0061] Next, in C++, to flexibly call the target functions, we need to save the function call entry in a special way. Specifically, we define some static variables in the C++ code, which are pointers to functions. During the initialization phase of the program, we assign the actual address of the target function to these static variables. In this way, through these static variables, we can indirectly call the corresponding C++ functions.

[0062] For example, suppose we have an addition function add, we define a static function pointer variable addFunc, and assign the address of the add function to it during initialization. After that, when we need to call the addition function, we only need to call it through the addFunc pointer, without directly using the function name. This way of calling through static variable pointers provides convenience for subsequent C# calls to C++ functions, because C# can obtain and call these function pointers stored in static variables through specific mechanisms.

[0063] Finally, we need to compile the above processed C++ code into a dynamic link library (DLL). This DLL contains the static variable function pointers and initialization functions defined earlier. In the C# program, we will reference this DLL through specific mechanisms (such as the DllImport attribute) and call the initialization function to complete the initialization of the C++ function pointer. Once the initialization is complete, the C# program can indirectly call the C++ functions encapsulated in the DLL through the standardized interface code generated earlier. For example, when the C# program needs to perform addition operations, it will call the addFunc pointer in the DLL to achieve it, without worrying about the specific implementation details of the underlying C++ function. In this way, we successfully wrap the C++ interface into a form that C# can easily call, achieving functional interaction between the two languages.

[0064] It can be understood that since the C++ DLL only stores functions and structures, there is no problem of C# inheriting C++ class objects, and the DLL can also solve the problem of variable type mapping. Users can freely define the C++ functions and structures to be called through the C# configuration file without modifying the C# code. This allows users to easily extend and modify the called C++ functions without recompiling the C# code.

[0065] Based on the above step S101, we encapsulate a pure C++ DLL through the interaction between C++ DLL and C#, avoid C# inheriting C++ class objects, and when C# calls C++ functions, the pure C++ DLL calls the original C++ interface through a static pointer to obtain the function of the original C++ interface.

[0066] Step S102: build a C++ / CLI dynamic link library, wherein the C++ / CLI dynamic link library initializes the common language runtime environment operation when the C++ application starts, dynamically loads C# functions and reflects the binding function to ensure the interoperability of C# functions and C++ functions.

[0067] Optionally, in the embodiment, since the software itself is a C++ application, it does not have a "common language runtime" (CLR), and therefore we need to call a new DLL at the appropriate time to provide functions for interacting with the software body, that is, to build a bridge for interaction between C++ and C#.

[0068] Specifically, the C++ / CLI dynamic link library is built.

[0069] C++ / CLI is a hybrid programming technology that allows C++ code and C# code to interoperate. In order to achieve the interoperability between C++ dynamic link library and C# functions, we need to create a C++ / CLI dynamic link library. This DLL will serve as a bridge between C++ and C#, responsible for passing call requests and data between the two languages.

[0070] We use development tools (Visual Studio) to create a new C++ / CLI project. This project will contain C++ / CLI code for implementing interoperability between C++ and C#. In the C++ / CLI project, a wrapper function is implemented for each C++ function. This wrapper function will call the function in the C++ dynamic link library and call the corresponding C# function according to the reflection relationship.

[0071] Set the properties of the C++ / CLI project to ensure that it can correctly link the C++ dynamic link library and the C# assembly. Preferably, the reference path can be set, the CLR support can be configured, etc.

[0072] Compile the C++ / CLI project to generate a dynamic link library. This DLL will contain C++ / CLI wrapper functions for implementing interoperability between C++ and C#.

[0073] The core function of the C++ / CLI dynamic link library constructed above is to realize the interoperation between the C++ dynamic link library and the C# function. Specifically, it is responsible for the following tasks:

[0074] Calling C# functions: When C++ code needs to call C# functions, the C++ / CLI DLL will find the corresponding C# functions according to the global mapping relationship and call them.

[0075] Data conversion: When data is passed between C++ and C#, the C++ / CLI DLL will be responsible for data type conversion. For example, converting int in C++ to int in C#, and converting char* in C++ to string in C#.

[0076] Error handling: The C++ / CLI DLL will also be responsible for handling errors that may occur during cross-language calls, such as type mismatch, function not found, etc.

[0077] It can be understood that through the C++ / CLI dynamic link library, C++ and C# can seamlessly call functions and pass data. This allows developers to easily use high-performance computing functions provided by C++ in C#, and to call advanced functions provided by C# in C++, such as graphical interfaces and network communications. Through the global mapping relationship, C# developers can call C++ functions as if they were calling local functions, without worrying about the underlying implementation details. This greatly simplifies the complexity of cross-language calls and improves development efficiency. In addition, users can freely define the C++ functions and C# functions to be called through a configuration file without modifying the code. This allows users to easily extend and modify the called functions without recompiling the code.

[0078] Based on the above step S102, we effectively realize the interoperation between the C++ dynamic link library and the C# function, so as to fully exert the advantages of the two languages and meet the complex application requirements.

[0079] Step S103: When the user uses the C# function configuration, receive the user's configuration file, and the C++ / CLI dynamic link library initializes the configuration according to the corresponding program calling occasion and target C# function obtained from the configuration file. When the program calling occasion is met, determine the C# function corresponding to the current program calling occasion according to the C++ / CLI dynamic link library, call the C# function, and call the original C++ function through the C++ dynamic link library inside the C# function to realize interface calling. The program calling occasion is the trigger condition for the C++ application to call the C# function.

[0080] Optionally, in this embodiment, this step is the interaction process when the user programs on the C# side and wants to interact with the C++ application.

[0081] When the user configures the C# function, they provide a configuration file. The format of the configuration file can be XML, JSON, or other easily parsed formats. The C++ / CLI dynamic link library is responsible for receiving and parsing this configuration file, extracting the key information.

[0082] Specifically, the structure and content of the configuration file are defined to ensure that it contains all necessary information. For example, the configuration file contains the name of the C# function, the parameter list, the return type, and the conditions for triggering the call. The C++ / CLI dynamic link library receives the user-provided configuration file through a file path parameter, network transmission, or other means during the initialization phase. Then use parsing tools (such as XML parser or JSON parser) to read the content of the configuration file and convert it into internal data structures. For example, extract the function name and parameter type from the configuration file and store them in a hash table or list in memory.

[0083] After parsing the configuration file, the C++ / CLI dynamic link library needs to extract the program call timing and target C# function information from the configuration file. These information will be used to initialize the configuration to ensure that the correct C# function is called at the appropriate time.

[0084] Specifically, read the description of the program call timing from the configuration file. The call timing can be a specific event, condition, or time point. For example, the call timing can be "when the user clicks the button" or "when the system starts". Read the detailed information of the target C# function from the configuration file, including function name, parameter type, return type, etc. These information will be used to find and call the corresponding C# function at runtime. Store the extracted call timing and target C# function information in the internal data structure of the C++ / CLI dynamic link library. The internal data structure includes setting event listeners, condition checkers, or timers, etc. to ensure that the C# function call is triggered at the appropriate time.

[0085] During the running of the C++ application, when the call timing defined in the configuration file is met, the C++ / CLI dynamic link library needs to determine the C# function corresponding to the current C++ function call. This step ensures that the correct C# function is called at the appropriate time.

[0086] Specifically, the C++ / CLI dynamic link library continuously monitors the running state of the program and detects whether the calling opportunity defined in the configuration file is met. The continuous monitoring program involves event listening, condition checking, or timing triggering mechanisms. When the calling opportunity is detected, the C++ / CLI dynamic link library finds the C# function corresponding to the current program calling C++ function. According to the parameter type of the C# function, the corresponding parameter value is obtained from the C++ application. This involves data type conversion and parameter wrapping operations to ensure that the parameters can be correctly passed between C++ and C#.

[0087] After determining the corresponding C# function and preparing the calling parameters, the C++ / CLI dynamic link library will call the C# function. Inside the C# function, the original C++ function will be further called back through the C++ / CLI dynamic link library, thereby realizing the complete interface call.

[0088] Specifically, the C++ / CLI dynamic link library uses reflection or other mechanisms to call the target C# function. During the calling process, the prepared parameters are passed to the C# function. After receiving the calling request, the C# function executes its internal logic, including data processing, business logic execution, and other operations. Inside the C# function, the original C++ function is called back through the C++ / CLI dynamic link library as needed, allowing the C# function to call the C++ provided functionality during execution, thereby realizing deep interoperation between C++ and C#. After the C# function is executed, the result is returned to the C++ / CLI dynamic link library. The C++ / CLI dynamic link library then passes the result back to the C++ application, completing the entire interface calling process.

[0089] It can be understood that through the configuration file, users can dynamically define the calling opportunity and target function of the C# function without modifying the code. This enables the system to flexibly adapt to different runtime requirements without the need for recompilation and deployment of code. This greatly improves the flexibility and scalability of the system, making it easier for developers to implement complex functional requirements.

[0090] This example demonstrates how the present embodiment implements a flexible, efficient, and robust cross-language calling mechanism by building C++ dynamic link libraries and C++ / CLI dynamic link libraries, enabling C++ and C# to seamlessly collaborate in complex business scenarios and meet the development needs of modern application programs.

[0091] From the above description, the interface calling method provided by the embodiments of the present application can extract interface C++ functions and structures to construct a target C++ interface by analyzing original C++ interfaces, standardize the target C++ interface, construct a C++ dynamic link library based on a calling pointer of original C++ interface data and the standardized interface, construct a C++ / CLI dynamic link library in a C++ application, when a user uses a C# function configuration, the C++ / CLI dynamic link library obtains corresponding program calling timing and target C# functions from a configuration file to perform initialization configuration, when the program calling timing is met, the C++ / CLI dynamic link library determines the C# functions corresponding to the C++ functions of the current program calling, calls the C# functions and calls back the original C++ functions in the C# functions through the C++ dynamic link library, and interface calling is implemented, thereby improving the efficiency and flexibility of interface calling.

[0092] In an embodiment of the interface calling method of the present application, the following content can also be specifically included:

[0093] Step S201: identifying functions and structures in original C++ interface data;

[0094] Step S202: extracting definition information of the functions and structures to determine corresponding target C++ interface data, wherein the definition information of the functions and structures includes function names, parameter types, return value types, and member variable types and names of structures.

[0095] Optionally, in the embodiment, the original C++ interface data is usually provided in the form of a header file or a dynamic link library, and the header file describes functions, structures and other elements that can be called by the outside in detail. The present solution first analyzes these data, and identifies function declarations and structure definitions and other key information from the read text by means of regular expression and other text analysis techniques. For example, when a function declaration is encountered, the regular expression can identify the return type of the function, the function name and the parameter list; for structure definition, it can extract the name of the structure and each member variable contained therein.

[0096] After the target interface data (function names, parameter types, return value types, etc.) that needs to be exposed to C# is extracted, the interface data (i.e., target C++ interface data) that needs to be wrapped is selected from the analysis results, including:

[0097] C++ functions: functions that need to be exposed to C# calling.

[0098] Structures: composite types for cross-language data transmission.

[0099] This step requires determining which functions and structures are needed based on the pre-set requirements. For example, if our goal is to implement a simple mathematical operation function, we may select the addition function and the structure for representing two-dimensional points from the numerous C++ interfaces. By searching for these specific names in the parsed data, we can accurately extract the function declarations and structure definitions needed for further processing.

[0100] Through step S202, the target C++ interface data is obtained in this embodiment, laying a solid data processing foundation for subsequent C# calling of C++ interfaces.

[0101] In an embodiment of the interface calling method of the present application, the following content can also be specifically included:

[0102] Step S301: defining a static variable for storing the calling entry of the original C++ interface data;

[0103] Step S302: constructing an initialization function to initialize the static variable and determine the corresponding calling pointer, so that the C# interface can access the original C++ interface through the calling pointer.

[0104] Optionally, in this embodiment, in C++, function calls are usually implemented through function pointers. In order to enable C# to call functions in C++, we need to define some static variables in the C++ code, which will store the calling entry of C++ functions. Specifically, these static variables are function pointers, which point to specific functions in C++.

[0105] Specifically, it is determined which C++ functions need to be called by C#. These functions are interface functions exposed by the C++ dynamic link library (DLL). A static variable is defined for each C++ function that needs to be called. The type of these static variables is function pointer, and its function signature is consistent with the corresponding C++ function. In the initialization phase of the program, these static variables are initialized to the address of the corresponding C++ function. In this way, C++ functions can be indirectly called through these static variables.

[0106] In order to ensure that C# can correctly call C++ functions, we need to implement an initialization function in the C++ code. The function of this initialization function is to initialize the previously defined static variables (function pointers) to the address of the corresponding C++ function.

[0107] Specifically, we create an initialization function whose purpose is to set the values of static variables. The function name is fixed, such as Initialize. In the initialization function, each static variable (function pointer) is set to the corresponding C++ function address. In this way, when the C# code calls the function through these static variables, it is actually calling the specific function in C++. Ensure that the initialization function can be called by C# code, and export the function in the C++ DLL so that C# code can call it through a specific mechanism (DllImport).

[0108] Through step S302, the embodiment obtains a calling pointer by defining a static variable and initializing it as a function pointer, provides a stable calling interface for C++ functions, so that C# code can indirectly call C++ functions through these static variables without directly handling function addresses, which makes the calling process more secure and stable.

[0109] In an embodiment of the interface calling method of the present application, the following content can also be specifically included:

[0110] Step S401: determining a C#-compatible intermediate layer function declaration according to the standardized C++ interface data;

[0111] Step S402: binding the calling pointer to the intermediate layer function declaration to generate a C++ exported function with a unified calling specification, and determining a corresponding C++ dynamic link library based on the exported function.

[0112] Optionally, in the embodiment, when wrapping the C++ interface into a form that can be called by C#, a group of C#-compatible intermediate layer function declarations need to be defined first according to the standardized C++ interface data (i.e. the interface data after type conversion and adjustment). The role of these intermediate layer functions is to serve as a bridge between C++ and C#, ensuring smooth function calling and data interaction between the two languages.

[0113] Specifically, the C++ interface data after type conversion and adjustment is reviewed to determine the parameter type, return type, and calling convention of each function. According to the above analysis results, a group of new function declarations are defined, which match the requirements of C# in terms of parameter type and return type, and follow the calling convention (such as __stdcall or __cdecl) that C# can recognize. For example, if a C++ function has a return type of int and parameter types of int and float, the corresponding intermediate layer function declaration should also have the same return type and parameter types, but the calling convention may need to be adjusted to adapt to C#.

[0114] Optionally, in this embodiment, after the intermediate layer function declarations compatible with C# are defined, the aforementioned call pointers (i.e. the pointers to the original C++ functions) need to be bound to the intermediate layer function declarations. The purpose of this is to generate a set of C++ exported functions with unified calling specifications, which can be directly called by C# code.

[0115] Specifically, for each intermediate layer function declaration, it is bound to the corresponding call pointer. When the C# code calls the intermediate layer function, it actually indirectly calls the original C++ function through the call pointer. This binding can be achieved by writing corresponding wrapper functions in C++ code, which internally use the call pointer to call the original C++ function. In C++ code, use specific export macros to export the bound intermediate layer function declarations as exported functions in the C++ dynamic link library (DLL).

[0116] Finally, according to the generated C++ exported functions with unified calling specifications, the corresponding C++ dynamic link library is determined. In the C++ development environment, create a DLL project and add the relevant C++ source code files to the project, and compile the C++ code containing the intermediate layer function implementation and exported function declarations into a dynamic link library.

[0117] Through step S403, this embodiment successfully realizes cross-language calling between C++ and C# by defining intermediate layer function declarations compatible with C# and binding call pointers to these declarations to generate exported functions.

[0118] In an embodiment of the interface calling method of the present application, the following content can also be specifically included:

[0119] Step S501: When the program calling opportunity is met, the C++ / CLI dynamic link library receives a call request and determines the corresponding call identifier, wherein the call request is a C++ call request of a C++ application program.

[0120] Step S502: According to the reflection mechanism, query the C# function associated with the call identifier in the preset C# dynamic link library.

[0121] Optionally, in this embodiment, when the program calling opportunity is met, the C++ / CLI dynamic link library receives a call request from a C++ application program and determines the corresponding call identifier. This step is the key hub of cross-language calling, ensuring that the C++ application program can correctly trigger the logical execution of the C# side.

[0122] During the execution of a C++ application, a request for calling is initiated at a specific logical point (e.g. user operation, timed task or event trigger). Since C++ itself cannot directly call managed code (C#), a C++ / CLI dynamic link library is needed as a bridge. The dynamic link library adopts a hybrid compilation mode, which can be directly called by C++ and loaded with CLR (Common Language Runtime) to support the interaction of managed code.

[0123] Specifically, the C++ application sends a request to the C++ / CLI layer through a function pointer, a callback mechanism or an explicit interface call; after receiving the request, the C++ / CLI layer parses the parameters and extracts the call identifier (e.g. function name, event ID or predefined enumeration value). The identifier is used to uniquely determine the target C# function, and its format can be a string (e.g. "CalculateSum"), an integer ID (e.g. 1001) or more complex structured data (e.g. JSON key-value pair). The generation rule of the identifier can be defined in a configuration file (e.g. XML) to ensure that C++ and C# can consistently parse it.

[0124] Specifically, the C++ / CLI layer converts the original data types of C++ into CLR-compatible types.

[0125] Through the above steps, the C++ application does not need to be aware of the existence of C#, and can trigger the logic of managed code by only calling the standard C++ interface. The decoupling design of the call identifier enables C++ and C# to evolve independently, as long as the compatibility of the identifier is ensured.

[0126] Optionally, in the embodiment, the C# function associated with the call identifier is queried in the preset C# dynamic link library (DLL) based on the reflection mechanism. This step realizes dynamic binding, allowing the C# side to flexibly extend the function without modifying the C++ code.

[0127] The triggering of reflection depends on the following inputs: call identifier, preset C# DLL path, XML configuration binding rule. The reflection mechanism decouples the caller and the callee, and both sides only need to rely on the identifier protocol rather than the specific implementation.

[0128] Based on the above steps, the user only needs to write the C# function according to the agreement and update the configuration file to add new functions without recompiling the C++ code, and at the same time supports loading different DLLs at runtime, which is suitable for plug-in architecture or hot update scenarios.

[0129] Through the S502 step, the embodiment constitutes the core link of cross-language dynamic calling, which first solves the problem of request transmission from C++ to C#, and then realizes flexible function binding through reflection. This design not only guarantees performance, but also greatly improves the scalability and maintainability of the system.

[0130] In an embodiment of the interface calling method of the present application, the following can also be included:

[0131] Step S601: creating a managed code proxy according to the C++ / CLI dynamic link library;

[0132] Step S602: converting the calling request into a dynamic call to the C# function according to the managed code proxy.

[0133] Optionally, in the embodiment, the managed code proxy is a bridge between the C++ / CLI layer and the C# managed code.

[0134] Specifically, the managed code proxy is responsible for:

[0135] encapsulating cross-language calling details, and hiding the complex logic of data type conversion, memory management, etc. between C++ and C#;

[0136] providing a unified calling interface: enabling the C++ application to trigger the C# function in a consistent manner without needing to care about the underlying implementation.

[0137] supporting dynamic binding: in combination with the reflection mechanism, the proxy can adapt to different C# functions, and achieve flexible calling.

[0138] The creation of the managed code proxy includes the following steps:

[0139] First, the target C# function is obtained according to the calling request received by the C++ / CLI layer;

[0140] Then, if the target C# function is an instance method (not static), an instance of the class to which it belongs is dynamically created through Activator.CreateInstance; if it is a static method, the instantiation step is directly skipped.

[0141] Finally, the calling logic is encapsulated, the C++ parameters are converted into CLR compatible types, and the managed code proxy is implemented.

[0142] Optionally, in the embodiment, the dynamic call is the last step of cross-language interaction, and its core task is to seamlessly pass the C++ request to the C# function and return the result.

[0143] The specific steps include:

[0144] parameter passing and conversion: arranging the encapsulated CLR parameters according to the signature of the target C# function;

[0145] method call execution: calling the target function through MethodInfo.Invoke, and passing in the instance (if it is an instance method) and the parameter array;

[0146] Return value processing, convert C# return value to C++ compatible type.

[0147] In addition, if the C# function needs to call back the C++ code, the agent layer can encapsulate the C++ function pointer as a managed delegate.

[0148] Through the S602 step, the embodiment successfully completes the request conversion and dynamic calling from C++ to C#. While maintaining high performance, it provides high flexibility and maintainability, which is suitable for complex cross-language integration scenarios.

[0149] In an embodiment of the interface calling method of the present application, the following contents can also be specifically included:

[0150] Step S701: Create a class library project using Visual Studio, select C++ / CLI language type, and determine the corresponding C++ / CLI dynamic link library;

[0151] Step S702: Load the C++ / CLI dynamic link library to initialize the common language runtime environment when the C++ application starts, so that the C# code can be executed in the C++ process.

[0152] Optionally, in the embodiment, when the C++ application starts, a special module, namely the C++ / CLI hybrid compilation module, needs to be loaded. This module is written in C++ / CLI, which combines the high-performance characteristics of C++ and the.NET framework support of C#. The purpose of loading this module is to initialize the common language runtime (CLR) environment, so that the C# code can be executed smoothly in the C++ process.

[0153] First, create a C++ / CLI project using Visual Studio, which will contain code for initializing the CLR environment and managing global mapping relationships. In the C++ / CLI project, configure the necessary properties to ensure that it can correctly load the CLR runtime, including setting the CLR support options and specifying the required.NET framework version. In the startup code of the C++ application, add logic to load the C++ / CLI module by calling Windows API functions or using the dynamic loading mechanism of C++.

[0154] Once the C++ / CLI module is loaded, it will be responsible for initializing the common language runtime (CLR) environment. CLR is the core component of the.NET framework, which provides runtime services such as memory management, exception handling, and security checks, so that managed code (such as C# code) can run in it.

[0155] Then, in the C++ / CLI module, the startup function of CLR is called to initialize the CLR environment and set the configuration parameters of CLR. After initializing CLR, the assembly containing C# code is loaded by calling the load assembly function of CLR. After loading the C# assembly, C# object instances can be created. This can be done through the reflection mechanism, specifying the name of the C# class and the constructor parameters.

[0156] By loading the C++ / CLI module and initializing the CLR environment, C++ code can execute C# code in a C++ process, and vice versa. This enables seamless collaboration between C++ and C# code, fully leveraging the strengths of both languages.

[0157] Through the S702 step, the C++ / CLI dynamic link library is successfully built, providing a good running environment and mapping relationship between C++ and C#, laying a solid foundation for subsequent interface calls.

[0158] In order to improve the efficiency and flexibility of interface calls, the present application provides an embodiment of an interface calling device for implementing all or part of the contents of the interface calling method, see Figure 2 , which specifically includes the following contents:

[0159] The C++ dynamic link library determination module 10 is used to parse the original C++ interface data, extract the corresponding target C++ interface data, standardize the function type of the target C++ interface data according to the preset C# function type conversion rule, determine the corresponding standardized C++ interface data, store the calling entry of the original C++ interface data as a calling pointer in the form of a static variable, and determine the corresponding C++ dynamic link library according to the calling pointer and the standardized C++ interface data, wherein the target C++ interface data includes C++ functions and structures;

[0160] The C++ / CLI dynamic link library determination module 20 is used to build a C++ / CLI dynamic link library, wherein the C++ / CLI dynamic link library initializes the common language runtime environment operation when the C++ application starts, and ensures the interoperability of C# functions and C++ functions through dynamic loading of C# functions and reflection binding functions.

[0161] The interface calling module 30 is configured to receive a configuration file of a user when the user uses a C# function, the C++ / CLI dynamic link library is configured to initialize a corresponding program calling time and a target C# function from the configuration file, when the program calling time is met, the C++ / CLI dynamic link library is configured to determine a C# function corresponding to the current program calling time, the C# function is called and the original C++ function is called back through the C++ dynamic link library in the C# function, and the interface calling is implemented.

[0162] As can be seen from the above description, the interface calling device provided by the embodiment of the present application can extract an interface C++ function and a structure body to construct a target C++ interface by analyzing an original C++ interface, standardize the target C++ interface, construct a C++ dynamic link library based on a calling pointer of the original C++ interface data and the standardized interface, construct a C++ / CLI dynamic link library in a C++ application program, when a user uses a C# function, the C++ / CLI dynamic link library obtains a corresponding program calling time and a target C# function from a configuration file to initialize configuration, when the program calling time is met, the C++ / CLI dynamic link library determines a C# function corresponding to the current program calling time, the C# function is called and the original C++ function is called back through the C++ dynamic link library in the C# function, and the interface calling is implemented, thereby improving the efficiency and flexibility of the interface calling.

[0163] In order to further illustrate the present application, a specific application example of an interface calling method using the above interface calling device is provided, which specifically includes the following contents.

[0164] Some C++ interfaces of the software are originally opened to the outside for external calling. A user writes a C++ dynamic link library to call the interface, and at the same time, the user also exposes an interface, and the software can also call the interface written by the user. That is, the entire calling process is: the software itself -> user interface -> interface exposed by the software. For example, the software itself provides some interfaces, such as addition and multiplication. The user can use these interfaces and perform mixed operations, and at the same time, the mixed operation interface is reversely exposed to the software, and the software can perform mixed operations according to the needs of the client.

[0165] The current target is to replace the C++ dynamic link library written by the client with C#.

[0166] Firstly, the C# calls the C++ method, because the C# runtime itself supports calling native methods. However, the previous C# interface is a COM interface, and all the interfaces are encapsulated into a class object, and the calling is implemented through the header file introduction and the inheritance of the C++ class. Under this design, the C# program cannot directly inherit the class object of the C++.

[0167] Therefore we can first encapsulate a pure C++ DLL, dedicated to provide C# call. The C++ DLL inside only store functions, structure. Therefore will not produce let C # inherit from C ++ class object problem. At the same time, the DLL can also solve certain variable type mapping problem. The implementation of the DLL is roughly as follows: (1) in the form of static variables store C++ pointer, pointer on the original interface can be called. (2) provide an initialization function, name fixed, waiting for C# end call, and the pointer initialization (3) according to the variable mapping requirements, all functions are wrapped (this step can use automation script batch generation)

[0168] Because the software itself is a C++ application, it has no "common language runtime" (CLR), so we need to call a new DLL at the right time, take C++ / CLI hybrid compilation (solve cross language call problem), start the environment to provide and software body interaction function, and use dictionary to record which C# function needs to be called

[0169] User written functions need a call time. That is, the need for a user function and software itself button binding relationship. Just, we are C#, in C++ / CLI code, can use reflection to dynamically find dll, class name, function name, so you can find any function. And the user only need to pre write the function they want to be called, into an XML configuration file, so the software can read this relationship, and can call

[0170] Through XML, the user can configure in advance, improve flexibility. So the user's code does not have to comply with a certain specific architecture or name fixed. Through C++ wrapping original interface, shielding the complexity of the original interface, and use automatic generation technology here, as long as the original interface has changed, can immediately respond.

[0171] From the hardware level, in order to improve the efficiency and flexibility of interface call, the present application provides an embodiment of an electronic device for implementing all or part of the contents of the interface call method, the electronic device specifically contains the following contents:

[0172] A processor, a memory, a communications interface, and a bus; wherein the processor, the memory, the communications interface complete the communication among each other through the bus; the communications interface is used for realizing the information transmission between the interface calling method and the core business system, the user terminal, and the related database and other related devices; the logic controller can be a desktop computer, a tablet computer, a mobile terminal, and the like, and the embodiment is not limited thereto. In the embodiment, the logic controller can be implemented with reference to the embodiments of the interface calling method and the embodiments of the interface calling method, the contents of which are incorporated herein, and the repeated parts are not described herein.

[0173] It can be understood that the user terminal can include a smart phone, a tablet electronic device, a network set-top box, a portable computer, a desktop computer, a personal digital assistant (PDA), a vehicle-mounted device, a smart wearable device, and the like. The smart wearable device can include smart glasses, a smart watch, a smart bracelet, and the like.

[0174] In actual application, part of the interface calling method can be executed on the electronic device as described above, or all operations can be completed in the client device. Specifically, the selection can be made according to the processing capability of the client device and the limitation of the user usage scenario, and the like. The present application is not limited thereto. If all operations are completed in the client device, the client device can further include a processor.

[0175] The client device described above can have a communication module (i.e., a communication unit) and can be communicatively connected with a remote server to realize the data transmission with the server. The server can include a server of the task scheduling center side, and the server of the intermediate platform side can also be included in other implementation scenarios, for example, the server of the third-party server platform communicatively connected with the server of the task scheduling center. The server can include a single computer device, a server cluster composed of multiple servers, or a server structure of a distributed device.

[0176] Figure 3 A schematic block diagram of a system configuration of the electronic device 9600 of the embodiment of the present application is shown in FIG. 9. As shown in FIG. 9, the electronic device 9600 can include a central processor 9100 and a memory 9140; the memory 9140 is coupled to the central processor 9100. It is worth noting that the structure shown in FIG. 9 is exemplary; other types of structures can also be used to supplement or replace the structure to realize the telecommunication function or other functions. Figure 3 Figure 3 The structure shown in FIG. 9 is exemplary; other types of structures can also be used to supplement or replace the structure to realize the telecommunication function or other functions.

[0177] ​In an embodiment, the interface calling method function can be integrated into the central processor 9100. The central processor 9100 can be configured to control as follows:

[0178] Step S101: parse the original C++ interface data, extract the corresponding target C++ interface data, standardize the function type of the target C++ interface data according to the preset C# function type conversion rule, determine the corresponding standardized C++ interface data, store the calling entry of the original C++ interface data as a calling pointer in the form of a static variable, determine the corresponding C++ dynamic link library according to the calling pointer and the standardized C++ interface data, wherein the target C++ interface data includes C++ functions and structures;

[0179] Step S102: build a C++ / CLI dynamic link library, wherein the C++ / CLI dynamic link library initializes the common language runtime environment operation when the C++ application starts, ensures the interoperability of C# functions and C++ functions by dynamically loading C# functions and reflecting binding functions;

[0180] Step S103: when the user configures using a C# function, receive the user's configuration file, the C++ / CLI dynamic link library obtains the corresponding program calling occasion and target C# function from the configuration file for initialization configuration, when the program calling occasion is met, determines the C# function corresponding to the current program calling occasion according to the C++ / CLI dynamic link library, calls the C# function and calls the original C++ function through the C++ dynamic link library inside it to realize interface calling, wherein the program calling occasion is the trigger condition for the C++ application to call the C# function.

[0181] From the above description, the electronic device provided by the embodiments of the present application can parse the original C++ interface, extract the interface C++ function and structure to build the target C++ interface, standardize the target C++ interface, and based on the calling pointer of the original C++ interface data and the standardized interface, build a C++ dynamic link library; build a C++ / CLI dynamic link library in a C++ application; when the user configures using a C# function, the C++ / CLI dynamic link library obtains the corresponding program calling occasion and target C# function from the configuration file for initialization configuration, when the program calling occasion is met, determines the C# function corresponding to the current program calling occasion according to the C++ / CLI dynamic link library, calls the C# function and calls the original C++ function through the C++ dynamic link library inside it to realize interface calling, thereby improving the efficiency and flexibility of interface calling.

[0182] In another implementation, the interface calling method can be configured separately from the central processing unit 9100. For example, the interface calling method can be configured as a chip connected to the central processing unit 9100, and the interface calling method function can be implemented through the control of the central processing unit.

[0183] like Figure 3 As shown, the electronic device 9600 may further include: a communication module 9110, an input unit 9120, an audio processor 9130, a display 9160, and a power supply 9170. It is worth noting that the electronic device 9600 does not necessarily need to include these components. Figure 3 All components shown; in addition, the electronic device 9600 may also include Figure 3 For components not shown, please refer to existing technologies.

[0184] like Figure 3 As shown, the central processing unit 9100, sometimes also referred to as a controller or operating control, may include a microprocessor or other processor device and / or logic device, which receives inputs and controls the operation of various components of the electronic device 9600.

[0185] The memory 9140 may be, for example, one or more of a cache, flash memory, hard drive, removable media, volatile memory, non-volatile memory, or other suitable devices. It may store the aforementioned failure-related information, and also store a program for executing that information. The central processing unit 9100 may execute the program stored in the memory 9140 to perform information storage or processing, etc.

[0186] Input unit 9120 provides input to central processing unit 9100. Input unit 9120 may be, for example, a keypad or touch input device. Power supply 9170 provides power to electronic device 9600. Display 9160 displays images and text. Display may be, for example, an LCD display, but is not limited thereto.

[0187] The memory 9140 can be a solid-state memory, such as a read-only memory (ROM), random access memory (RAM), a SIM card, etc. It can also be a memory that retains information even when power is off, can be selectively erased, and contains more data; examples of this type of memory are sometimes referred to as EPROMs. The memory 9140 can also be some other type of device. The memory 9140 includes a buffer memory 9141 (sometimes referred to as a buffer). The memory 9140 may include an application / function storage unit 9142 for storing application programs and function programs or processes for executing the operation of the electronic device 9600 via the central processing unit 9100.

[0188] The memory 9140 can further include a data storage 9143 for storing data such as contacts, digital data, pictures, sounds, and / or any other data used by the electronic device. A driver storage 9144 of the memory 9140 can include various drivers of the electronic device for communication functions and / or for performing other functions of the electronic device (e.g., a messaging application, a phonebook application, etc.).

[0189] The communication module 9110 is a transmitter / receiver that transmits and receives signals via the antenna 9111. The communication module 9110 is coupled to the central processor 9100 to provide input signals and receive output signals, as in the case of a conventional mobile communication terminal.

[0190] Based on different communication technologies, a plurality of communication modules 9110 can be provided in the same electronic device, such as a cellular network module, a Bluetooth module, and / or a wireless local area network module, etc. The communication module 9110 is further coupled to the speaker 9131 and the microphone 9132 via the audio processor 9130 to provide audio output via the speaker 9131 and receive audio input from the microphone 9132, thereby implementing a conventional telecommunication function. The audio processor 9130 can include any suitable buffer, decoder, amplifier, etc. In addition, the audio processor 9130 is further coupled to the central processor 9100, thereby enabling recording on the local device via the microphone 9132 and playing stored sound on the local device via the speaker 9131.

[0191] The embodiment of the present application further provides a computer readable storage medium capable of implementing all steps of the interface calling method in the above-mentioned embodiment in which the execution subject is a server or a client, wherein the computer readable storage medium stores a computer program, and the computer program is executed by a processor to implement all steps of the interface calling method in the above-mentioned embodiment in which the execution subject is a server or a client, for example, the processor implements the following steps when executing the computer program:

[0192] Step S101: parsing original C++ interface data, extracting corresponding target C++ interface data, standardizing function types of the target C++ interface data according to a preset C# function type conversion rule, determining corresponding standardized C++ interface data, storing a calling entry of the original C++ interface data in the form of a static variable as a calling pointer, determining corresponding C++ dynamic link library according to the calling pointer and the standardized C++ interface data, wherein the target C++ interface data includes C++ functions and structures;

[0193] Step S102: constructing a C++ / CLI dynamic link library, wherein the C++ / CLI dynamic link library initializes a common language runtime environment operation at startup of the C++ application, ensures interoperability of C# functions and C++ functions by dynamically loading C# functions and reflecting binding functions;

[0194] Step S103: when a user configures using a C# function, receiving a configuration file of the user, the C++ / CLI dynamic link library obtains a corresponding program calling time and a target C# function from the configuration file to perform initialization configuration, when the program calling time is met, determining a C# function corresponding to the current program calling time according to the C++ / CLI dynamic link library, calling the C# function and calling the original C++ function in the C++ dynamic link library to realize interface calling, wherein the program calling time is a trigger condition for the C++ application to call the C# function.

[0195] From the above description, the computer readable storage medium provided by the embodiments of the present application can be known, by analyzing the original C++ interface, extracting the interface C++ function and the structure to construct the target C++ interface, after standardizing the target C++ interface, based on the calling pointer of the original C++ interface data and the standardized interface, constructing the C++ dynamic link library; constructing the C++ / CLI dynamic link library in the C++ application; when the user configures using the C# function, the C++ / CLI dynamic link library obtains the corresponding program calling time and the target C# function from the configuration file to perform initialization configuration, when the program calling time is met, determining the C# function corresponding to the C++ function of the current program calling according to the C++ / CLI dynamic link library, calling the C# function and calling the original C++ function in the C++ dynamic link library to realize interface calling, thereby the efficiency and flexibility of interface calling can be improved.

[0196] The embodiments of the present application also provide a computer program product capable of realizing all steps of the interface calling method in the above-mentioned embodiments, wherein the computer program / instruction is executed by the processor to realize the steps of the interface calling method, for example, the computer program / instruction realizes the following steps:

[0197] Step S101: analyzing the original C++ interface data, extracting the corresponding target C++ interface data, standardizing the function type of the target C++ interface data according to a preset C# function type conversion rule, determining the corresponding standardized C++ interface data, storing the calling entry of the original C++ interface data as a calling pointer in the form of a static variable, and determining the corresponding C++ dynamic link library according to the calling pointer and the standardized C++ interface data, wherein the target C++ interface data includes C++ functions and structures;

[0198] Step S102: constructing a C++ / CLI dynamic link library, wherein the C++ / CLI dynamic link library initializes a common language runtime environment operation at startup of the C++ application, ensures interoperability of C# functions and C++ functions through dynamic loading of C# functions and reflection binding functions;

[0199] Step S103: when a user uses C# function configuration, receiving a configuration file of the user, the C++ / CLI dynamic link library obtains a corresponding program calling time and a target C# function from the configuration file to perform initialization configuration, when the program calling time is met, determining a C# function corresponding to the current program calling time according to the C++ / CLI dynamic link library, calling the C# function and calling the original C++ function through the C++ dynamic link library in the C# function to realize interface calling, wherein the program calling time is a trigger condition for which the C++ application needs to call the C# function.

[0200] From the above description, it can be known that the computer program product provided by the embodiment of the present application can realize interface calling by analyzing an original C++ interface, extracting interface C++ functions and structures to construct a target C++ interface, constructing a C++ dynamic link library based on a calling pointer of the original C++ interface data and the standardized interface after standardizing the target C++ interface, constructing a C++ / CLI dynamic link library in a C++ application, when a user uses C# function configuration, the C++ / CLI dynamic link library obtains a corresponding program calling time and a target C# function from a configuration file to perform initialization configuration, when the program calling time is met, determining a C# function corresponding to the current program calling time according to the C++ / CLI dynamic link library, calling the C# function and calling the original C++ function through the C++ dynamic link library in the C# function to realize interface calling, thereby improving the efficiency and flexibility of interface calling.

[0201] Those skilled in the art should understand that the embodiments of the present application can be provided as a method, device, or computer program product. Therefore, the present application can adopt a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can adopt a computer program product in the form of being implemented on one or more computer usable storage media (including but not limited to disk memory, CD-ROM, optical memory, etc.) containing computer usable program codes.

[0202] The computer program instructions can also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart block or blocks. Figure 1 one or more flowcharts and / or blocks Figure 1 one or more flowcharts and / or blocks

[0203] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instructions which implement the function specified in the flowchart block or blocks. Figure 1 one or more flowcharts and / or blocks Figure 1 one or more flowcharts and / or blocks

[0204] The computer program instructions can also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart block or blocks. Figure 1 one or more flowcharts and / or blocks Figure 1 one or more flowcharts and / or blocks

[0205] The principles and implementations of the present application are described in the specific embodiments of the present application, the above description of the embodiments is only 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, the specific implementation and application range will be changed, and the above description of the present application should not be understood as the limitation of the present application.

Claims

1. An interface invocation method, characterized in that, Applied to C++ applications, the method includes: Parse the original C++ interface data, extract the corresponding target C++ interface data, standardize the function types of the target C++ interface data according to the preset C# function type conversion rules, determine the corresponding standardized C++ interface data, store the call entry point of the original C++ interface data as a call pointer in the form of a static variable, and determine the corresponding C++ dynamic link library based on the call pointer and the standardized C++ interface data. The target C++ interface data includes C++ functions and structures. A C++ / CLI dynamic link library is constructed, wherein the C++ / CLI dynamic link library initializes the Common Language Runtime Environment when the C++ application starts, and ensures the interoperability between C# functions and C++ functions by dynamically loading C# functions and binding functions through reflection; When a user configures using C# functions, the system receives the user's configuration file. The C++ / CLI dynamic link library retrieves the corresponding program invocation timing and target C# function from the configuration file for initialization. When the program invocation timing is met, the system determines the C# function corresponding to the current program invocation timing based on the C++ / CLI dynamic link library, calls the C# function, and internally calls back the original C++ function through the C++ dynamic link library to implement the interface call. The program invocation timing is the triggering condition for the C++ application to call the C# function.

2. The interface calling method according to claim 1, characterized in that, The process of parsing the original C++ interface data and extracting the corresponding target C++ interface data includes: Identify functions and structures in raw C++ interface data; Extract the definition information of the functions and structures to determine the corresponding target C++ interface data. The definition information of the functions and structures includes the function name, parameter type, return value type, and the member variable type and name of the structure.

3. The interface calling method according to claim 1, characterized in that, The method of storing the call entry point of the original C++ interface data as a call pointer in the form of a static variable includes: Define a static variable to store the entry point for calling raw C++ interface data; Construct an initialization function to initialize the static variables and determine the corresponding call pointer so that the C# interface can access the original C++ interface through the call pointer.

4. The interface calling method according to claim 1, characterized in that, The step of determining the corresponding C++ dynamic link library based on the call pointer and the standardized C++ interface data includes: Based on the standardized C++ interface data, determine the intermediate layer function declarations that are compatible with C#; The call pointer is bound to the intermediate function declaration to generate a C++ exported function with a unified calling specification, and the corresponding C++ dynamic link library is determined based on the exported function.

5. The interface calling method according to claim 1, characterized in that, When the program invocation timing is met, determining the C# function corresponding to the current program invocation timing based on the C++ / CLI dynamic link library includes: When the program call timing is met, the C++ / CLI dynamic link library receives the call request and determines the corresponding call identifier, wherein the call request is a C++ call request from a C++ application; Based on the reflection mechanism, the C# function associated with the call identifier is queried in the preset C# dynamic link library.

6. The interface calling method according to claim 5, characterized in that, After querying the C# function associated with the call identifier in a preset C# dynamic link library based on reflection, the process includes: Create a managed code proxy based on the C++ / CLI dynamic link library; The managed code agent converts the call request into a dynamic call to the C# function.

7. The interface calling method according to claim 1, characterized in that, The construction of the C++ / CLI dynamic link library includes: To create a class library project using Visual Studio, select the C++ / CLI language type and determine the corresponding C++ / CLI dynamic link library. When a C++ application starts, the C++ / CLI dynamic link library is loaded to initialize the Common Language Runtime environment so that C# code can be executed within the C++ process.

8. An interface calling device, characterized in that, The device includes: The C++ dynamic link library determination module is used to parse the original C++ interface data, extract the corresponding target C++ interface data, standardize the function types of the target C++ interface data according to the preset C# function type conversion rules, determine the corresponding standardized C++ interface data, store the call entry of the original C++ interface data as a call pointer in the form of a static variable, and determine the corresponding C++ dynamic link library based on the call pointer and the standardized C++ interface data. The target C++ interface data includes C++ functions and structures. A C++ / CLI dynamic link library determination module is used to construct a C++ / CLI dynamic link library. The C++ / CLI dynamic link library initializes the Common Language Runtime Environment when the C++ application starts. It ensures the interoperability between C# functions and C++ functions by dynamically loading C# functions and binding functions through reflection. The interface call module is used to receive the user's configuration file when the user configures using C# functions. The C++ / CLI dynamic link library obtains the corresponding program call timing and target C# function from the configuration file for initialization configuration. When the program call timing is met, the C++ / CLI dynamic link library determines the C# function corresponding to the current program call timing, calls the C# function, and internally calls back the original C++ function through the C++ dynamic link library to realize the interface call. The program call timing is the trigger condition for the C++ application to call the C# function.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the steps of the interface invocation method according to any one of claims 1 to 7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the interface invocation method as described in any one of claims 1 to 7.