executing external program from a gui/window - better use System or OpenWbObject() [Solved]

23 posts / 0 new
Last post
Nube
Nube's picture
Offline
Last seen: 4 years 10 months ago
Joined: 2012-09-10 02:09
executing external program from a gui/window - better use System or OpenWbObject() [Solved]

I don't know if it is the right place for this topic, in case it is not right please move it in right location of the forum.

What I am trying to achieve is to execute an external program from a gui. When user click the button, it run the program. My work is based from this documentation that I found using Google. It is the amiga wiki page. Here is the link of the page:

http://wiki.amigaos.net/wiki/Executing_External_Programs

First i created this simple program to test if it works and indeed it works. When I place this little program inside the directory where the program is, it works without problems but when I insert this little piece of code inside my main project, it runs but the main window of the program trashes and then the system freezes. I suspect I need more code to add but I don't know where to look at..

Test program:

  1. #include <stdio.h>
  2. #include <proto/exec.h>
  3. #include <proto/dos.h>
  4. #include <dos/dostags.h>
  5.  
  6. CONST_STRPTR command = "mame rastan cgfx requester frameskip 1 rate 22050";
  7. BPTR file;
  8. uint8 *autoconsole="CON:0/0/600/150/Mame/AUTO/CLOSE/WAIT";
  9.  
  10. int main(){
  11. if(file = IDOS->Open(autoconsole,MODE_OLDFILE)){
  12.  
  13. return IDOS->SystemTags(command,
  14. SYS_Input, file,
  15. SYS_Asynch, TRUE,
  16. SYS_Output, NULL,
  17. SYS_UserShell, TRUE,
  18. TAG_END);
  19. }
  20. else return(RETURN_FAIL);
  21. }

