string as message argument in c object
I´m VERY newbie to C and to creating externals. I need to pass a string as a messages argument. In this external, when I send the message ‘ getText "a simple string" ‘ the method getText must send exactly the same string to the Max window. I only get weird symbols (always different ones in every max session). The external code is in the attachment.
I suppose this a very simple question (related maybe to proxies), but I’m blocked here after readings tutorials and forum threads.
Thanks in advance for your help.
you need to declare your t_symbol as a pointer.
Here is your corrected code:
////////////////////////// object struct
typedef struct _genomus
///////////////////////// function prototypes
//// standard set
void *genomus_new(t_symbol *s, long argc, t_atom *argv);
void genomus_getText(t_genomus *x, t_symbol *getText);
post("GenoMus – test version\n");
c = class_new("genomus", (method)genomus_new, (method)NULL, sizeof(t_genomus), 0L, 0);
class_addmethod(c, (method)genomus_getText, "getText", A_SYM, 0);
s_genomus_class = c;
t_genomus *x = (t_genomus *)object_alloc(s_genomus_class);
x->s_proxy = proxy_new((t_object *)x, 1, &x->s_value);
x->m_outlet = outlet_new((t_object *)x, NULL);
x->x_getText = NULL;
void genomus_getText(t_genomus *x, t_symbol *getText)
post("received string: %s", getText->s_name);
You might also carefully study the code examples that come with the SDK.
They show a number of useful techniques that you can use in various contexts.
Let me know if the above code works as you want because I just made the corrections without testing the new code.
You have to understand the difference between Max symbols and C strings.
Max symbols are pointers to a data structure that, among other things, contains a pointer to the C string that is associated with the symbol.
void genomus_getText(t_genomus *x, t_symbol getText)
post("received string: %s\n", getText->s_name);
For production code you will need to add safety checks (make sure that getText is not null).
There is a lot to digest in there, but you probably need to spend more time with the SDK documentation.
since i am currenty going through this, here’s a concise external tutorial, albeit dating back to max 4.6 unfortunately :
and these "Flop" xcode projects by Nicolas Danet are a precious set of dummies for beginners like us :
and i could advise to begin with doing some tutorials, it might seem long and too much for a beginning, but it is really a timesaver to know some basics about what you are doing.
Thank you very much to all posters for the astonishing quick responses. Luigi, your code is right. As you all say, I must spent a lot of time exploring the SDK. I’m just at the beginning with development.
See you on the net!
Forums > Dev