Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am generating a C++ static library with approximately 5 million functions. This library is linked in to an executable. I need to be able to call any number of these functions during run-time from an external application that will notify the executable containing these functions via a flag through shared memory.

I have an external .NET application that already knows all the function names and prototypes in the static library. Both applications have access to a shared memory location. I want my external application to be able to populate an array in shared memory that are pointers to the functions I want called by the C++ application. I cannot assign all of these function pointers to an array from the C++ application because the compile time would be too long.

Ultimately, I would like to generate a list of all the function names, and their offsets during compile time that I could parse using my external application. I could then parse them in my .NET application and pass them to the C++ application to be called.

Any help would be greatly appreciated.

Thanks.

What I have tried:

I have been using the Dia2lib.dll to parse the .PDB generated by the C++ static library, and am able to obtain the function names and offsets, but, this does not seem like a consistent and reliable method.  The project I am working on will be compiled on different platforms, and different OS versions, and the Dia2lib.dll seems to change enough that it just isn't going to work.
Posted
Updated 12-Mar-21 11:43am
Comments
BillWoodruff 12-Mar-21 18:34pm    
"with approximately 5 million functions ... compiled on different platforms, and different OS versions." This sounds like either science-fiction or madness.
KarstenK 13-Mar-21 4:28am    
Consult somebody who has the knowledage to rate your affords. I think that you are going the wrong way and waist your time.

1 solution

I don't think you can do that in shared memory for use by two applications. Pointers in one process will be useless to another process. The offsets can be placed in there though but I'm not sure what address you would use as a base.

You might be able to get the address of a "marker" function and then use it as a base address to use with the offsets you have loaded previously. I'm not sure this would work. I would have to do some experiments to verify it but seems like it could. To experiment, I would 'hard code' values for four or five functions and get their addresses. Then read the offsets from the file and see how they correlate. From there, you should be able to deduce the relationship of offsets to actual function addresses.

However, I think you need to use a linkage map from the application, not the library. The linker is going to place the functions at random locations that have no relationship to their offsets in the library because it is a static library. You need to get their offsets once they have been linked with the application.
 
Share this answer
 
Comments
BillWoodruff 12-Mar-21 18:29pm    
+5
Rick York 12-Mar-21 21:36pm    
Thank you sir.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900