Code inside main project:

  1. // MAME GUI by Davide "Nubechecorre" Palombo
  2. // use "gcc -o mamegui mamegui.c" to compile
  3.  
  4. // Include required libraries and gadgets classes
  5.  
  6. #include <stdio.h>
  7. #include <proto/exec.h>
  8. #include <proto/dos.h>
  9. #include <proto/intuition.h>
  10. #include <proto/listbrowser.h>
  11. #include <proto/wb.h>
  12. #include <dos/dostags.h>
  13.  
  14. #include <classes/window.h>
  15. #include <gadgets/button.h>
  16. #include <gadgets/layout.h>
  17. #include <gadgets/listbrowser.h>
  18. #include <gadgets/checkbox.h>
  19. #include <gadgets/slider.h>
  20. #include <gadgets/radiobutton.h>
  21. #include <gadgets/scroller.h>
  22. #include <gadgets/integer.h>
  23. #include <images/label.h>
  24. #include <images/bitmap.h>
  25.  
  26. // Declare all the struct libraries and Intefaces
  27.  
  28. struct ClassLibrary *WindowBase;
  29. Class *WindowClass;
  30.  
  31. struct ClassLibrary *LayoutBase;
  32. Class *LayoutClass;
  33.  
  34. struct ClassLibrary *ButtonBase;
  35. Class *ButtonClass;
  36.  
  37. struct ClassLibrary *LabelBase;
  38. Class *LabelClass;
  39.  
  40. struct ClassLibrary *BitMapBase;
  41. Class *BitMapClass;
  42.  
  43. struct ClassLibrary *CheckBoxBase;
  44. Class *CheckBoxClass;
  45.  
  46. struct ClassLibrary *SliderBase;
  47. Class *SliderClass;
  48.  
  49. struct ClassLibrary *ScrollerBase;
  50. Class *ScrollerClass;
  51.  
  52. struct ClassLibrary *IntegerBase;
  53. Class *IntegerClass;
  54.  
  55. struct ClassLibrary *RadioButtonBase;
  56. Class *RadioButtonClass;
  57.  
  58. struct Library *ListBrowserBase;
  59. Class *ListBrowserClass;
  60. struct ListBrowserIFace *IListBrowser;
  61.  
  62. struct Library *IntuitionBase;
  63. struct IntuitionIFace *IIntuition;
  64.  
  65. struct Library *WorkbenchBase;
  66. struct WorkbenchIFace *IWorkbench;
  67.  
  68. // Struct Window for my Window App
  69.  
  70. struct Window *window;
  71.  
  72. // Struct Screen for the image to be displayed
  73.  
  74. struct Screen *screen;
  75.  
  76. // Struct List for listbrowser, ColumnInfo and Node
  77.  
  78. struct List *listbrowser_list;
  79. struct Node *node;
  80.  
  81. // Populate the listbrowser node
  82.  
  83. CONST_STRPTR nodetexts[] = {
  84. "Double Dragon",
  85. "Rastan",
  86. "Street Fighter",
  87. "Operation Wolf",
  88. "Out Run",
  89. "Dragon Ninja",
  90. "Ninja Warriors",
  91. "Operation Thunderbolt",
  92. "Turbo Outrun",
  93. "Knights of the round",
  94. NULL
  95. };
  96.  
  97. // With C "Enum" and "Object *" I create/enumerate all the elements for my Gui
  98.  
  99. enum{
  100. OID_WINDOW,
  101. OID_WINDOW_LAYOUT,
  102. OID_BANNER,
  103. OID_BITMAP,
  104. OID_CONTAINER,
  105. OID_LISTBROWSER,
  106. OID_CONTAINER_TOP,
  107. OID_CHECKBOX_1,
  108. OID_CHECKBOX_2,
  109. OID_CHECKBOX_3,
  110. OID_CHECKBOX_4,
  111. OID_CHECKBOX_5,
  112. OID_HLAYOUT,
  113. OID_VLAYOUT_1,
  114. OID_VLAYOUT_2,
  115. OID_INTEGER,
  116. OID_SLIDER,
  117. OID_RADIOBUTTON,
  118. OID_LAYOUT_L,
  119. OID_LAYOUT_R,
  120. OID_LAYOUT_SOUND,
  121. OID_BSTART,
  122. OID_LAST
  123. };
  124.  
  125. Object *objects[OID_LAST];
  126.  
  127. // This is the minimun amount of stack for my program
  128.  
  129. static const char USED minstack[]="$STACK:80000";
  130.  
  131. // This is the string used for the version command under CLI/SHELL to see the version of the program
  132.  
  133. STATIC CONST_STRPTR version USED = "$VER: mamegui version 1.0 (06.05.2018)";
  134.  
  135. // This is the string used to run the program
  136.  
  137. CONST_STRPTR command = "mame rastan cgfx requester frameskip 1 rate 22050";
  138.  
  139. // file to use as buffer for the console
  140.  
  141. BPTR file;
  142.  
  143. // console to use for command
  144.  
  145. uint8 *autoconsole="CON:0/0/600/150/mame/AUTO/CLOSE/WAIT";
  146.  
  147. // This is the main loop of the program
  148.  
  149. int main(){
  150.  
  151. // initialize variable for later use in the listbrowser
  152.  
  153. int i;
  154.  
  155. // Create radiobutton label list
  156. CONST_STRPTR radiolist[] = {"11025","22050",NULL};
  157.  
  158. // Here I open all the required libraries and classes
  159.  
  160. IntuitionBase = IExec->OpenLibrary("intuition.library", 52);
  161. if(IntuitionBase == NULL){
  162. IDOS->Printf("Unable to get IntuitionBase pointer, unable to open the library\n");
  163. }else{
  164. IDOS->Printf("Get IntuitionBase pointer, library opened \n");
  165. }
  166. IIntuition = (struct IntuitionIFace *)IExec->GetInterface(IntuitionBase,"main",1,NULL);
  167. if(IIntuition == NULL){
  168. IDOS->Printf("Unable to get Intuition Interface\n");
  169. return(0);
  170. }else{
  171. IDOS->Printf("Get Intuition Interface\n");
  172. }
  173.  
  174. WorkbenchBase = IExec->OpenLibrary("workbench.library", 52);
  175. if(WorkbenchBase == NULL){
  176. IDOS->Printf("Unable to get WorkbenchBase pointer, unable to open the library\n");
  177. }else{
  178. IDOS->Printf("Get WorkbenchBase pointer, library opened \n");
  179. }
  180. IWorkbench = (struct WorkbenchIFace *)IExec->GetInterface(WorkbenchBase,"main",1,NULL);
  181. if(IWorkbench == NULL){
  182. IDOS->Printf("Unable to get Workbench Interface\n");
  183. return(0);
  184. }else{
  185. IDOS->Printf("Get Workbench Interface\n");
  186. }
  187.  
  188. WindowBase = IIntuition->OpenClass("window.class", 52, &WindowClass);
  189. if(WindowBase == NULL){
  190. IDOS->Printf("Unable to get WindowBase, unable to get Window Class\n");
  191. return(0);
  192. }else{
  193. IDOS->Printf("Get WindowBase pointer, Window Class opened\n");
  194. }
  195.  
  196. LayoutBase = IIntuition->OpenClass("gadgets/layout.gadget", 52, &LayoutClass);
  197. if(LayoutBase == NULL){
  198. IDOS->Printf("Unable to get LayoutBase, unable to open Layout Class\n");
  199. return(0);
  200. }else{
  201. IDOS->Printf("Get LayoutBase, Layout Class opened\n");
  202. }
  203.  
  204. ButtonBase = (struct ClassLibrary *)IIntuition->OpenClass("gadgets/button.gadget", 52, &ButtonClass);
  205. if(ButtonBase == NULL){
  206. IDOS->Printf("Unable to GetButtonBase, unable to open Button Class\n");
  207. return(0);
  208. }else{
  209. IDOS->Printf("Get ButtonBase, Button Class opened\n");
  210. }
  211.  
  212. LabelBase = (struct ClassLibrary *)IIntuition->OpenClass("images/label.image", 52, &LabelClass);
  213. if(LabelBase == NULL){
  214. IDOS->Printf("Unable to get LabelBase, unable to open Label Class\n");
  215. return(0);
  216. }else{
  217. IDOS->Printf("Get LabelBase, Label Class opened\n");
  218. }
  219.  
  220. BitMapBase = (struct ClassLibrary *)IIntuition->OpenClass("images/bitmap.image", 52, &BitMapClass);
  221. if(BitMapBase == NULL){
  222. IDOS->Printf("Unable to get BitMapBase, unable to open BitMap Class\n");
  223. return(0);
  224. }else{
  225. IDOS->Printf("Get BitMapBase, BitMap Class opened\n");
  226. }
  227.  
  228. ListBrowserBase = (struct Library *)IIntuition->OpenClass("gadgets/listbrowser.gadget", 52, &ListBrowserClass);
  229. if(ListBrowserBase == NULL){
  230. IDOS->Printf("Unable to get ListBrowserBase, unable to open ListBrowser Class\n");
  231. return(0);
  232. }else{
  233. IDOS->Printf("Get ListBrowserBase, ListBrowser Class opened\n");
  234. }
  235.  
  236. IListBrowser = (struct ListBrowserIFace *)IExec->GetInterface((struct Library *)ListBrowserBase,"main",1,NULL);
  237. if(IListBrowser == NULL){
  238. IDOS->Printf("Unable to get ListBrowser Interface\n");
  239. return(0);
  240. }else{
  241. IDOS->Printf("Get ListBrowser Interface\n");
  242. }
  243.  
  244. CheckBoxBase = IIntuition->OpenClass("gadgets/checkbox.gadget", 52, &CheckBoxClass);
  245. if(CheckBoxBase == NULL){
  246. IDOS->Printf("Unable to get CheckBoxBase, unable to open CheckBox Class\n");
  247. return(0);
  248. }else{
  249. IDOS->Printf("Get CheckBoxBase, CheckBox Class opened\n");
  250. }
  251.  
  252. SliderBase = IIntuition->OpenClass("gadgets/slider.gadget", 52, &SliderClass);
  253. if(SliderBase == NULL){
  254. IDOS->Printf("Unable to get SliderBase, unable to open Slider Class\n");
  255. return(0);
  256. }else{
  257. IDOS->Printf("Get SliderBase, Slider Class opened\n");
  258. }
  259.  
  260. ScrollerBase = IIntuition->OpenClass("gadgets/scroller.gadget", 52, &ScrollerClass);
  261. if(ScrollerBase == NULL){
  262. IDOS->Printf("Unable to get ScrollerBase, unable to open Scroller Class\n");
  263. return(0);
  264. }else{
  265. IDOS->Printf("Get ScrollerBase, Scroller Class opened\n");
  266. }
  267.  
  268. RadioButtonBase = IIntuition->OpenClass("gadgets/radiobutton.gadget", 52, &RadioButtonClass);
  269. if(RadioButtonBase == NULL){
  270. IDOS->Printf("Unable to get RadioButtonBase, unable to open RadioButton Class\n");
  271. return(0);
  272. }else{
  273. IDOS->Printf("Get RadioButtonBase, RadioButton Class opened\n");
  274. }
  275.  
  276. IntegerBase = IIntuition->OpenClass("gadgets/integer.gadget", 52, &IntegerClass);
  277. if(IntegerBase == NULL){
  278. IDOS->Printf("Unable to get IntegerBase, unable to open Integer Class\n");
  279. return(0);
  280. }else{
  281. IDOS->Printf("Get IntegerBase, Integer Class opened\n");
  282. }
  283.  
  284. // Allocate the listbrowser list.
  285. listbrowser_list = (struct List *) IExec->AllocSysObject(ASOT_LIST, NULL);
  286. if (listbrowser_list == NULL)
  287. {
  288. // Here you should free the resources allocated above
  289. // and report memory error; we'll just exit for now.
  290. return RETURN_FAIL;
  291. }
  292.  
  293. // Loop to populate ListBrowser list and Node
  294. for (i=0; nodetexts<em>; i++)
  295. {
  296. node = IListBrowser->AllocListBrowserNode(1,
  297. //LBNA_Flags, LBFLG_CUSTOMPENS,
  298. LBNA_Column, 0,
  299. LBNCA_Text, nodetexts<em>,
  300. //LBNCA_FGPen, TEXTPEN,
  301. TAG_END);
  302.  
  303. if (node) IExec->AddTail(listbrowser_list, node);
  304. }
  305.  
  306. if(screen = IIntuition->LockPubScreen(NULL)){
  307.  
  308. objects[OID_WINDOW] = IIntuition->NewObject(WindowClass, NULL,
  309. WA_ScreenTitle, "MameGui - By Davide Palombo V. 1.0",
  310. WA_Title, "MameGui",
  311. WA_Width, 800,
  312. WA_Height, 600,
  313. WA_DragBar, TRUE,
  314. WA_CloseGadget, TRUE,
  315. WA_SizeGadget, TRUE,
  316. WA_DepthGadget, TRUE,
  317. WA_Activate, TRUE,
  318. WINDOW_IconifyGadget, TRUE,
  319. WINDOW_Position, WPOS_CENTERSCREEN,
  320. WA_NewLookMenus, TRUE,
  321. WA_FadeTime, 800000,
  322. WA_AutoAdjust, TRUE,
  323. WA_PubScreen, screen,
  324. WINDOW_GadgetHelp, TRUE,
  325. WINDOW_Layout, objects[OID_WINDOW_LAYOUT] = IIntuition->NewObject(LayoutClass, NULL,
  326. LAYOUT_Orientation, LAYOUT_ORIENT_VERT,
  327. LAYOUT_SpaceOuter, TRUE,
  328.  
  329. LAYOUT_AddChild, objects[OID_BANNER] = IIntuition->NewObject(LayoutClass, NULL,
  330. LAYOUT_Orientation, LAYOUT_ORIENT_HORIZ,
  331. LAYOUT_SpaceOuter, TRUE,
  332. LAYOUT_VertAlignment, LALIGN_TOP,
  333. LAYOUT_AddImage, objects[OID_BITMAP] = IIntuition->NewObject(BitMapClass, NULL,
  334. BITMAP_Screen, screen,
  335. BITMAP_Masking, TRUE,
  336. BITMAP_Transparent, TRUE,
  337. BITMAP_OffsetX, 0,
  338. BITMAP_OffsetY, 0,
  339. BITMAP_Width, 400,
  340. BITMAP_Height, 138,
  341. BITMAP_SourceFile, "PROGDIR:img/logo-mame.png",
  342. TAG_END), // end of BitMap Object
  343. TAG_END), // end of oid_banner
  344.  
  345. LAYOUT_AddChild, objects[OID_CONTAINER] = IIntuition->NewObject(LayoutClass, NULL,
  346. LAYOUT_Orientation, LAYOUT_ORIENT_HORIZ,
  347. LAYOUT_SpaceOuter, TRUE,
  348.  
  349. LAYOUT_AddChild, objects[OID_LAYOUT_L] = IIntuition->NewObject(LayoutClass, NULL,
  350. LAYOUT_Orientation, LAYOUT_ORIENT_VERT,
  351. LAYOUT_SpaceOuter, TRUE,
  352. LAYOUT_AddChild, IIntuition->NewObject(LayoutClass, NULL,
  353. LAYOUT_Orientation, LAYOUT_ORIENT_VERT,
  354. LAYOUT_SpaceOuter, TRUE,
  355. LAYOUT_BevelStyle, BVS_GROUP,
  356. LAYOUT_Label, " Games List ",
  357.  
  358. LAYOUT_AddChild, objects[OID_LISTBROWSER] = IIntuition->NewObject(ListBrowserClass, NULL,
  359. LISTBROWSER_Labels, listbrowser_list,
  360. LISTBROWSER_MultiSelect, FALSE,
  361. LISTBROWSER_ShowSelected, TRUE,
  362. TAG_END), // end of ListBrowser
  363.  
  364. TAG_END), // end of bvs_group games_list
  365. TAG_END), // end of oid_layout_l
  366.  
  367. LAYOUT_AddChild, objects[OID_LAYOUT_R] = IIntuition->NewObject(LayoutClass, NULL,
  368. LAYOUT_Orientation, LAYOUT_ORIENT_VERT,
  369. LAYOUT_SpaceOuter, TRUE,
  370. LAYOUT_AddChild, IIntuition->NewObject(LayoutClass, NULL,
  371. LAYOUT_Orientation, LAYOUT_ORIENT_VERT,
  372. LAYOUT_SpaceOuter, TRUE,
  373. LAYOUT_BevelStyle, BVS_GROUP,
  374. LAYOUT_Label, " Screenshots ",
  375. TAG_END), // end of bvs_group screenshots
  376.  
  377. LAYOUT_AddChild, IIntuition->NewObject(LayoutClass, NULL,
  378. LAYOUT_Orientation, LAYOUT_ORIENT_VERT,
  379. LAYOUT_SpaceOuter, TRUE,
  380. LAYOUT_BevelStyle, BVS_GROUP,
  381. LAYOUT_Label, " Options ",
  382.  
  383. LAYOUT_AddChild, objects[OID_CONTAINER_TOP] = IIntuition->NewObject(LayoutClass, NULL,
  384. LAYOUT_Orientation, LAYOUT_ORIENT_HORIZ,
  385. //LAYOUT_SpaceOuter, TRUE,
  386.  
  387. LAYOUT_AddChild, objects[OID_VLAYOUT_1] = IIntuition->NewObject(LayoutClass, NULL,
  388. LAYOUT_Orientation,LAYOUT_ORIENT_VERT,
  389.  
  390. LAYOUT_AddChild, objects[OID_CHECKBOX_1] = IIntuition->NewObject(CheckBoxClass, NULL,
  391. GA_ID, OID_CHECKBOX_1,
  392. GA_RelVerify, TRUE,
  393. GA_Text, "_Request",
  394. GA_HintInfo, "A requester pops up asking you for the right screen mode to open",
  395. GA_Selected, FALSE,
  396. CHECKBOX_TextPlace, PLACETEXT_RIGHT,
  397. TAG_END), // end of chekbox_1
  398.  
  399. LAYOUT_AddChild, objects[OID_CHECKBOX_2] = IIntuition->NewObject(CheckBoxClass, NULL,
  400. GA_ID, OID_CHECKBOX_2,
  401. GA_RelVerify, TRUE,
  402. GA_HintInfo, "Enable/Disable the Joypad",
  403. GA_Selected, FALSE,
  404. GA_Text, "_Joypad",
  405. CHECKBOX_TextPlace, PLACETEXT_RIGHT,
  406. TAG_END), // end of chekbox_2
  407.  
  408. TAG_END), // end of vlayout_1
  409.  
  410. LAYOUT_AddChild, objects[OID_VLAYOUT_2] = IIntuition->NewObject(LayoutClass, NULL,
  411. LAYOUT_Orientation,LAYOUT_ORIENT_VERT,
  412.  
  413. LAYOUT_AddChild, objects[OID_CHECKBOX_4] = IIntuition->NewObject(CheckBoxClass, NULL,
  414. GA_ID, OID_CHECKBOX_4,
  415. GA_RelVerify, TRUE,
  416. GA_HintInfo, "use CyberGraphics instead of direct gfxmem access",
  417. GA_Selected, FALSE,
  418. GA_Text, "_Cgfx",
  419. CHECKBOX_TextPlace, PLACETEXT_RIGHT,
  420. TAG_END), // end of chekbox_4
  421.  
  422. LAYOUT_AddChild, objects[OID_HLAYOUT] = IIntuition->NewObject(LayoutClass, NULL,
  423. LAYOUT_Orientation, LAYOUT_ORIENT_HORIZ,
  424. //LAYOUT_SpaceInner, TRUE,
  425. LAYOUT_VertAlignment, LALIGN_BOTTOM,
  426.  
  427. LAYOUT_AddChild, objects[OID_CHECKBOX_5] = IIntuition->NewObject(CheckBoxClass, NULL,
  428. GA_ID, OID_CHECKBOX_5,
  429. GA_RelVerify, TRUE,
  430. GA_HintInfo, "frameskip 1-9 (def: 3)",
  431. GA_Selected, FALSE,
  432. GA_Text, "_Frameskip",
  433. CHECKBOX_TextPlace, PLACETEXT_RIGHT,
  434. TAG_END), // end of chekbox_5
  435.  
  436. LAYOUT_AddChild, objects[OID_INTEGER] = IIntuition->NewObject(IntegerClass, NULL,
  437. GA_ID, OID_INTEGER,
  438. GA_RelVerify, TRUE,
  439. GA_Disabled, TRUE,
  440. INTEGER_Arrows, TRUE,
  441. INTEGER_MaxChars, 3,
  442. INTEGER_Minimum, 0,
  443. INTEGER_Maximum, 9,
  444. INTEGER_Number, 0,
  445. TAG_END), // end of oid_integer
  446.  
  447. TAG_END), // end of hlayout
  448.  
  449. TAG_END), // end of vlayout_2
  450.  
  451. TAG_END), // end of container_top
  452.  
  453. LAYOUT_AddChild, IIntuition->NewObject(LayoutClass, NULL,
  454. LAYOUT_Orientation, LAYOUT_ORIENT_HORIZ,
  455. //LAYOUT_SpaceOuter, TRUE,
  456. LAYOUT_BevelStyle, BVS_GROUP,
  457. LAYOUT_Label, " Sound ",
  458.  
  459. LAYOUT_AddChild, objects[OID_LAYOUT_SOUND] = IIntuition->NewObject(LayoutClass, NULL,
  460. LAYOUT_Orientation, LAYOUT_ORIENT_HORIZ,
  461. //LAYOUT_SpaceOuter, TRUE,
  462. LAYOUT_AddChild, objects[OID_CHECKBOX_3] = IIntuition->NewObject(CheckBoxClass, NULL,
  463. GA_ID, OID_CHECKBOX_3,
  464. GA_RelVerify, TRUE,
  465. GA_HintInfo, "Enable/Disable sound emulation",
  466. GA_Selected, FALSE,
  467. GA_Text, "_Sound",
  468. GA_Disabled, FALSE,
  469. CHECKBOX_TextPlace, PLACETEXT_RIGHT,
  470. TAG_END), // end of chekbox_3
  471.  
  472. LAYOUT_AddChild, objects[OID_RADIOBUTTON] = IIntuition->NewObject(RadioButtonClass, NULL,
  473. GA_ID, OID_RADIOBUTTON,
  474. GA_RelVerify, TRUE,
  475. GA_Text, radiolist,
  476. GA_Disabled, TRUE,
  477. RADIOBUTTON_Selected, 1,
  478. TAG_END), // end of radio_button
  479.  
  480. TAG_END), // end of oid_layout_sound
  481.  
  482. TAG_END), // end of bvs_group sound
  483.  
  484. TAG_END), // end of bvs_group options
  485.  
  486. TAG_END), // end of oid_layout_r
  487.  
  488. TAG_END), // end of oid_container
  489.  
  490. LAYOUT_AddChild, objects[OID_BSTART] = IIntuition->NewObject(ButtonClass, NULL,
  491. GA_ID, OID_BSTART,
  492. GA_RelVerify, TRUE,
  493. GA_Text, "Start",
  494. TAG_END),
  495.  
  496. TAG_END), // end of window_layout
  497. TAG_END); // end of window
  498. }
  499. if(objects[OID_WINDOW] != NULL)
  500. {
  501. struct Window *window = (struct Window *)IIntuition->IDoMethod(objects[OID_WINDOW], WM_OPEN, NULL);
  502. if(window != NULL)
  503. {
  504. uint32 signal = 0;
  505. IIntuition->GetAttr(WINDOW_SigMask,objects[OID_WINDOW],&signal);
  506. BOOL done = FALSE;
  507.  
  508. // Our window is open, we can unlock the public screen.
  509. IIntuition->UnlockPubScreen(NULL, screen);
  510.  
  511. while(!done)
  512. {
  513. uint32 wait = IExec->Wait(signal|SIGBREAKF_CTRL_C);
  514.  
  515. if(wait & SIGBREAKF_CTRL_C)
  516. {
  517. done = TRUE;
  518. break;
  519. }
  520.  
  521. if(wait & signal)
  522. {
  523. uint32 result = WMHI_LASTMSG;
  524. int16 code = 0;
  525. uint32 selected = 0;
  526. BOOL chk_sel = FALSE;
  527.  
  528. while((result = IIntuition->IDoMethod(objects[OID_WINDOW],WM_HANDLEINPUT,&code)) != WMHI_LASTMSG)
  529. {
  530. switch(result & WMHI_CLASSMASK) //CLASSMASK RESTITUISCE LA PARTE BASSA DELLA WORD (L'ID)
  531. {
  532. case WMHI_GADGETUP:
  533. switch(result & WMHI_GADGETMASK) //LA GADGETMASK INVECE RESTITUISCE LA PARTE ALTA DELLA WORD IL BIT
  534. {
  535. case OID_CHECKBOX_1:
  536. IDOS->Printf("Hai premuto il checkbox_1\n");
  537. break;
  538.  
  539. case OID_CHECKBOX_2:
  540. IDOS->Printf("Hai premuto il checkbox_2\n");
  541. break;
  542.  
  543. case OID_RADIOBUTTON:
  544. IIntuition->GetAttr(RADIOBUTTON_Selected, objects[OID_RADIOBUTTON], &selected);
  545. IDOS->Printf("Hai premuto il RadioButton: codice=%lu scelta=%lu\n", code, selected);
  546. break;
  547.  
  548. case OID_CHECKBOX_3:
  549. IIntuition->GetAttr(GA_Selected, objects[OID_CHECKBOX_3], &selected);
  550. IDOS->Printf("Hai premuto il checkbox sound: codice=%lu scelta=%lu\n", code, selected);
  551. if(selected==1){
  552. IIntuition->RefreshSetGadgetAttrs((struct Gadget *)objects[OID_RADIOBUTTON],
  553. (struct Window *)window,
  554. NULL,
  555. GA_Disabled,FALSE,
  556. TAG_END);
  557. }
  558.  
  559. if(selected==0){
  560. IIntuition->RefreshSetGadgetAttrs((struct Gadget *)objects[OID_RADIOBUTTON],
  561. (struct Window *)window,
  562. NULL,
  563. GA_Disabled,TRUE,
  564. TAG_END);
  565. }
  566. break;
  567.  
  568. case OID_CHECKBOX_5:
  569. IIntuition->GetAttr(GA_Selected, objects[OID_CHECKBOX_5], &selected);
  570. IDOS->Printf("Hai premuto il checkbox frameskip: codice=%lu scelta=%lu\n", code, selected);
  571. if(selected==1){
  572. IIntuition->RefreshSetGadgetAttrs((struct Gadget *)objects[OID_INTEGER],
  573. (struct Window *)window,
  574. NULL,
  575. GA_Disabled,FALSE,
  576. TAG_END);
  577. }
  578.  
  579. if(selected==0){
  580. IIntuition->RefreshSetGadgetAttrs((struct Gadget *)objects[OID_INTEGER],
  581. (struct Window *)window,
  582. NULL,
  583. GA_Disabled,TRUE,
  584. TAG_END);
  585. }
  586. break;
  587.  
  588. case OID_BSTART:
  589. if(file = IDOS->Open(autoconsole,MODE_OLDFILE)){
  590. return IDOS->SystemTags(command,
  591. SYS_Input, file,
  592. SYS_Output, NULL,
  593. SYS_Asynch, TRUE,
  594. SYS_UserShell, TRUE,
  595. TAG_END);
  596. }
  597. else return(RETURN_FAIL);
  598. break;
  599.  
  600. }
  601. break;
  602. case WMHI_CLOSEWINDOW:
  603. window = NULL;
  604. done = TRUE;
  605. break;
  606. }
  607. }
  608. }
  609. }
  610. }
  611.  
  612. // Dispose/Close all object and libraries/classes resources
  613.  
  614. IIntuition->DisposeObject(objects[OID_WINDOW]);
  615.  
  616. if(listbrowser_list){
  617. // Free the allocated list nodes.
  618. IListBrowser->FreeListBrowserList(listbrowser_list);
  619. // Free the allocated list structure.
  620. IExec->FreeSysObject(ASOT_LIST, listbrowser_list);
  621. }
  622.  
  623. if(WindowBase){
  624. IIntuition->CloseClass(WindowBase);
  625. IDOS->Printf("Window Class Closed\n");
  626. }
  627. if(LayoutBase){
  628. IIntuition->CloseClass(LayoutBase);
  629. IDOS->Printf("Layout Class Closed\n");
  630. }
  631. if(ButtonBase){
  632. IIntuition->CloseClass(ButtonBase);
  633. IDOS->Printf("Button Class Closed\n");
  634. }
  635. if(LabelBase){
  636. IIntuition->CloseClass(LabelBase);
  637. IDOS->Printf("LabelBase Class Closed\n");
  638. }
  639. if(BitMapBase){
  640. IIntuition->CloseClass(BitMapBase);
  641. IDOS->Printf("BitMap Class Closed\n");
  642. }
  643. if(CheckBoxBase){
  644. IIntuition->CloseClass(CheckBoxBase);
  645. IDOS->Printf("CheckBox Class Closed\n");
  646. }
  647. if(SliderBase){
  648. IIntuition->CloseClass(SliderBase);
  649. IDOS->Printf("Slider Class Closed\n");
  650. }
  651. if(RadioButtonBase){
  652. IIntuition->CloseClass(RadioButtonBase);
  653. IDOS->Printf("RadioButton Class Closed\n");
  654. }
  655. if(ScrollerBase){
  656. IIntuition->CloseClass(ScrollerBase);
  657. IDOS->Printf("Scroller Class Closed\n");
  658. }
  659. if(IntegerBase){
  660. IIntuition->CloseClass(IntegerBase);
  661. IDOS->Printf("Integer Class Closed\n");
  662. }
  663. if(ListBrowserBase){
  664. IExec->DropInterface((struct Interface *)IListBrowser);
  665. IIntuition->CloseClass((struct ClassLibrary *)ListBrowserBase);
  666. IDOS->Printf("ListBrowser Class Closed\n");
  667. }
  668.  
  669. if(WorkbenchBase){
  670. IExec->DropInterface((struct Interface *)IWorkbench);
  671. IDOS->Printf("Workbench Interface Dropped\n");
  672. IExec->CloseLibrary(WorkbenchBase);
  673. IDOS->Printf("Workbench Library Closed\n");
  674. }
  675.  
  676. if(IntuitionBase){
  677. IExec->DropInterface((struct Interface *)IIntuition);
  678. IDOS->Printf("Intuition Interface Dropped\n");
  679. IExec->CloseLibrary(IntuitionBase);
  680. IDOS->Printf("Intuition Library Closed\n");
  681. }
  682. if(DOSBase){
  683. IExec->DropInterface((struct Interface *)IDOS);
  684. printf("Dos Interface Dropped\n");
  685. IExec->CloseLibrary(DOSBase);
  686. printf("Dos Library Closed\n");
  687. }
  688. }
  689.  
  690. // End of my program - RETURN_OK
  691.  
  692. return RETURN_OK;
  693. }

