NO

Author Topic: Possible Addin bug  (Read 1596 times)

Offline John Z

  • Member
  • *
  • Posts: 790
Possible Addin bug
« on: September 17, 2022, 03:48:24 PM »
Possible Add-in bug.
Summary:  If an add-in is already enabled when Pelles C is started a call to AddIn_GetActiveProject returns the project name.  However if the same add-in is disabled when Pelles C is started but then activated using the Tools- Customize, a call to AddIn_GetActiveProject fails to return the project name.

Thoughts: It could be a bug OR could be I'm not initializing the add-in correctly

How to test:
Copy Add_in_Bug.dll to AddIns64 directory
Start Pelles C by clicking on any project you already have or just use Add_in_Bug.ppj from attached sources
Check TOOLBAR for a button 'C', if existing then the Addin was enabled automatically click  to see project name.

if the button is not there go to Tool - Customize - Add ins and check the box for "PellesC addin bug check"
Click OK
Click the C button and see if the project name is displayed.
Then CLOSE PellesC and restart it.  This will mean that the add-in was already active on Pelles C startup
Click the C button now the project name shows up.

Also when a different Project is loaded the 'C' which was working when enabled before Pelles was started now does not get the newly loaded project name.

I hope clear; the result of AddIn_GetActiveProject seemingly depends on the add-in as already being checked as active when Pelles C starts up.  If activated after Pelles is started the button shows but the results of AddIn_GetActiveProject is an empty string.

I lean towards  "I've done wrong" so I hope for someone to correct me  :o

Minimum project source attached as a PellesC ZIP.

Forum has been too quiet anyway  :)

John Z

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: Possible Addin bug
« Reply #1 on: September 17, 2022, 08:11:04 PM »
A bug in Add-In code.

SendMessage(hwnd, AIM_GET_ACTIVE_PROJECT, (WPARAM)(int)(cchMax), (LPARAM)(WCHAR *)(pch))
Quote
Description:
The message retrieves the display name of the active project. The argument hwnd contains the project pane window handle, the argument pch points to a buffer for the result, and the argument cchMax contains the buffer size in characters.


How to fix:
Code: [Select]
ans = AddIn_GetActiveProject(g_hwndProj, p_msg, 260);
« Last Edit: September 17, 2022, 09:05:37 PM by TimoVJL »
May the source be with you

Offline John Z

  • Member
  • *
  • Posts: 790
Re: Possible Addin bug
« Reply #2 on: September 17, 2022, 09:29:27 PM »
Thanks TimolVJL!

I see, I've used the wrong window handle, 'main' instead of proj', yikes.  Appreciate the help .

John Z

Offline John Z

  • Member
  • *
  • Posts: 790
Re: Possible Addin bug
« Reply #3 on: September 20, 2022, 12:23:26 PM »
Modified my test program to use g_hwndProj separate from a g_hwndMain.

Tested and this shows the same results; the add-in performs differently if already installed and enabled when Pelles UI is started compared to enabling the add-in after Pelles UI is already running.

Also when it is enabled before Pelles UI is started it works, but if disabled and then re-enabled in the same Pelles UI instance the add-in does not perform correctly.

All this code does is return the current project name.  It is very short.

Anybody get this to work?  I'd be happy to understand my mistake...

All help appreciated, I'm stuck!

John Z

Offline John Z

  • Member
  • *
  • Posts: 790
Re: Possible Addin bug
« Reply #4 on: September 22, 2022, 01:39:49 PM »
Although I'm still working, with help, to see if I have made some blunder or another here is a possible clue.

Changing the Project Mode for example from 'Release' to 'Debug' then back to 'Release' the test program retrieves the project.ppj file name correctly.  So if the add-in is not enabled when Pelle IDE starts but then enabled, or if later it is disabled and re-enabled in the same IDE instance, just toggling the project Mode from one mode to another fixes the problem and the utility retrieve the project ppj filename every time.

There is  nothing in my test code that has anything to do with changing the Project Mode it only affects the IDE internally.

John Z
 

Offline John Z

  • Member
  • *
  • Posts: 790
Re: Possible Addin bug
« Reply #5 on: September 25, 2022, 01:26:25 PM »
This has been resolved with a lot of help from TimoVJL, turns out I had not included AIE_PRJ_CREATE case which turns out to be key in retrieving the project.ppj name consistently. 

TimoVJL's patience and help to resolve this oversight/bug are very much appreciated.

John Z

Check under 'Feature Requests' @ https://forum.pellesc.de/index.php?topic=10212.0 here for a new version of the
CopyMode Add-in Beta for testing.  Feedback will be appreciated.