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

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4502
  • Karma: +92/-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: 4401
  • Karma: +41/-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: 4401
  • Karma: +41/-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: 4502
  • Karma: +92/-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: 4502
  • Karma: +92/-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: 4401
  • Karma: +41/-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: 4502
  • Karma: +92/-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: 4502
  • Karma: +92/-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: 4401
  • Karma: +41/-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.