before using the System() function I tried to use the WBOpenObject() function but i wasn't able to pass argument to the program so I tried the System() function thinking it was the right function to use but I have the problem above.. Any hint on where to find proper example or documentation?

Thanks,

Nube
Nube's picture
Offline
Last seen: 4 years 10 months ago
Joined: 2012-09-10 02:09
Re: executing external program from a gui/window - better use...

Maybe I solved the problem but tell me if my solution is the right one..

I used this code when the user press the start button:

  1. case OID_BSTART:
  2. if(file = IDOS->FOpen(autoconsole,MODE_OLDFILE,0)){
  3. error = IDOS->SystemTags(command,
  4. SYS_Input, file,
  5. SYS_Output, NULL,
  6. SYS_Asynch, TRUE,
  7. SYS_UserShell,FALSE,
  8. TAG_END);
  9. }
  10. if(error != 0){
  11. return(RETURN_FAIL);
  12. }
  13. break;

I changed from IDOS->Open() to IDOS->FOpen(). This function use buffered file so I guessed that could be the reason of trashed window and error when quitting the emulator..

Now i have no more error and trash window when i run the program.. It works both on shell and workbench.

Thanks,

Davide

Nube
Nube's picture
Offline
Last seen: 4 years 10 months ago
Joined: 2012-09-10 02:09
Re: executing external program from a gui/window - better use...

