Here is a snippet working for me
// convert string to wstring
std::wstring ToWideString(std::string narrowString)
{
return std::wstring_convert<std::codecvt_utf8<wchar_t>>().from_bytes(narrowString);
}
void CreateMaterial(CwAPI3D::MaterialController* mc) {
// get the string value of the material
auto newMaterialNameWS = ToWideString(Value);
auto newMaterialNameCS = newMaterialNameWS.c_str();
// check if the material exists
auto material_id = mc->getMaterialID(newMaterialNameCS);
if (material_id == 0) {
// if the material does not exist, create it
material_id = mc->createMaterial(newMaterialNameCS);;
// set the material group to switchboard materials
mc->setGroup(material_id, L"Switchboard_Materials");
}
}