Quick q: code to recognize standalone?

cap10subtext's icon

Could use some ideas on how to detect if the external is built into a standalone application.

Suggestions?

Peter Nyboer's icon

I'm not clear on what you are asking? Do want to know....
1. if a specific external was added to the collective during the standalone building process?
2. if your patch is being run in a standalone/runtime or in Max 5?

1. The Max window prints out all the files added to the standalone when it makes it.
OR
In the file menu, you can use the "List externals and Subpatcher Files" command to print everything in the Max window.
OR
You can use the message "collectfiles" to thispatcher in your main patch - this can be useful.
OR
You can startup your standalone and see if there's an error in the Max window! Note all the problems, and create a shell script, .bat file, or automator to gather all these problematic missing files for your standalone and put them in the right place.

Max Patch
Copy patch and select New From Clipboard in Max.

for 2. :

cap10subtext's icon

That's weird, part of my post went missing... :(

What I'm looking for is a line or two of code in C I can include in my external that tests, on startup, whether the external is being included in an application/collective? Basically it would be if it's being run in a standalone, look for a support folder in a different place.

Sorry this wasn't clear but I'm not sure why part of my post wasn't included in the above.

Luigi Castelli's icon
cap10subtext's icon

Wonderful! Thanks so much, Luigi!

Timothy Place's icon

Here is the code I use for this in Tap.Tools :

    // Check for Environment (Max or Standalone)
    {
        char    appname[256];
        int        isMax = 0;
        appname[0] = '';

        #ifdef MAC_VERSION
            CFBundleRef    bun = CFBundleGetMainBundle();
            CFURLRef    url = CFBundleCopyBundleURL(bun);
            CFStringRef string = CFURLCopyLastPathComponent(url);
            CFStringGetCString(string, appname, 256, 0);
            isMax =    strcmp(appname, "MaxMSP.app");
            CFRelease(string);
        #else
            char    *appname_win;
            HMODULE hMod;
            hMod = GetModuleHandle(NULL);
            GetModuleFileName(hMod, (LPCH)appname, sizeof(appname));

            appname_win = strrchr(appname, '\');
            isMax =    strcmp(appname_win+1, "max.exe");    // Max 4 had a lower case first letter
            if(isMax)    // the above did not match
                isMax =    strcmp(appname_win+1, "Max.exe");    // Max 5 has an upper case first letter
            //post("TT IsMax: %i AppName: %s", isMax, appname_win+1);
        #endif
        is_standalone = (isMax != 0);
    }

cap10subtext's icon

Tim: Thanks so much!