Author Topic: Compiling a PM sample with GCC (2023)  (Read 126046 times)

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4986
  • Karma: +110/-1
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #240 on: July 27, 2023, 02:04:31 am »
Seems to be a bug in GCC, doubling the size didn't help but removing the optimization got rid of the warning. -O1 or -Os (optimize for size) or -Og (optimize in debugger friendly way) also gets rid of the warning, -O3 of course doesn't. Too lazy to try to figure out which optimization that -O2 uses triggered the problem. I'd suggest changing the optimization of ctxmenu.c to -O1.

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4940
  • Karma: +44/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC (2023)
« Reply #241 on: July 29, 2023, 03:21:34 pm »
Thanks for the feedback.

I'm leaving "CNRMENU" on the github repo:
https://github.com/OS2World/DEV-SAMPLES-C-PM-CNRMENU

Regards
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4940
  • Karma: +44/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC (2023)
« Reply #242 on: July 30, 2023, 04:51:32 am »
Hello

Now I'm trying this sample: https://github.com/OS2World/DEV-SAMPLES-The-IBM-Developer-Connection-Release-12/tree/master/PMSAMPLE/MOUSPLAY

It compiles and runs, but it seems that it does not do what it offers. I guess you have to put the X and Y coordinates and it will move the mouse pointer there, press a click and even put some text. But it does not work for me.

It also has two warnings of some variables that I'm not sure if does something.

Regards
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4986
  • Karma: +110/-1
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #243 on: July 30, 2023, 07:40:07 am »
Hi, the warnings are simple, need to include stdlib.h.
Code: [Select]
--- mousplay.h.orig     2023-07-29 22:10:56.000000000 -0700
+++ mousplay.h  2023-07-29 22:30:46.000000000 -0700
@@ -5,6 +5,7 @@
 #define INCL_WIN
 #include <OS2.h>
 #include <process.h>
+#include <stdlib.h>
 /*---------------------------------------------------------------------------+
 |  Dialog defines                                                            |
 +---------------------------------------------------------------------------*/

Searching @unixroot/usr/include will often show the header that has the prototype, beginthread in this case.
Compile failed here with,
Code: [Select]
wrc -r mousplay.rc
Open Watcom Windows and OS/2 Resource Compiler Version 2.0beta1 LA
Portions Copyright (c) 1993-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See http://www.openwatcom.org/ for details.
mousplay.h(9): Error! E062:  Unable to open 'process.h'
make: *** [makefile:35: mousplay.res] Error 9

Which is caused by wrc not understanding GCC include options, fixed by adding %UNIXROOT%\usr\include to %INCLUDE%, perhaps something that should be done in config.sys.
It crashes here in pmmerge after entering the coordinates and text.
Code: [Select]
______________________________________________________________________

 Call Stack
______________________________________________________________________

   EBP     Address    Module     Obj:Offset    Nearest Public Symbol
 --------  ---------  --------  -------------  -----------------------
 Trap  ->  1FC06AAE   PMMERGE   0004:00116AAE  between XQueryWindowText + 12 and
 WSetWindowULong - 10E

 0012FE98  1FC04B5F   PMMERGE   0004:00114B5F  between WIN32QUERYWINDOWTEXT + 2F
 and CalcUpdate - 15

 0012FEDC  1FBF59F9   PMMERGE   0004:001059F9  between WIN32DISPATCHMSG + F5 and
 CheckLoseBoost - 1B

 0012FF28  00010759   MOUSPLAY  0001:00000759  mousplay.c#59 main + 99 0001:0000
06C0 (mousplay.c)

  Offset Name                 Type                         Hex Value
  ────── ──────────────────── ──────────────────────────── ─────────
   32    qmsg                 0x202                        0

 0012FF78  00010027   MOUSPLAY  0001:00000027  crt0.s#90 __text + 27 0001:000000
00 (D:\Temp\ccLyDNo2.s)

 0012FFE0  1FDC811B   LIBCN0    0001:0003811B  unwind-pe.h#201 ___gcc_personalit
y_v0 - 47 0001:00038162 (unwind-c.obj)

16 bit code failure??

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4986
  • Karma: +110/-1
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #244 on: July 30, 2023, 08:50:16 am »
The makefile is also weird. To build the exe, you are linking against the import lib twice and also the obj file used to build the dll. I fixed with,
Code: [Select]
--- makefile.orig       2023-07-29 22:58:40.000000000 -0700
+++ makefile    2023-07-29 23:15:18.000000000 -0700
@@ -16,7 +16,7 @@
 all : mousplay.exe mousedll.dll

 mousplay.exe: mousedll.obj mousplay.obj mousplay.def mousplay.res $(HEADERS) $(LIBS)
