C++ Revit Addin

C++ Revit Addin

JPMorrow
Explorer Explorer
930 Views
1 Reply
Message 1 of 2

C++ Revit Addin

JPMorrow
Explorer
Explorer

Hey all,

 

I am trying to spark some discussion on building a C++ / CLR Mixed Revit Addin. I have been developing my addins in C# so far and I want to try breaking out of the GUI frameworks that it provides and try out some C++ alternatives. I have yet to discover any of the pitfalls and limitations of making a mixed C# / C++ addin, but it is possible, and I want to give it at try.

 

I have a bit of a kicker though, I don't use Microsoft Visual Studio as my IDE, I do all my current addin development in VSCode, which means defining my own build systems. I came across this blog post HERE that discusses making a c++ addin complete with a Visual Studio sample solution. I took all the compiler and linker flags from that solution and put them in a .bat file to build my program, however, I receive a couple of errors on compiling that the solution did not present.

 

Below is the .bat script I use to build my addin

 

 

 

 off

call "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" x64

set appName = %1
set revitAPI=.\refs\2019\RevitAPI.dll
set revitAPIUI=.\refs\2019\RevitAPIUI.dll

set compilerFlags= /ifcOutput.\build\ /GS /analyze- /W3 /Zc:wchar_t /Zi /Od /Fd.\build\vc140.pdb /Zc:inline /fp:precise /D "WIN32" /D "_DEBUG" /D "_WINDLL" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /Oy- /clr /MDd /FC /Fa.\build\ /EHa /nologo /Fo.\build\ /Fp.\build\%appName%.pch /diagnostics:column
set linkerflags= /OUT:.\build\%appName%.dll /LTCG /CLRIMAGETYPE:IJW /MANIFEST /NXCOMPAT /PDB:.\build\%appName%.pdb /DYNAMICBASE /FIXED:NO /DEBUG /DLL /MACHINE:X64 /ERRORREPORT:PROMPT /NOLOGO /ASSEMBLYDEBUG /TLBID:1 

cl.exe %compilerflags% Main.cpp /link %revitAPI% %revitAPIUI% %linkerflags%

 

 

 

This is the output from the compiler:

 

 

> Executing task in folder CPPRevitAddin: C:\Users\%USERNAME%\Desktop\Code\C++\CPPRevitAddin\.vscode\build ${appName} <

**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.8.4
** Copyright (c) 2020 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'
Main.cpp
.\refs\2019\RevitAPI.dll : fatal error LNK1302: only support linking safe .netmodules; unable to link ijw/native .netmodule
The terminal process "C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -Command C:\Users\Jmorrow\Desktop\Code\C++\CPPRevitAddin\.vscode\build ${appName}" terminated with exit code: 1.

 

 

 

The line in question that the other solution never hits is:

 

 

.\refs\2019\RevitAPI.dll : fatal error LNK1302: only support linking safe .netmodules; unable to link ijw/native .netmodule

 

 

 

I have tried many ways of getting around the error including doing /clr:safe flag (it is deprectiated and appears to do nothing). I am open to any suggestions at this point because information on this specific error is sparse and often refers the programmer to try recompiling the C# dll with certain flags. This is not an option since I cant recompile the Revit API.

0 Likes
931 Views
1 Reply
Reply (1)
Message 2 of 2

jeremy_tammik
Alumni
Alumni

The Revit 2019 API required the .NET framework 4.7:

 

https://help.autodesk.com/view/RVT/2019/ENU/?guid=Revit_API_Revit_API_Developers_Guide_Introduction_...

 

I don't see where that requirement is being enforced in you build settings.

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes