Excellent solution Jon!
The code is now up and working. Here is the source code:
wchar_t* convertStringto_wchar_t(string s) { const char * c = s.c_str(); const size_t cSize = strlen(c) + 1; wchar_t* wc = new wchar_t[cSize]; mbstowcs(wc, c, cSize); return wc; } 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); worked = mdlView_setLevelDisplay(modelRef, 0, levid, FALSE);//not working, worked = 0 } } infile.close(); return SUCCESS; }
The trick was in the conversion of the string to a wchar_t! Like Jon brilliantly pointed out, use mbstowcs. This program now takes a text file with a level name on each line, and turns those levels off in the active model reference! Thank you so much guys for all the help!
The text file is called "Turn off Levels.txt" and would look something like this:
dsnCellElements Level 5 Level 3 Level 1 Level 2 Level 7 Level 6 Level 4 Level 20 dsnStdBlockModified dsnStdBlockNotModified