Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically generate a C Win32 DLL

I need to repeatedly generate a Win32 DLL with a registration information function. This function uses literals to return customer specific registration information, with a separate DLL being built per customer.

I have a test version working correctly, with hard-coded information for one customer. The urgency for some sites dictates I generate some DLL's manually, but I would like to give the client an application that dynamically emits the C source and builds a DLL on demand.

What would be the the best way to do this? I have VS 2008 C++ Express, and thus the cl.exe compiler. My current approach would simply be to have a C# application with a string constant for the C source, and before generation, replace tokens in that with required parameters, then build and link by shelling out and running cl.exe.

like image 604
ProfK Avatar asked Aug 03 '26 11:08

ProfK


2 Answers

Put all customer information as string resources in a .rc file. Link the corresponding .res file into your DLL. All code in the DLL that depends on that customer information would call LoadString to fetch this.

Then build a seperate program (or function) called "UpdateDLL.exe" that uses the Win32 APIs: BeginUpdateResource, UpdateResource, etc... to update the DLL with the new information.

Ship the following:

  1. A pre-compiled DLL that has empty (or default) strings for the customer information in the resources.

  2. Your UpdateDLL.exe tool that takes the DLL name and customer info file as command line param.

  3. Your customer runs "UpdateDLL.exe customer.dll myinfo.txt" to update his copy of the DLL with his information.

like image 92
selbie Avatar answered Aug 05 '26 09:08

selbie


My generic idea is to have a program like this:

string UserName = "PLACEHOLDER UserName                     ";
string RegCode  = "PLACEHOLDER RegCode                      ";
bool CheckRegistration(string UserName, RegCode) {
  ...
}

Compile this to a .dll file. For each user, load the .dll file, find the two PLACEHOLDERs in it, and replace them the real user data. Make sure you pad the string with spaces.

like image 38
pts Avatar answered Aug 05 '26 08:08

pts