I would like to mark my question as "solved" but I cannot edit my first post.. By the way the problem is solved :)

jabirulo
jabirulo's picture
Offline
Last seen: 4 hours 1 min ago
Joined: 2013-05-30 00:53
Re: executing external program from a gui/window - better use...

Hi, I do use this to execute/launch Time prefs. from a GUI:

  1. /* V52.7 : Execute <command> asynchronusly
  2.   V52.9 : Simplified launch routine
  3.   V52.12: Uses wb_lib (reads icon tooltypes)
  4. */
  5. BOOL beginCommand(char *command)
  6. {
  7. return IWorkbench->OpenWorkbenchObject(command, TAG_DONE); //V52.12: Uses wb_lib (reads icon tooltypes)
  8.  
  9. // return IDOS->SystemTags(command, SYS_Input,NULL, SYS_Output,NULL, /*SYS_Error,NULL,*/
  10. // NP_Priority,0, SYS_Asynch,TRUE, TAG_END); //V52.9 : Simplified launch routine
  11. }

AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P

Nube
Nube's picture
Offline
Last seen: 4 years 10 months ago
Joined: 2012-09-10 02:09
Re: executing external program from a gui/window - better use...

Thanks Jabirulo :)

hypex
hypex's picture
Offline
Last seen: 1 month 2 weeks ago
Joined: 2011-09-09 16:20
Re: executing external program from a gui/window - better use...

