First create a static library project in the same solution and turn on Common Language Runtime support. Don't turn on CLR support for the EXE project.
Add a class to the library project(.h + .cpp). Then add your necessary functions to the class and implement them only in the .cpp.
Note: You shouldn't use any .NET framework classes in .h file. For example, take a function
void ShowSomeMessageBox();
Let its implementation be,
void YourClassName::ShowSomeMessageBox()
{
System::Windows::Forms::MessageBox::Show("Hello World!");
}
Here the declaration doesn't of the method has no .NET objects as parameters. That is you can have data types like
char
,
int
or
std::string
as the parameters and not
System::String
for example.
After this, add reference to the library project in the EXE project properties. Then add the path where you've saved the header file. Then
#include
the header file. And you can use ShowSomeMessage() method without exposing your whole EXE project source to CLR.
Note: This trick will only work in Visual C++.