none
A simple c++ dll string export example RRS feed

  • Question

  • Hi,

    I am looking for a simple c++ dll example which exports a string. All the examples i see are for math.

    Does any one know a string export sample?

    Greatings, hans

    Thursday, January 2, 2020 9:02 AM

All replies

  • with "exports a string": do you mean a method that returns a System::String^?
    you would create a new project, either a "CLR Class Library (.NET Framework)" or "CLR Class Library (.NET Core)" 
    then add 
    using namespace System;
    
    namespace ClassLibrary1 {
    	public ref class Class1
    	{
    	public:
    		String^ GetAString()
    		{
    			return "Hello";
    		}
    	};
    }
    
    may I ask why you would want to use C++ to create a .NET assembly?
    Thursday, January 2, 2020 12:30 PM
  • Hi,

    I made a tool with c#. Now i want to avoid that some one can copy past everything with a decompiler. So i want to make a dll in c++ and put some functions in the dll. I do not want a .net c++ dll. i want a "real" c++ dll.

    wrong start i guess when i read you're answer.

    Greatings, Hans

    Friday, January 3, 2020 10:29 AM
  • You could use an obfuscator to protect the code in your C# assembly.

    But when you really want to go the way of a native C++ dll (which can of course be decompiled, too,
    just not as easily):
    Marshaling Data with Platform Invoke contains the example method
    char* TestStringAsResult()

    When you are more familiar with COM, you could also use a COM server to return a BSTR.
    • Edited by EckiS Friday, January 3, 2020 6:36 PM
    Friday, January 3, 2020 6:35 PM
  • Hi,

    Did you solve your problem? If your question has been answered then please click the "Mark as Answer" Link at the bottom of the correct post(s), so that it will help other members to find the solution quickly if they face a similar issue.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, January 10, 2020 3:12 AM
    Moderator