News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

PreProc

Started by czerny, January 03, 2012, 02:52:30 AM

Previous topic - Next topic

czerny

Hallo,

I would like to learn, how to write AddIns.
It would be nice if someone could check my work. The first is a minimal AddIn. May be it can be a starting point for someone. The second  one runs the Preprocessor.

czerny


TimoVJL

#1
In AddInCommand()  instead of ShellExecute() you can use CreateProcess()
...
STARTUPINFO si = {0};
PROCESS_INFORMATION pi = {0};
...
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(szPara,adi.szFilename);
AddIn_OpenDocument(hwndMain, AID_SOURCE, GetIFile(szPara));
} else AddIn_WriteOutput(hwndMain, _T("error"));
...

EDIT:
Use AddInCommandEx()  instead of AddInCommand() for Win64 compability.
May the source be with you

czerny

Thank you timovjl,

I have changed this and uploaded a corrected version.

czerny

TimoVJL

Please upload corrected PreProc again.
There was ppj-file only.
May the source be with you

czerny


TimoVJL

If you want to use current project CCFLAGS too:
...
static HWND hwndProj = NULL;
...
case AIE_PRJ_CREATE:
// Remember project window handle, in case we need it.
hwndProj = hwnd;
return TRUE;

case AIE_PRJ_DESTROY:
// Forget project window handle.
hwndProj = NULL;
return TRUE;
...
AddIn_GetIDEFolder(hwndMain, ADDIN_FOLDER_BIN, szTmp, sizeof(szTmp)/sizeof(szTmp[0]));
_tcscat(szTmp, _T("\\pocc.exe /P "));
if (hwndProj && AddIn_GetProjectSymbol(hwndProj, _T("CCFLAGS"), szTmp1, sizeof(szTmp1)/sizeof(szTmp1[0]))) {
_tcscat(szTmp, szTmp1);
_tcscat(szTmp, _T(" "));
}
...
May the source be with you

czerny

Thank you!

I would'nt have found howto get things like CCFLAGS.

My first cause to make this addin was, to test preprocessor macros. But yesterday I had problems to compile the newest zlib library. I had some suspicion that a macro OF(arg) is not working right and  than I would have needed the real flags.

czerny

CommonTater

Look in the AddIn SDK helpfile

You could quite easily...
use AddIn_GetProjectSymbol()  to get the original CCFLAGS and save them
change the CCFLAGS to your liking with AddIn_SetProjectSymbol()
Send AddIn_SendIDECommand() with AIC_PROJECT_COMPILE
Trap the AddIn_Main token for AIE_PROJ_ENDBUILD
Then use AddIn_SetProjectSymbol() to restore the original CCFLAGS

No messing with ShellExecute or CreateProcess at all...

czerny

Hallo Commontater,

I tried your suggestion but get a little  problem.

if (hwndProj && AddIn_GetProjectSymbol(hwndProj, _T("CCFLAGS"), ccFlags, sizeof(ccFlags)/sizeof(ccFlags[0]))) {
_tcscpy(szTmp, _T("/P "));
_tcscat(szTmp, ccFlags);
AddIn_SetProjectSymbol(hwndProj, _T("CCFLAGS"), szTmp); //set
AddIn_GetProjectSymbol(hwndProj, _T("CCFLAGS"), szTmp, sizeof(szTmp)/sizeof(szTmp[0])); //check
AddIn_WriteOutput(hwndMain, szTmp);
AddIn_SendIDECommand(hwndMain, AIC_PROJ_COMPILE); //build
AddIn_SetProjectSymbol(hwndProj, _T("CCFLAGS"), ccFlags); //reset
AddIn_WriteOutput(hwndMain, ccFlags);
}

Project saved: D:\C\wwl\ide-extensions\extensions\PreProc\PreProc.ppj
/P -W1 -Ot -Gz -Ze -Tx86-coff
Project saved: D:\C\wwl\ide-extensions\extensions\PreProc\PreProc.ppj
-W1 -Ot -Gz -Ze -Tx86-coff
Project build started
Project build ended successfully


It seems as if I have to wait until the file is compiled. Is there a simple  solution?

czerny

Stefan Pendl

Quote from: czerny on January 05, 2012, 12:37:30 AM
It seems as if I have to wait until the file is compiled. Is there a simple  solution?

I think you omitted the stage below:
Quote from: CommonTater on January 04, 2012, 07:07:21 PM
Trap the AddIn_Main token for AIE_PROJ_ENDBUILD

Reread Taters suggestion.
---
Stefan

Proud member of the UltraDefrag Development Team

CommonTater

Yep... you want this to be event driven...

1) don't add the button until a project is created/opened AddIn_Main()  ...AIE_PROJ_CREATE
2) don't do anything until the button is pressed.
3) when the button is pressed flip the CCFLAGS and set a flag
4) start the compile
5) do nothing.
6) when AddIn_Main signals AIE_PROJ_ENDBUILD ... then put the strings back only if he flag is set

AddIn_Main is a message tosser... use it like you would the WinProc in a windows program.

Also, beware of syntax like this...

AddIn_GetProjectSymbol(hwndProj, _T("CCFLAGS"), szTmp, sizeof(szTmp)/sizeof(szTmp[0])); //check

Size of only works on arrays in scope... if you aren't extremely careful you'll end up with the size of the pointer instead of the size of the array...  It's better to us a #define such as ... #define MAX_CCFLAGS 128 ... both when defining the string and when referring to it's size than to try clever sizeof() tricks.





czerny

Ok,

I have made a lot of changes (new version uploaded). But it remains a problem:

A file that is not part of the project (tst.c for example) will not be compiled by AddIn_SendIDECommand().

I see three different ways to handle this.

Check, if file is part of the project. If so than
1.) do nothing (not so good) or
2.) include it in the project -- compile -- exclude  it again or
3.) invoke pocc as in my first attempts.

Is there an other solution? Some idees?

czerny

TimoVJL

Least with AddIn_EnumProjectFiles you can verify if file is part of project.
If it is not then you can process it with some default values with that another way.
May the source be with you

czerny

This would be the 3. way. But I do not like to have two ways than to invoke the preprocessor.
Should I return to CreateProcess alone?

czerny

czerny

#14
I have two questions to AddIn_EnumProjectFiles:
When is this function returning TRUE or FALSE resp.?

What about the return value of the callback function? It seems to me, that a return FALSE stops enumeration. Is this right?

A second point:

Try this with the actual version.
Rename Preproc.c to say Preproc_Tmp.c
Then click the Preproc Button
Why is AddIn_SendIDECommand not invoked then?

A  third point:

If  I enum project files, the file tst.c (which is excluded) is also listed.
How can I check, if a file is excluded?

czerny