Seems i forgot a check, try this one.
static BOOL SetLinkerFlags(int idCmd)
{
TCHAR szOld[1024], szNew[1024], *psz;
/* Get the current linker options */
if (AddIn_GetProjectSymbol(g_hwndPrj, _T("LINKFLAGS"), szOld, NELEMS(szOld)) == 0)
return FALSE;
/* Set the new options */
switch (idCmd)
{
case ID_RELEASE:
{
lstrcpy(szNew, _T("-release"));
break;
}
case ID_DEBUG:
{
lstrcpy(szNew, _T("-debug -debugtype:both"));
break;
}
case ID_PROFILE:
{
if (_tcsstr(szOld, _T("console")) == NULL)
{
lstrcpy(szNew, _T("-debug -debugtype:both profiler.lib"));
}
else
{
lstrcpy(szNew, _T("-debug -debugtype:both profiler.lib user32.lib"));
}
break;
}
}
if (_tcsstr(szOld, _T("console")) == NULL)
{
/* Walk through the current options and build the new options */
for (psz = _tcstok(szOld, _T(" ")); psz != NULL; psz = _tcstok(NULL, _T(" ")))
{
/* Forget old options */
if (lstrcmp(psz, _T("-release")) == 0 ||
lstrcmp(psz, _T("-debug")) == 0 ||
lstrcmp(psz, _T("-debugtype:both")) == 0 ||
lstrcmp(psz, _T("-debugtype:coff")) == 0 ||
lstrcmp(psz, _T("-debugtype:cv")) == 0 ||
lstrcmp(psz, _T("profiler.lib")) == 0)
continue;
/* Add this option to the new linker options */
if (szNew[0] != '\0')
lstrcat(szNew, _T(" "));
lstrcat(szNew, psz);
}
}
else
{
/* Walk through the current options and build the new options */
for (psz = _tcstok(szOld, _T(" ")); psz != NULL; psz = _tcstok(NULL, _T(" ")))
{
/* Forget old options */
if (lstrcmp(psz, _T("-release")) == 0 ||
lstrcmp(psz, _T("-debug")) == 0 ||
lstrcmp(psz, _T("-debugtype:both")) == 0 ||
lstrcmp(psz, _T("-debugtype:coff")) == 0 ||
lstrcmp(psz, _T("-debugtype:cv")) == 0 ||
lstrcmp(psz, _T("profiler.lib")) == 0 ||
((idCmd != ID_PROFILE) && (lstrcmp(psz, _T("user32.lib")) == 0)))
continue;
/* Add this option to the new linker options */
if (szNew[0] != '\0')
lstrcat(szNew, _T(" "));
lstrcat(szNew, psz);
}
}
/* Set the new linker options */
return AddIn_SetProjectSymbol(g_hwndPrj, _T("LINKFLAGS"), szNew);
}