Nube, before you go I noticed this. You open a console window for input but not output. Which I see is the standard but strange looking way for providing a console. It's unusual to have a window for input and no window for output. You set SYS_Asynch to TRUE which means the system will close your file so you will need to leave it open. Using Open() is fine for that purpose. But then it looks like your program exits immediately without closing the GUI. It is a test program but using FOpen() over Open() shouldn't make any difference so something else is amiss.

xenic
xenic's picture
Offline
Last seen: 1 year 11 months ago
Joined: 2011-05-07 04:52
Re: executing external program from a gui/window - better use...

@hypex

Nube, before you go I noticed this. You open a console window for input but not output. Which I see is the standard but strange looking way for providing a console. It's unusual to have a window for input and no window for output. You set SYS_Asynch to TRUE which means the system will close your file so you will need to leave it open. Using Open() is fine for that purpose.

According to the dos autodocs, SystemTags will copy SYS_Input to SYS_Output if SYS_Output is 0 (zero). However, he needs to check the SystemTags() return value and close the console if SystemTags() returns -1 (error). If SystemTags() succeeds, SystemTags() will close the console (in SYS_Asynch mode) as you pointed out. If SYS_Input is specified as 0 (zero) then SystemTags() will use NIL: for input.

But then it looks like your program exits immediately without closing the GUI.

