Hi all,
 
I'm currently trying to fathom out MUI Custom Classes, and I thought I had, until my applicaion started crashing once I used INST_DATA() I would get random crashes.
 
So, I wrote a small test application and it seems to work without crashing so I must be doing something wrong in my main application with regards to INST_DATA(). I've attached my test application and I would really appreciate it if someone could run through my code and see that I'm declaring and calling everything correctly.
 
Also, can the INST_DATA() data structure consist of any variable type? e.g. other structs, pointers, ULONG's etc.
 
Thanks for any advice,
Daniel


Visit http://www.amiga.dk/tumult for MUI-related
information, especially about MUI custom classes.


Yahoo! Groups Sponsor
ADVERTISEMENT
click here


Yahoo! Groups Links

Attachment: makefile
Description: Binary data

/* ansi c */
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

/* system */
#include <exec/exec.h>

/* prototypes */
#include <proto/dos.h>
#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/muimaster.h>

/* definitions */
#define MAKE_ID(a,b,c,d) ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) 
(d))

/* libraries */
struct Library *MUIMasterBase    = NULL;

/* custom classes */
struct MUI_CustomClass *mywin_mcc;

/* structures */
struct mywin_data
        {
                APTR    button;
                STRPTR buffer;
        };

/* prototypes */
ULONG __stdargs DoSuperNew(struct IClass *cl,Object *obj,ULONG tag1,...);
ULONG SAVEDS ASM mywin_despatch(REG(a0,struct IClass *cl), REG(a2,Object *obj), 
REG(a1,Msg msg));

ULONG SAVEDS mywin_new(struct IClass *cl, Object *obj, struct opSet *msg);
ULONG SAVEDS mywin_dispose(struct IClass *cl, Object *obj, Msg msg);
ULONG SAVEDS mywin_setup(struct IClass *cl, Object *obj, Msg msg);
ULONG SAVEDS mywin_cleanup(struct IClass *cl, Object *obj, Msg msg);

/* int main() */
int main(int argc, char *argv[])
        {
                ULONG sigs;
                APTR app, win;

                struct mywin_data *data = NULL;

                /* open library */
                if((MUIMasterBase = OpenLibrary(MUIMASTER_NAME, MUIMASTER_VMIN))!=0)
                        {
                                /* create custom class */
                                if((mywin_mcc = MUI_CreateCustomClass(NULL, 
MUIC_Window, NULL, sizeof(struct mywin_data), mywin_despatch))!=0)
                                        {
                                                /* build interface */
                                                                app = 
ApplicationObject,
                                                                        
MUIA_Application_Title,                         "MUI",
                                                                        
MUIA_Application_Description,           "MUI Test",
                                                                        
MUIA_Application_Base,                          "MUIT",

                                                                        SubWindow, win 
= (Object*)NewObject(mywin_mcc->mcc_Class, NULL, TAG_DONE),
                                                                End;

                                                                if(app)
                                                                        {
                                                                                
/*methods */
                                                                                
DoMethod(win, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, app, 2, 
MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);

                                                                                /* 
open window */
                                                                                
SetAttrs(win, MUIA_Window_Open, TRUE);

                                                                                /* set 
some text */
                                                                                data = 
INST_DATA(mywin_mcc->mcc_Class, win);
                                                                                
if(data)
                                                                                       
 {
                                                                                       
         data->buffer = AllocVec(255, MEMF_ANY|MEMF_CLEAR);
                                                                                       
         if(data->buffer) sprintf(data->buffer, "Simple MUI Custom Class Test");
                                                                                       
 }

                                                                                /* 
main loop */
                                                                                
while(DoMethod(app, MUIM_Application_NewInput, &sigs) != 
MUIV_Application_ReturnID_Quit)
                                                                                       
 {
                                                                                       
         if(sigs)
                                                                                       
                 {
                                                                                       
                         sigs = Wait(sigs|SIGBREAKF_CTRL_C);
                                                                                       
                         if(sigs & SIGBREAKF_CTRL_C) break;
                                                                                       
                 }
                                                                                       
 }

                                                                                /* 
dispose app */
                                                                                
MUI_DisposeObject(app);
                                                                        }

                                                
                                                /* delete custom class */
                                                MUI_DeleteCustomClass(mywin_mcc);
                                        }

                                /* close library */
                                CloseLibrary(MUIMasterBase);
                        }
        }

/* mywin_despatch() */
ULONG SAVEDS ASM mywin_despatch(REG(a0,struct IClass *cl), REG(a2,Object *obj), 
REG(a1,Msg msg))
        {
                switch(msg->MethodID)
                        {
                                case OM_NEW:
                                        return mywin_new(cl,obj,(APTR)msg);

                                case OM_DISPOSE:
                                        return mywin_dispose(cl,obj,(APTR)msg);

                                case MUIM_Setup:
                                        return mywin_setup(cl,obj,(APTR)msg);

                                case MUIM_Cleanup:
                                        return mywin_cleanup(cl,obj,(APTR)msg);
                        }

                return DoSuperMethodA(cl,obj,msg);
        }

/* ULONG SAVEDS mywin_new() */
ULONG SAVEDS mywin_new(struct IClass *cl, Object *obj, struct opSet *msg)
        {
                struct mywin_data *data = NULL;
                APTR button;

                /* create class */
                obj = (Object *)DoSuperNew(cl, obj,
                                MUIA_Window_ID,         MAKE_ID('M','A','I','N'),
                                MUIA_Window_Title,      "MUI",

                                WindowContents, VGroup,
                                        Child, button = SimpleButton("A Simple 
Button"),
                                End,
                        TAG_MORE, msg->ops_AttrList);

                if(obj)
                        {
                                data = INST_DATA(cl, obj);
                                data->button = button;

                                /* return object pointer */
                                return((ULONG)obj);
                        }

                CoerceMethod(cl, obj, OM_DISPOSE);
                return(0);
        }

/* ULONG SAVEDS mywin_dispose() */
ULONG SAVEDS mywin_dispose(struct IClass *cl, Object *obj, Msg msg)
        {
                struct mywin_data *data = INST_DATA(cl, obj);

                if(data->buffer)
                        {       
                                printf("Buffer: %s\n", data->buffer);
                                FreeVec(data->buffer);
                        }

                /* */
                return(DoSuperMethodA(cl, obj));
        }

/* ULONG SAVEDS imwin_setup() */
ULONG SAVEDS mywin_setup(struct IClass *cl, Object *obj, Msg msg)
        {
                struct mywin_data *data = INST_DATA(cl, obj);

                if(!(DoSuperMethodA(cl, obj, msg))) return(FALSE);

                /* */
                return(TRUE);
        }

/* ULONG SAVEDS mywin_cleanup() */
ULONG SAVEDS mywin_cleanup(struct IClass *cl, Object *obj, Msg msg)
        {
                struct mywin_data *data = INST_DATA(cl, obj);

                /* */
                return(DoSuperMethodA(cl, obj));
        }

/* DoSuperNew() */
ULONG __stdargs DoSuperNew(struct IClass *cl,Object *obj,ULONG tag1,...)
        {
                return(DoSuperMethod(cl, obj, OM_NEW, &tag1, NULL));
        }

Reply via email to