I've got this here code (C++, Allegro and AGUP for the GUI) that's an utter bastard to get to work.
| 1 | |
| 2 | int translate() |
| 3 | { |
| 4 | alert("You pushed my button!", "Isn't this a useful feature?", 0, |
| 5 | "&Yes", "&Definitely", 'y', 'd'); |
| 6 | |
| 7 | return D_O_K; |
| 8 | } |
| 9 | |
| 10 | |
| 11 | |
| 12 | (...) |
| 13 | |
| 14 | DIALOG main_dlg[] = |
| 15 | { |
| 16 | /* (dialog proc) (x) (y) (w) (h) (fg)(bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */ |
| 17 | |
| 18 | /* this element just clears the screen, therefore it should come before the others */ |
| 19 | { d_agup_clear_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }, |
| 20 | |
| 21 | |
| 22 | |
| 23 | { d_agup_edit_proc, 100, 75, 160, 8, 0, 0, 0, 0, LENGTH, 0, word_1, NULL, NULL }, |
| 24 | { d_agup_push_proc, 100, 95, 100, 20, 0, 0, 0, 0, 0, 0, str_trans, 0, translate }, |
| 25 | { quit_proc, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 0, 0, 0 }, |
| 26 | |
| 27 | /* the next two elements don't draw anything */ |
| 28 | { d_yield_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }, |
| 29 | { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL } |
| 30 | }; |
What it does while compiling, is giving this error message:
invalid conversion from `int (*)()' to `void*'
It points to the main_dlg declaration, and seems to be caused by the d_agup_push_proc part.
Now, I've checked an example code that does work:
| 1 | int surprise() |
| 2 | { |
| 3 | alert("You pushed my button!", "Isn't this a useful feature?", 0, |
| 4 | "&Yes", "&Definitely", 'y', 'd'); |
| 5 | |
| 6 | return D_O_K; |
| 7 | } |
| 8 | |
| 9 | (...) |
| 10 | |
| 11 | #define DIS D_DISABLED |
| 12 | #define SEL D_SELECTED |
| 13 | |
| 14 | |
| 15 | DIALOG main_dlg[] = |
| 16 | { |
| 17 | /* proc x y w h fg bg key flags d1 d2 dp dp2 dp3 */ |
| 18 | { d_agup_clear_proc, 0, 0, 320, 240, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 19 | |
| 20 | /* First column */ |
| 21 | { d_agup_check_proc, 5, 25, 100, 12, 0, 0, 0, SEL, 0, 0, (void *)"check box", 0, 0 }, |
| 22 | { d_agup_radio_proc, 5, 50, 100, 12, 0, 0, 0, SEL, 1, 0, (void *)"radio 1", 0, 0 }, |
| 23 | { d_agup_radio_proc, 5, 75, 100, 12, 0, 0, 0, 0, 1, 0, (void *)"radio 2", 0, 0 }, |
| 24 | { d_agup_shadow_box_proc, 5, 100, 100, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 25 | { d_agup_slider_proc, 5, 125, 100, 12, 0, 0, 0, 0, 100, 50, 0, 0, 0 }, |
| 26 | { d_agup_edit_proc, 5, 150, 100, 14, 0, 0, 0, 0, 100, 0, buf2, 0, 0 }, |
| 27 | { d_agup_list_proc, 5, 175, 100, 50, 0, 0, 0, 0, 2, 0, lister, sel2, 0 }, |
| 28 | |
| 29 | /* Buttons */ |
| 30 | { d_agup_button_proc, 110, 25, 100, 20, 0, 0, 0, 0, 0, 0, (void *)"button", 0, 0 }, |
| 31 | { d_agup_push_proc, 110, 50, 100, 20, 0, 0, 0, 0, 0, 0, (void *)"button", 0, surprise }, |
| 32 | { d_agup_button_proc, 215, 25, 100, 20, 0, 0, 0, DIS, 0, 0, (void *)"button", 0, 0 }, |
| 33 | { d_agup_button_proc, 215, 50, 100, 20, 0, 0, 0, DIS|SEL, 0, 0, (void *)"button", 0, 0 }, |
| 34 | |
| 35 | /* Misc */ |
| 36 | #define ICON_DIALOG 12 |
| 37 | { d_agup_icon_proc, 240, 75, 50, 50, 0, 0, 0, 0, 2, 2, 0, 0, 0 }, |
| 38 | { d_agup_text_proc, 240, 130, 75, 12, 0, 0, 0, 0, 0, 0, (void *)"A", 0, 0 }, |
| 39 | #if (ALLEGRO_VERSION == 4) && (ALLEGRO_SUB_VERSION == 0) |
| 40 | /* Allegro 4.0 had a severely broken ctext_proc. */ |
| 41 | { d_agup_ctext_proc, 240 + 75 / 2, 150, 0, 12, 0, 0, 0, 0, 0, 0, (void *)"B", 0, 0 }, |
| 42 | #else |
| 43 | { d_agup_ctext_proc, 240, 150, 75, 12, 0, 0, 0, 0, 0, 0, (void *)"B", 0, 0 }, |
| 44 | #endif |
| 45 | { d_agup_rtext_proc, 240, 170, 75, 12, 0, 0, 0, 0, 0, 0, (void *)"C", 0, 0 }, |
| 46 | { d_agup_textbox_proc, 110, 75, 100, 150, 0, 0, 0, 0, 0, 0, buf3, 0, 0 }, |
| 47 | { d_agup_slider_proc, 215, 75, 12, 100, 0, 0, 0, 0, 100, 50, 0, 0, 0 }, |
| 48 | { d_agup_box_proc, 215, 185, 100, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 49 | { d_agup_slider_proc, 215, 213, 100, 12, 0, 0, 0, DIS, 100, 0, 0, 0, 0 }, |
| 50 | { d_agup_menu_proc, 5, 5, 310, 12, 0, 0, 0, 0, 0, 0, menubar, 0, 0 }, |
| 51 | { quit_proc, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 0, 0, 0 }, |
| 52 | { d_agup_text_proc, 0, 232, 320, 8, 0, 0, 0, 0, 0, 0, version, 0, 0 }, |
| 53 | { d_yield_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 54 | { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } |
| 55 | }; |
That does work. I don't see what I've done wrong :? Anybody able to help me out on this one?
Try an explicit cast on both the string and procedure (void *).
C++ is a lot more strict on casting. Non-void pointers need to be cast to void* (in this case, the translate function pointer you're passing).
That worked. Thanks so much, you two:)