Could that be why his window is being trashed?

X1000 - OS 4.1FE

Nube
Nube's picture
Offline
Last seen: 4 years 10 months ago
Joined: 2012-09-10 02:09
Re: executing external program from a gui/window - better use...

@Xenic @hypex

Thanks for the reply. I tried using FOpen() and it immediatly solved the trashed window problem but I have to check, as xenic said, the return value to see if there is an error. About the console, as Xenic said, I red in the Autodocs that if you set SYS_Asynch TRUE and SYS_Output 0 it will copy Input to Output so I guess it is correct..

But then it looks like your program exits immediately without closing the GUI.

When I exit the emulator (with esc key, it is the MAME) it returns to the gui so I can run another game. Then when I quit the gui it free all the allocated resources..

Now I have no more trashed window by the way I have to check the return code from SystemTags as you said :-)

Thanks for the informations! I'll keep you updated!

P.S.: In the meanwhile I added menu with icons and shortcuts and an infowindow using the new infowindowclass

:-)

Rigo
Rigo's picture
Offline
Last seen: 1 year 10 months ago
Joined: 2011-01-24 21:55
Re: executing external program from a gui/window - better use...

Just remember, not everyone will have infowindow.class installed. So unless you only target users with the Enhancer package installed, or provide some other method of showing "About", there may be issues.

