Getting path output from object

    Mar 04 2010 | 8:35 pm
    First - I'M A TOTAL NEWBIE, both with my C skills which are a long forgotten memory, as well as with Max external building. So please be merciful - I have cobbled together what follows by cutting and pasting things from the SDK, found code on the web, etc..
    I'm trying to build an external that will deliver the path of the VST plugin directory on Windows, based on the data that is in the Windows registry. I know how to do this task with mxj and Java, but want to avoid using mxj if possible.
    The code below compiles and works, such that if I send the output to a print object (after banging the inlet), I see the correct path in the Max window, but if I instead capture the output to a message box, all of the / characters are stripped out of it. What am I doing wrong? Specific code changes would be greatly appreciated... as would other suggestions/tips for the code in general.
    Thanks, Dan
    #include "ext.h" #include "ext_obex.h" #include #include #include
    ////////////////////////// object struct typedef struct _winvstpath { t_object ob; void *m_outlet1; } t_winvstpath;
    ///////////////////////// function prototypes //// standard set void *winvstpath_new(t_symbol *s, long argc, t_atom *argv); void winvstpath_free(t_winvstpath *x); void winvstpath_assist(t_winvstpath *x, void *b, long m, long a, char *s); void winvstpath_bang(t_winvstpath *x);
    //////////////////////// global class pointer variable void *winvstpath_class; char data[256]; char key1[180]="SOFTWARE\VST"; HKEY hkey; // Handle to registry key unsigned long datalen; // data field length(in), data returned length(out) unsigned long datatype; // #defined in winnt.h (predefined types 0-11)
    int main(void) { t_class *c; c = class_new("winvstpath", (method)winvstpath_new, (method)winvstpath_free,
    (long)sizeof(t_winvstpath), 0L, A_GIMME, 0); class_addmethod(c, (method)winvstpath_assist, "assist", A_CANT, 0); class_addmethod(c, (method)winvstpath_bang, "bang", 0); class_register(CLASS_BOX, c); /* CLASS_NOBOX */ winvstpath_class = c; return 0; }
    void winvstpath_assist(t_winvstpath *x, void *b, long m, long a, char *s) { if (m == ASSIST_INLET) { // inlet sprintf(s, "Bang for path", a); } else { // outlet sprintf(s, "Path for VST folder", a); } }
    void winvstpath_free(t_winvstpath *x) { ; }
    void *winvstpath_new(t_symbol *s, long argc, t_atom *argv) { t_winvstpath *x = NULL; long i; if (x = (t_winvstpath *)object_alloc(winvstpath_class)) { for (i = 0; i < argc; i++) { if ((argv + i)->a_type == A_LONG) { object_post((t_object *)x, "arg %ld: long (%ld)", i, atom_getlong(argv+i)); } else if ((argv + i)->a_type == A_FLOAT) { object_post((t_object *)x, "arg %ld: float (%f)", i, atom_getfloat(argv+i)); } else if ((argv + i)->a_type == A_SYM) { object_post((t_object *)x, "arg %ld: symbol (%s)", i, atom_getsym(argv+i)->s_name); } else { object_error((t_object *)x, "forbidden argument"); } } } x->m_outlet1 = outlet_new((t_object *)x, NULL); return (x); }
    void winvstpath_bang(t_winvstpath *x) { if (!RegOpenKeyExA(HKEY_LOCAL_MACHINE,key1,0,KEY_QUERY_VALUE,&hkey) == ERROR_SUCCESS) { post("Error opening HKLM subkey: %sn",key1); }
    datalen = 255;
    if (RegQueryValueExA(hkey, "VstPluginsPath", NULL, &datatype, data, &datalen) == ERROR_SUCCESS) { outlet_anything(x->m_outlet1,gensym(data),0,NIL); }
    RegCloseKey(hkey); }

    • Mar 05 2010 | 2:37 pm
      Hi Dan,
      Good to see you making your way to this forum ;-). One minor tip for future posts with code is to surround the code block with 'pre' tags so that the indenting is maintained.
      I'm not sure about the / chars being stripped. Are they perhaps chars which are then mis-interpreted?
      If you are passing a path out to the Max universe, you will probably want to use path_nameconform() to get it formatted properly. Maybe this could help to solve the problem too.
      Good luck...
    • Mar 05 2010 | 5:02 pm
      Hi Tim,
      Yes, I will definitely use the right formatting markup codes next time, will make the code much easier to read! ;-)
      Yes, I mistyped in my original post - it was backslashes that were being stripped, not forward slashes. And sure enough, using path_nameconform() to get them converted to forward slashes helped solve the problem.
      Many thanks! Dan