NO

Author Topic: PreProc  (Read 18846 times)

czerny

  • Guest
PreProc
« on: January 03, 2012, 02:52:30 AM »
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

« Last Edit: January 08, 2012, 03:08:36 PM by czerny »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: PreProc
« Reply #1 on: January 03, 2012, 10:50:18 AM »
In AddInCommand()  instead of ShellExecute() you can use CreateProcess()
Code: [Select]
...
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.
« Last Edit: January 03, 2012, 12:24:55 PM by timovjl »
May the source be with you

czerny

  • Guest
Re: PreProc
« Reply #2 on: January 03, 2012, 06:18:10 PM »
Thank you timovjl,

I have changed this and uploaded a corrected version.

czerny

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: PreProc
« Reply #3 on: January 04, 2012, 10:15:37 AM »
Please upload corrected PreProc again.
There was ppj-file only.
May the source be with you

czerny

  • Guest
Re: PreProc
« Reply #4 on: January 04, 2012, 03:39:57 PM »
sorry!

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: PreProc
« Reply #5 on: January 04, 2012, 05:09:34 PM »
If you want to use current project CCFLAGS too:
Code: [Select]
...
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

  • Guest
Re: PreProc
« Reply #6 on: January 04, 2012, 05:56:11 PM »
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

  • Guest
Re: PreProc
« Reply #7 on: January 04, 2012, 07:07:21 PM »
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

  • Guest
Re: PreProc
« Reply #8 on: January 05, 2012, 12:37:30 AM »
Hallo Commontater,

I tried your suggestion but get a little  problem.

Code: [Select]
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

Offline Stefan Pendl

  • Global Moderator
  • Member
  • *****
  • Posts: 582
    • Homepage
Re: PreProc
« Reply #9 on: January 05, 2012, 01:16:04 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:
Trap the AddIn_Main token for AIE_PROJ_ENDBUILD

Reread Taters suggestion.
---
Stefan

Proud member of the UltraDefrag Development Team

CommonTater

  • Guest
Re: PreProc
« Reply #10 on: January 05, 2012, 01:48:07 AM »
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...
Code: [Select]
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

  • Guest
Re: PreProc
« Reply #11 on: January 05, 2012, 04:49:19 PM »
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

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: PreProc
« Reply #12 on: January 05, 2012, 05:32:52 PM »
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

  • Guest
Re: PreProc
« Reply #13 on: January 05, 2012, 06:35:07 PM »
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

  • Guest
Re: PreProc
« Reply #14 on: January 07, 2012, 01:28:58 PM »
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
« Last Edit: January 07, 2012, 01:49:32 PM by czerny »