Of course, if you are going to provide an alternate "About", it kind of makes using infowindow.class pointless really.

Simon

OldFart
OldFart's picture
Offline
Last seen: 2 hours 33 min ago
Joined: 2010-11-30 14:09
Re: executing external program from a gui/window - better use...

@Nube

A few minor niggles about your code occurred to me, although they won't affect the problem at hand:

1: both in line 70 and line 501 you define a struct Window *window., of which the first one, line 70, may be removed.

2: starting from line 682 you close dos.library preceded by dropping its interface, but hey, you didn't anywhere open c.q get them. And it is not necessary to open c.q. close this library and consequently get and drop the interface as the startup-code will do this for you. You may delete lines 682 upto and including line 687.

3: in line 511 you state while (!done). You assume here that one of the boolean states applied to this variable is 0.'done' is a boolean and has therefore 2 defined states, 'TRUE' and 'FALSE', and 65534 undefined states. Only set the variable with either 'TRUE' or 'FALSE' and test the variable against either 'TRUE' or 'FALSE' (in UNNEGATED form!). 'TRUE' is not equivalent to '!FALSE' and 'FALSE' is not equivalent to '!TRUE'. Also avoid, for the same reason, testing with a negated comparison, like while (done != TRUE). Use: while (done == FALSE) and never fall prey to the old April's fool-prank of assigning differnet values to the macro's TRUE and FALSE. I'm speaking here from experience...

OldFart

Nube
Nube's picture
Offline
Last seen: 4 years 10 months ago
Joined: 2012-09-10 02:09
Re: executing external program from a gui/window - better use...

Thanks for the usefull informations :-)

thomas
thomas's picture
Offline
Last seen: 9 hours 20 min ago
Joined: 2011-05-16 14:23
Re: executing external program from a gui/window - better use...

@OldFart:

3. this is nit-picking. In C language zero is defined as boolean false and every non-zero value is treated as boolean true. If you set done to 27, !done will still be 0 and thus false. And !0 is 1.

