NO

Author Topic: PreProc  (Read 9496 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: 1891
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: 1891
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: 1891
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: 566
    • 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: 1891
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 »