-       gcc -Zomf -Zmap -lmousedll $(LIBS) mousedll.obj mousplay.obj mousplay.def mousplay.res -o $@
+       gcc -Zomf -Zmap $(LIBS) mousplay.obj mousplay.def mousplay.res -o $@
        wrc mousplay.res

 mousplay.obj: mousplay.c mousplay.h $(HEADERS)

Could have gone with -lmousedll instead of $(LIBS).
Then we get undefined symbol errors, fixed by updating the def,
Code: [Select]
--- mousedll.def.orig   2023-07-29 23:16:30.000000000 -0700
+++ mousedll.def        2023-07-29 23:24:36.000000000 -0700
@@ -12,11 +12,11 @@
 DATA MULTIPLE NONSHARED


-;EXPORTS
-;MousePlayHookProc @1
-;KeyPlayHookProc   @2
-;Thmq              @3
-;sXCoordinate      @4
-;sYCoordinate      @5
-;PlayString        @6
+EXPORTS
+MousePlayHookProc @1
+KeyPlayHookProc   @2
+_Thmq              @3
+_sXCoordinate      @4
+_sYCoordinate      @5
+_PlayString        @6

Still crashes though :(

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4940
  • Karma: +44/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC (2023)
« Reply #245 on: July 30, 2023, 03:23:44 pm »
Hi Dave

Thanks for the feedback. This is strange, I did the changes, and it compiled fine. Now it does not want to compile, I'm not sure what I screwed up.

Also, when it runs, the exe does not shows on the "taskbar", it shows on TOP, was there some other trick to make it show there?

I found inside MOUSPLAY.DLG a reference to "DLGINCLUDE 1 "RAFAEL.H"" but not sure if it is related to some issue.

Regards
« Last Edit: July 30, 2023, 03:25:26 pm by Martin Iturbide »
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4986
  • Karma: +110/-1
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #246 on: July 30, 2023, 06:28:12 pm »
Hi Martin, somehow in MOUSPLAY_B2 mousedll.c is 0 bytes. Once I restored it, it compiled fine, still crashed.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4986
  • Karma: +110/-1
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #247 on: July 30, 2023, 11:13:57 pm »
Seems you changed WinQueryDlgItemShort() to WinQueryDlgItemText(), changing it back gets rid of the crash but the program still doesn't seem to work and leaves the DLL loaded. Possibly the DEF needs adjusting to use  INITGLOBAL TERMGLOBAL like how it was? I'll test later.
Code: [Select]
--- mousplay.c.orig 2023-07-30 09:48:22.000000000 -0700
+++ mousplay.c 2023-07-30 13:19:58.000000000 -0700
@@ -7,9 +7,9 @@
 /*************************************************************************/
 /* Move and play  related variables                                      */
 /*************************************************************************/
-extern LONG   sXCoordinate; /* Make coordinates extern to share    */
-extern LONG   sYCoordinate; /* with the hook DLL                   */
-extern CHAR    PlayString[]; /* DLL definition of character string     */
+extern PSHORT   sXCoordinate; /* Make coordinates extern to share    */
+extern PSHORT   sYCoordinate; /* with the hook DLL                   */
+extern PSZ    PlayString[]; /* DLL definition of character string     */
 ULONG EXPENTRY MousePlayHookProc(HAB habSpy,BOOL fSkip, PQMSG pQmsg);      /* 4 */
 ULONG EXPENTRY KeyPlayHookProc(HAB habSpy,BOOL fSkip, PQMSG pQmsg);        /* 4 */
 ULONG TextLen;
@@ -70,9 +70,9 @@
           /* hook                                                    */
           /***********************************************************/
 
-          if( !WinQueryDlgItemText( hwndDlg, EF_X, (LONG) &sXCoordinate, FALSE ))
+          if( !WinQueryDlgItemShort( hwndDlg, EF_X, (PSHORT)&sXCoordinate, FALSE ))
                                      sXCoordinate=0;
-          if( !WinQueryDlgItemText( hwndDlg, EF_Y, (LONG) &sYCoordinate, FALSE ))
+          if( !WinQueryDlgItemShort( hwndDlg, EF_Y, (PSHORT)&sYCoordinate, FALSE ))
                                      sYCoordinate=0;
           TextLen=WinQueryDlgItemText( hwndDlg,ID_CHARPLAY, 79, (PSZ) PlayString);
           TstTID=_beginthread(PlayThread,0,STACKSIZE,0);

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4940
  • Karma: +44/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC (2023)
« Reply #248 on: July 30, 2023, 11:48:05 pm »
Thanks Dave. I don't know how I lost mousedll.c. Now it compiles without error and warnings, but , yes, still does not work.
I changed the  INITGLOBAL TERMGLOBAL on mousedll, but no improvement.

Regards
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4940
  • Karma: +44/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC (2023)
« Reply #249 on: November 16, 2023, 09:43:04 pm »
Hello.

I just get back to compile an extra little thing. It compiles and works.
 
Can you please give me a hand with this warning?
Quote
gcc -Wall -Zomf -c -O2 pmstars.c -o pmstars.obj
pmstars.c: In function 'ClientWndProc':
pmstars.c:60:16: warning: variable 'my_timer' set but not used [-Wunused-but-set-variable]
   60 |   static ULONG my_timer;  /* System (PM) number indicating unique (system) timer number
      |                ^~~~~~~~

Regards
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Mentore

  • Full Member
  • ***
  • Posts: 198
  • Karma: +6/-0
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #250 on: November 17, 2023, 10:42:05 am »
Hello.

I just get back to compile an extra little thing. It compiles and works.
 
Can you please give me a hand with this warning?
Quote
gcc -Wall -Zomf -c -O2 pmstars.c -o pmstars.obj
pmstars.c: In function 'ClientWndProc':
pmstars.c:60:16: warning: variable 'my_timer' set but not used [-Wunused-but-set-variable]
   60 |   static ULONG my_timer;  /* System (PM) number indicating unique (system) timer number
      |                ^~~~~~~~

Regards

Hi Martin, the warning simply states the my_timer variable is never used. Just to be extra sure, search for it into the source code and if it is really never used (as I expect to happen), you can safely comment out / delete the statement.

Mentore

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4940
  • Karma: +44/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC (2023)
« Reply #251 on: November 17, 2023, 03:35:12 pm »
Hello

If I comment :
 line 60 // static ULONG my_timer;

and
 line 98 // my_timer=WinStartTimer( hab, hwnd, 0L, (ULONG)50 );

It will compile without errors, runs, but the animation will not work.

I guess I will leave this warning as it is.

Regards
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4940
  • Karma: +44/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC (2023)
« Reply #252 on: November 17, 2023, 04:07:29 pm »
Hello

Here it is another one. I tried to convert Fatbits (pixel magnifier program) from the OS/2 1.1 API by changing some WinQuery.. functions to PrfQuery.... Removed the warnings. I ignored the ASM code that seemed only to create the DLL, and didn't create the DLL, I embedded it to the EXE. 

It compiles without warnings, it loads, shows the magnified pixels, but it does not refresh the screen according the position of the cursor. If I maximize and reduce a window, it will refresh the magnifier image.

Regards
« Last Edit: November 17, 2023, 04:10:15 pm by Martin Iturbide »
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Mentore

  • Full Member
  • ***
  • Posts: 198
  • Karma: +6/-0
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #253 on: November 21, 2023, 11:03:11 am »
Hello

If I comment :
 line 60 // static ULONG my_timer;

and
 line 98 // my_timer=WinStartTimer( hab, hwnd, 0L, (ULONG)50 );

It will compile without errors, runs, but the animation will not work.

I guess I will leave this warning as it is.

Regards

which is the right thing to do, Martin, as the variable is of course needed. To remove the warning you may try to do something with it like this:

Code: [Select]
my_timer++;
my_timer--;

before calling WinStartTimer, so that the compiler thinks we have done something on it, or maybe search for some
Code: [Select]
#pragma statement to avoid the warning. Not sure about it, since I'm no GCC expert at all.

Mentore

Alex Taylor

  • Sr. Member
  • ****
  • Posts: 395
  • Karma: +5/-0
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #254 on: November 21, 2023, 02:32:30 pm »
Can you please give me a hand with this warning?
Quote
gcc -Wall -Zomf -c -O2 pmstars.c -o pmstars.obj
pmstars.c: In function 'ClientWndProc':
pmstars.c:60:16: warning: variable 'my_timer' set but not used [-Wunused-but-set-variable]
   60 |   static ULONG my_timer;  /* System (PM) number indicating unique (system) timer number
      |                ^~~~~~~~

Calling WinStopTimer on it at cleanup time might be the most "proper" way of dealing with that.  However, a quicker and cheaper way of eliminating the warning is probably to add:

Code: [Select]
if ( my_timer ) {;}   /* stop compiler from complaining */
after the call to WinStartTimer.