I agree that you should never do done == TRUE or done != TRUE, but done != FALSE or !done is perfectly ok.

I'd even prefer !done because the ! operator converts the integer with one false and many true values into a bolean with exactly one false and one true value.

Nube
Nube's picture
Offline
Last seen: 4 years 10 months ago
Joined: 2012-09-10 02:09
Re: executing external program from a gui/window - better use...

Thanks Thomas! and thanks to all of you :-)

hypex
hypex's picture
Offline
Last seen: 1 month 2 weeks ago
Joined: 2011-09-09 16:20
Re: executing external program from a gui/window - better use...

@xenic

However, he needs to check the SystemTags() return value and close the console if SystemTags() returns -1 (error).

I agree. Another thing to check.

Could that be why his window is being trashed?

I wonder if it is. But it has more serious problems. Which I'll point out below.

hypex
hypex's picture
Offline
Last seen: 1 month 2 weeks ago
Joined: 2011-09-09 16:20
Re: executing external program from a gui/window - better use...

@Nube

When I exit the emulator (with esc key, it is the MAME) it returns to the gui so I can run another game. Then when I quit the gui it free all the allocated resources..

Using the above code as an example, though it would have changed by now, I was referring to this on line 590:
                                                                                                                return IDOS->SystemTags(command,

This will call SystemTags(), exit the main() routine, and pass the result to DOS. In fact I noticed when ever there is a fail in the set up it will call return(0);. This will exit immediately without freeing any resources. Very bad. :-D

But it gets worse. I compiled your code on my X1000. It doesn't even run. Well I mean it doesn't load up a GUI. The CPU meter goes up for a second and then it totally freezes my system up. I happened to have my debug terminal attached and it killed the system. :-o

It gets to the point of "Get IntegerBase, Integer Class opened" and then full stop. So not only is something amiss, something is very amiss, Very, very, amiss. :-)

I tried to debug it but DB101 just crashes. Which it always does for me even on simple code. First class debugger just a slight embellishment there. Which is unfortunate as clearly a lot of work was put into it. GDB only for us and we don't even have the GUI version of GDB. :-?

jabirulo
jabirulo's picture
Offline
Last seen: 4 hours 1 min ago
Joined: 2013-05-30 00:53
Re: executing external program from a gui/window - better use...

Look into this pice of code:

  1. // Loop to populate ListBrowser list and Node
  2. for (i=0; nodetexts<em>; i++)...

"nodetexts< em >" is wrong and should be "nodetexts[ i ] "

Looks like embedded texteditor changes [ i ] into < em >, just do a find&replace for such piece of code.

AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P

hypex
hypex's picture
Offline
Last seen: 1 month 2 weeks ago
Joined: 2011-09-09 16:20
Re: executing external program from a gui/window - better use...

@jabirulo

"nodetexts< em >" is wrong and should be "nodetexts[ i ] "

Thanks, yes that solves the crash. I saw that. I thought some formatting code was embedded in there and removed it. This was on top of all the '240' codes in it. Looks like it needs a downlink for downloading actual source posted.

In any case now it runs through and just exits. This is a large chunk of code. I wonder if it worked at all? I'm about to get GDB out again and see where it fails. But last time I ran it through GDB it just ran the code when I told it next. Shouldn't do that.

Nube
Nube's picture
Offline
Last seen: 4 years 10 months ago
Joined: 2012-09-10 02:09
Re: executing external program from a gui/window - better use...

That code is now outdated but you need an image to insert and use in the bitmap inside the window layout that's why it doesn't open the window. About the trashed window it is due to a function that i replaced so no more crashes at all. About the listbrowser i think the problem is the parser of the site that replaced the with ..

Nube
Nube's picture
Offline
Last seen: 4 years 10 months ago
Joined: 2012-09-10 02:09
Re: executing external program from a gui/window - better use...

@Rigo

Sorry for the late reply I didn't see your answer sorry... yes I though about the About window and I am thinking to check the infowindow base pointer. If it is not availabe, (the infowindow class is not installed on the system) it will open a normal window with information on it.

:-)

hypex
hypex's picture
Offline
Last seen: 1 month 2 weeks ago
Joined: 2011-09-09 16:20
Re: executing external program from a gui/window - better use...

@Nube

That code is now outdated but you need an image to insert and use in the bitmap inside the window layout that's why it doesn't open the window.

Ah okay. Well as suspected the code is obsolete. And on that note where was the error about the image. ;-)

About the trashed window it is due to a function that i replaced so no more crashes at all

What replacing Open() with FOpen()? If so, then your problem isn't fixed, as using Open() is standard for this purpose. Something else is wrong if you can't use Open() to open a console.

. If it is not availabe, (the infowindow class is not installed on the system) it will open a normal window with information on it.

Your options would include that as well as an EasyRequest() or you can use a TimedDosRequester(). :-)

Nube
Nube's picture
Offline
Last seen: 4 years 10 months ago
Joined: 2012-09-10 02:09
Re: executing external program from a gui/window - better use...

Yes, as I replaced FOpen against Open the problem went away. By The Way I have to recheck it again as, as I said before, the code changed alot so i have to recheck it with open function

Nube
Nube's picture
Offline
Last seen: 4 years 10 months ago
Joined: 2012-09-10 02:09
Re: executing external program from a gui/window - better use...

@Hypex
Just let you know that now with the updated code, it works both with IDOS->Open() and IDOS->FOpen().

hypex
hypex's picture
Offline
Last seen: 1 month 2 weeks ago
Joined: 2011-09-09 16:20
Re: executing external program from a gui/window - better use...

@Nube

Well that's strange. I wonder what changed in your code then? Still I'd like to know why GDB doesn't debug on my system and just runs through. I found this using your code. But your code wouldn't be causing GDB to break and just run through without stopping. It's my problem, I'll deal with it. Good you got it going. :-)

Log in or register to post comments