Very good solution. Here is Jon's suggestion in the source code:
std::wstring convertStringto_wchar_t(string s) { const size_t cSize = s.length() + 1; wchar_t* wc = new wchar_t[cSize]; mbstowcs(wc, s.c_str(), cSize); std::wstring converted(wc); delete[] wc; return converted; } extern "C" DLLEXPORT int MdlMain (){ int worked; string line; ifstream infile; appendToFile(""); infile.open("Turn off Levels.txt"); if (infile.is_open()){ while (getline(infile, line)) // Saves the line in id { const std::wstring& levelName = convertStringto_wchar_t(line); DgnModelRefP modelRef = mdlModelRef_getActive(); LevelID levid; mdlLevel_getIdFromName(&levid, modelRef, LEVEL_NULL_ID, levelName.c_str()); worked = mdlView_setLevelDisplay(modelRef, 0, levid, FALSE);//not working, worked = 0 } } infile.close(); mdlDialog_cmdNumberQueue(FALSE, CMD_MDL_UNLOAD, mdlSystem_getCurrTaskID(), TRUE); return SUCCESS; }
Though I like your solution better, why couldn't I dereference my pointer later in the code?
extern "C" DLLEXPORT int MdlMain (){ int worked; string line; ifstream infile; appendToFile(""); infile.open("Turn off Levels.txt"); if (infile.is_open()){ while (getline(infile, line)) // Saves the line in id { MSWCharP levelName; levelName = convertStringto_wchar_t(line); DgnModelRefP modelRef = mdlModelRef_getActive(); LevelID levid; mdlLevel_getIdFromName(&levid,modelRef,LEVEL_NULL_ID,levelName); delete levelName; worked = mdlView_setLevelDisplay(modelRef, 0, levid, FALSE);//not working, worked = 0 } } infile.close(); mdlDialog_cmdNumberQueue(FALSE, CMD_MDL_UNLOAD, mdlSystem_getCurrTaskID(), TRUE); return SUCCESS; }
Thank you for the help!
I was not aware that MicroStation treats a char * like a wchar_t*. I also have not used wstrings very much, so I appreciated the example.