-1

I have a visual studio project called

"TopSecretProject"

that I want to share with an anonymous developer user, without revealing any of my code, including the header files (Since my .h files include the structure of my project ant the user cannot know about it).

The user should receive:

  1. A list of function names that he may call (depending on the permissions that the user has) and the user should be able to develop a program using these functions as black boxes.
  2. My sealed TopSecretProject, that he cannot open.

Is this scenario possible in any way?

I tried the following solution but failed:

  1. Exporting TopSecretProject as a static library.
  2. Creating a new VS project for the user, and adding the .lib to the user project.
  3. Copying all the .h files to the user's project and creating a pre compiled header file.
  4. removing the headers (now that I have the .pch I don't need them anymore)

The pre compiled header is rebuilt in any run and thus removing my first pre built pch... I also tried to copy the pch directly from the TopSecretProject but it didn't help.

Thanks very much in advance!!

Zorx
  • 28
  • 5
  • If you ask this question you'd better write _open source_ projects instead of _top secret_. – Lol4t0 Apr 25 '15 at 15:17
  • I don't understand your answer. Can you explain? – Zorx Apr 25 '15 at 15:19
  • Why do you want to hide the code? I don't think it is something _that_ important. And if you _share_ your code people will see it and help improve it. – Lol4t0 Apr 25 '15 at 15:23
  • Because it is not an open source project, it is intended for educational purposes and thus revealing the project reveals its solution. Can you help? – Zorx Apr 25 '15 at 15:51
  • I see. In this case the best solution is to provide service that will compile, run and test given code on your side. User will send their code to you, so you'll not spoil any code – Lol4t0 Apr 25 '15 at 16:15

1 Answers1

0

Any exported function declarations in the pre-compiled header, regardless of whether or not you want the end user to be able to call them, can be easily extracted from the pch (or the library, for that matter). You're only causing yourself headaches trying to deliver a pre-compiled header. :-)

Instead, how about creating a header file specifically for end users where the functions you want available to them are declared? The pitfall being you have to make a header file for each set of permissions (although is this more difficult than specifying the available functions for each set?)

Note, however, anyone could still look at your library's exported symbols if they wanted to try to use other features of the library.

Edit:

Regarding classes, if you really don't want to give the class declaration, you're stuck implementing some layer over the class for them to interact with. There's no getting around this. This probably means one of two paths:

One: You can declare some functions for creating, destroying, and using your classes and just pass back some good ole' void * pointers. e.g.

typedef void * MySecretClass;

MySecretClass initializeMSC( ... );
void freeMSC( MySecretClass cls );
int useMSC( MySecretClass cls, int param, ... );

Two: You can create a wrapper class that essentially does the same thing.

class MySecretClassWrapper
{
   public:
      MySecretClassWrapper( void );
      int useClass( int param );

   private:
      void * mySecretClassData; // <-- actual class instantiated here
};

And the compiled definitions:

MySecretClassWrapper::MySecretClassWrapper( void ) {
   mySecretClassData = reinterpret_cast<void *>(new MySecretClass);
}

int MySecretClassWrapper::useClass( int param ) {
   MySecretClass * object = reinterpret_cast<MySecretClass *>(mySecretClassData);
   return object ? object->useClass(param) : -1;
}

The first is a method I use when making C++ classes available to C applications. The second is the exact same idea but wrapped in a class which will be easier to use for C++ users.

Anthony
  • 2,256
  • 2
  • 20
  • 36
  • You are sure right about the pre-compiled header headache.. Thanks for that! I did what you recommended and it works great for functions, however I can't make it work for classes, unless I give the end users the entire class definition (which I don't want to give). Any suggestions on that? – Zorx Apr 25 '15 at 15:39
  • What a great answer, thank you. So my class is wrapped, but how can I wrap an implementation of some function in the class? function inside a class are using its fields and other functions, and the void * mySecretClassData doesn't know about them. Should I also add them to the wrapper as void* ? – Zorx Apr 25 '15 at 16:06
  • You just expose the functions you want as member functions of the class. Inside the function definitions (in the compiled .cpp not supplied to the end user) you typecast the void * pointer as your class type and just forward parameters and results to and from the class. Basically you just build a middleman interface to pass data around. – Anthony Apr 25 '15 at 16:11
  • I added a trivial example of a constructor and a member routine. It's a tedious exercise, but if you don't want to give away the class definition then you have to map all the class members. :-/ – Anthony Apr 25 '15 at 16:17
  • Your awesome, thank you! Works great. I used the c++ method that you suggested and also I wrapped any function that I wish to export. By the way, the static library that I give the end user, its considered sealed or should I do something about that as well? – Zorx Apr 25 '15 at 17:09
  • Like I mentioned, any function that's exported from the library, whether or not you want to give them access, is visible to anyone who knows how to extract exported symbols. (Or who has time for a five second Google search.) You can contrive a system of macros to conditionally export or not export functions for specific users, but then you have to rebuild the library for each set of permissions. That might become difficult to manage. It might be more pain than it's worth. – Anthony Apr 27 '15 at 01:35
  • Yes I understand that, what I meant is: could the end user access the actual implementation of the function and copy the actual implementation to its own use? – Zorx Apr 28 '15 at 07:02