hoping someone might be able to help me out. I have been writing addins in C#, but now im trying to start out with using c++/Cli for some wrappers. but I'm getting errors from the start...
here are the steps I took to create a c++/Cli class project.
1.open VS2015 and create new c++/CLI class project,
2. close and open the sln file from MicroStation SDK command prompt
3. add include location to properties.
4. add lib location to properties
5. then all I did was start to add using statements to my header file. I only added #include<Mstn\MdlApi\MdlApi.h>
once I added that I got 2 errors.
cannot open source file "_config-eccp.h"
and #error directive: Data Alignment must be defined in basedefs.h.
im a newbie what it comes to c++...
John Drsek said:here are the steps I took to create a c++/Cli class project
When you write a *.mke make file and use bmake to build your app. you can benefit from the SDK examples.
Some SDK examples have a Viz Studio solution, but I don't think that there is any C++/CLI example.
Try adding pre-processor definition WinNT to your Viz Studio project. That macro would be defined in your make file by one of the numerous *.mki include files. You have to replicate that in Viz Studio to build your project correctly.
Regards, Jon Summers LA Solutions
I am happy that Jon answered the same way as I did in a former discussion: Use bmake and .mke files in this situation.
Really, it's not simple answer these questions, because to set up C++/CLI project properly, when four different worlds intersects (native configuration of standard C++ header and libs, of MicroStation API files, managed standard configuration and optionally also references to used MicroStation assemblies), usually requires full attention.
BTW Is VS2015 the right version to be used? You do not specify product and version correctly (please, follow the best practices!), but for MicroStation CE Update 12, Visual Studio 2017 is required.
I recommend, in the first step, to try to compile and run mixed mode example delivered with SDK to ensure required tools and files are available on your computer.
Later, when you really want to stick on Visual Studio solution, you can log bmake output (in verbose mode optionally) and to check what parameters are passed to compiler and linker and set it in the same way in Visual Studio.
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
I really don't know what I'm doing when it comes to these bmake files.
I did define WinNT and that got rid of the second error.
but the first, cannot open source file "_config-eccp.h"
if coming from line 214 of config.h. but I have searched everywhere on my c drive and can not find the _config-eccp.h file.
John Drsek said:I really don't know what I'm doing when it comes to these bmake files
Most of us are in the same boat. I've been doing this stuff for more than two decades and still find those *.mki include files a mystery. Fortunately, we don't have to get involved with those too often (and only for reference, never to edit).
The simplest approach: when in Rome, do as the Romans do. Copy the example bmake files and modify.
..\SDK\include\Bentley\stdcxx\rw\config.h contains some information for the C++ compiler. I've never used it or seen it mentioned. Best left alone. However, that config.h has only 36 lines.
There is _config.h that has more lines and this...
// NOTE: the __EDG__ macro is #defined by most EDG-based compilers
#if defined (__EDG__) \
&& !defined (__DECCXX) \
&& !defined (__HP_aCC) \
&& !defined (__INTEL_COMPILER) \
&& !defined (_SGI_COMPILER_VERSION)
// FIXME: make this more robust by detecting the EDG eccp demo
// during library configuration (and avoid relying on compiler
// specific macros)
# include "_config-eccp.h"
#endif // __EDG__
I've never seen that file mentioned nor have I had to use it. Why it attempts to include the missing _config-eccp.h is buried in the C++ compiler. I don't know what defines __EDG__ — it's not in any of the __EDG__ files.
thank you for helping me.
I can make a test c++/cli with a simple function and call that from c# easily (plenty on stuff on the internet). but when trying to do the same with the SDK im feeling stuck.
I decided to just set up a c++ project just to get something working. So if you use bmake to build do you still set up a visual studio project..and just not worry about the errors.
I get the same exact error in my c++ project. whenever I add any of the include header files from the SDK I get that cannot open source file "_config-eccp.h" error. I set up my additional include and lib locations in the project settings and my include statements are valid and intillesense is working as the header files show up as im typing the include statement.
should I be going about this is a different way. I like the intellisense of visual studio. are there certain header files I need to include first??
i feel like once i get by this set up stuff i could get going.
Hi John Drsek,
For a handful of reasons we too would like to soon add a (simple, good and practical) C++/CLI example in the SDK.
I will discuss this with development to identify a small practical and beneficial example and file an Enhancement to add it to the SDK, then update this thread. Once we have an example available (having both .mke and .sln) I will see about updating our (simple and already dated VS2015) MicroStation Visual Studio Extensions project templates.
Until then and specific to your current concern, "_config-eccp.h" (IntelliSense database build Error) has been mentioned a few times and from my experience can be resolved/ignored if you use the "Build" option (vs. Build + IntelliSense). This article clearly shows the option I am referring to, and goes further (though I have not had a need or tested) providing multiple steps on how to manually clean up a (corrupt?) intelliSense solution database; (if needed) see: Fixing Visual Studio Intellisense Errors.
Answer Verified By: John Drsek
"2. close and open the sln file from MicroStation SDK command prompt"
Why?, Why not using Visual Studio?
"5. then all I did was start to add using statements to my header file. I only added #include<Mstn\MdlApi\MdlApi.h>"
From screen shot I assume cppWrappers.h has Common Language Support?
If it has then you can not include MdlApi.h there. You are mixing managed and unmanaged code!
"cannot open source file "_config-eccp.h" usually means your project settings are wrong!
Nenad Poljcic said:Why?, Why not using Visual Studio
im using visual studio I just open it from the command prompt so that the needed variables are set.
Nenad Poljcic said:"cannot open source file "_config-eccp.h" usually means your project settings are wrong!
clearly, I don't know what I'm doing. im going to try a different approach
Robert thank you for the link to the Visual Studio Extensions I was unaware of this. I was able to use that and actually built my project. so thankful for that finially made some progress
a c++/CLI example would be great. I would like to see an example of wrapping a function so c# developers and use things like adding fields to text like the CreateForElement function.
here is my new plan of attack
give up on c++/cli for now.
use the template in the extensions that you linked above.
write a function and export it to c.
use dll import in c# to access the function.
i did a quick test and was able to get this to work.
here is same sample code. the end goal that I wanted was to be able to add a field to a text element. so I took this code...
made it into one function like this....
bool AddField(__int64 ElementID)
DgnModelP pActiveModel = ISessionMgr::GetActiveDgnModelP();
TextBlockPropertiesPtr pTBProp = TextBlockProperties::Create(*pActiveModel);
ParagraphPropertiesPtr pParaProp = ParagraphProperties::Create(*pActiveModel);
DgnTextStylePtr pTextStyle = DgnTextStyle::GetActive();
RunPropertiesPtr pRunProp = RunProperties::Create(*pTextStyle, *pActiveModel);
TextBlockPtr pTextBlock = TextBlock::Create(*pTBProp, *pParaProp, *pRunProp, *pActiveModel);
pTextBlock->AppendText(L"This is a ViewIndependent text");
DgnFileP pDgnFile = ISessionMgr::GetActiveDgnFile();
SchemaInfo schemaInfo(ECN::SchemaKey(L"DgnElementSchema", 1, 0), *pDgnFile);
DgnECManagerR ecMan = DgnECManager::GetManager();
ECN::ECSchemaPtr pSchema = ecMan.LocateSchemaInDgnFile(schemaInfo, ECN::SchemaMatchType::SCHEMAMATCHTYPE_LatestCompatible);
if (pSchema == NULL)
ECN::ECClassCR ecClass = *pSchema->GetClassCP(L"ArcElement");
ElementId elemId = ElementID; // An arc element id
ElementHandle elem(elemId, pActiveModel);
DgnElementECInstancePtr pElemInst = ecMan.FindInstanceOnElement(elem, ecClass);
TextFieldPtr pField = TextField::CreateForElement(*pElemInst, L"Length", nullptr, *pActiveModel);
if (pField != NULL)
if (TEXTBLOCK_TO_ELEMENT_RESULT_Success ==
TextHandlerBase::CreateElement(eeh, nullptr, *pTextBlock))
I needed these two additional includes (added of the top of my cpp file.)
defined it in the header file like this...
extern "C" __declspec(dllexport) bool AddField(__int64 ElementID);
and had to add this linker to the mke file
LINKER_LIBRARIES + $(mdlLibs)ECObjects.lib
then back in my c# addin and added a dllimport
private static extern bool AddField(Int64 ElementID);
and then just called it in my method
//test dll function
bool result = AddField(1637);
it returned true and the text element with field was added to the model.
this is all still pretty rough code, going to update it a little bit for my needs but hopefully this helps others.
Thank you for the update and feedback (and code snips) and certainly glad to hear you are making more progress. Also, if one or more contributions on this thread helped resolve the post, please feel free to mark one or more of the responses as More > Verify Answer so other users can quickly pick up relevant pieces towards a solution.
Again, thank you for your update.