With this code you can borrow more options from current project for external file:
TCHAR *GetIFile(TCHAR *szFileName)
{
TCHAR *szTmp;
if (*szFileName)
{
szTmp = _tcsrchr(szFileName, '.');
*(++szTmp) = 'i';
*(++szTmp) = '\0';
}
return szFileName;
}
void ExecutePOCC(void)
{
HWND hwnd;
STARTUPINFO si = {0};
PROCESS_INFORMATION pi = {0};
ADDIN_DOCUMENT_INFO adi = { .cbSize = sizeof(adi) };
TCHAR szTmp[MAX_PATH*3];
TCHAR szTmp2[1024];
hwnd = AddIn_GetActiveDocument(hwndMain);
if (!hwnd) return;
if (!AddIn_GetDocumentInfo(hwnd, &adi)) return;
if ((adi.fDirty) || (!adi.szFilename[0]))
AddIn_SendIDECommand(hwndMain, AIC_FILE_SAVE);
if (!AddIn_GetDocumentInfo(hwnd, &adi)) return;
int nLen = AddIn_GetIDEFolder(hwndMain, ADDIN_FOLDER_BIN, szTmp, sizeof(szTmp)/sizeof(TCHAR));
_tcscat(szTmp, _T("\\pocc.exe -P "));
nLen += 13;
if (hwndProj && AddIn_GetProjectSymbol(hwndProj, _T("CCFLAGS"), &szTmp[nLen], sizeof(szTmp)/sizeof(TCHAR)-nLen)) {
_tcscat(szTmp, _T(" "));
AddIn_GetProjectSymbol(hwndProj, _T("INCLUDE"), szTmp2, sizeof(szTmp2)/sizeof(TCHAR));
SetEnvironmentVariable(_T("INCLUDE"), szTmp2);
AddIn_GetProjectSymbol(hwndProj, _T("LIB"), szTmp2, sizeof(szTmp2)/sizeof(TCHAR));
SetEnvironmentVariable(_T("LIB"), szTmp2);
}
_tcscat(szTmp, adi.szFilename);
//AddIn_WriteOutput(hwndMain, NULL);
AddIn_ClearOutput(hwndMain);
AddIn_WriteOutput(hwndMain, szTmp);
si.cb = sizeof(STARTUPINFO);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
if (CreateProcess(NULL,szTmp,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi))
{
WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
_tcscpy(szTmp,adi.szFilename);
AddIn_OpenDocument(hwndMain, AID_SOURCE, GetIFile(szTmp));
} else AddIn_WriteOutput(hwndMain, _T("error"));
}