Since VC++ is compiled in CLR, it cannot achieve encryption effect. If you want to protect your code, it is recommended to use C++ for core algorithms and C# for interaction.


While making component library, considering database connection code might be decompiled, I used WCF to interact with server data in previous version, articles can be found in my previous posts. But recently learning QT and trying to use QT+C++ or VC++ development to see effect, so simply wrote a demo developed by c++. Reference link: C++ Revit Add-In Steps:

  1. Need to ensure CLI tools installed on our VS. If proceed directly according to above steps, no class library option requires us to install extra components. Click install: Tools - Get Tools and Features to install Image Description
  2. Create class library, input name and .netframework version, version corresponds to version required by RevitAPI Image Description
  3. Follow c# development method, add reference. In header file add transaction header, and add iexternalcommand interface, and write content in cpp file. But when adding [transation] cannot add via intellisense, not clear if it is my reason. Since c++ uses pointers, if accustomed to var variable, can use auto instead. Code class just add ^ symbol. Others just follow c++ writing style to realize c++ for revit secondary development.

Code: header

#pragma once

using namespace System;
using namespace Autodesk::Revit::Attributes;


namespace ClassLibrary3 {
	
	[Autodesk::Revit::Attributes::Transaction(
		Autodesk::Revit::Attributes::TransactionMode::Manual)]

	[Autodesk::Revit::Attributes::Regeneration(
		Autodesk::Revit::Attributes::RegenerationOption::Manual)]
	
	public ref class Class1:Autodesk::Revit::UI::IExternalCommand
	{
	public:
		virtual Autodesk::Revit::UI::Result Execute(Autodesk::Revit::UI::ExternalCommandData^ commandData,
			String^% message, Autodesk::Revit::DB::ElementSet^ elements);
		// TODO: Add methods for this class here.
	};

cpp

#include "pch.h"

#include "ClassLibrary3.h"
#include "NameSpace.h"

namespace RevitAddin
{
	
}

Autodesk::Revit::UI::Result ClassLibrary3::Class1::Execute(Autodesk::Revit::UI::ExternalCommandData^ commandData, String^% message, Autodesk::Revit::DB::ElementSet^ elements)
{
	auto uiDoc = commandData->Application->ActiveUIDocument;
	auto doc = uiDoc->Document;
	auto selection = uiDoc->Selection;
	auto refer = selection->PickObject(Autodesk::Revit::UI::Selection::ObjectType::Element, "select");
	auto ele = doc->GetElement(refer);
	auto wall = static_cast<Autodesk::Revit::DB::Wall^>(ele);
	Autodesk::Revit::UI::TaskDialog::Show("Revit",wall->Name);
	return Autodesk::Revit::UI::Result::Succeeded;
}

Image Description