• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Finding the path of your filter plugin programmatically?

Explorer ,
Feb 10, 2011 Feb 10, 2011

Copy link to clipboard

Copied

Hi, I've been trying some time to get the path of my plugin so I can reference some resource files in a reliable manner (so no matter where my plugin is within the plugin directory it will work).  I've been trying to use the SP Suites to do this, but I can't seem to get them to work.

My short term goal is to print the path to my plugin binary to console.

My most recent attempt goes like this(from within doContinue):

    SPBasicSuite *sSPBasic = f->sSPBasic; //f being the global filter record passed in by photoshop

    SPAccessSuite *sSPAccess;

    SPErr error = sSPBasic->AcquireSuite(kSPAccessSuite,

      kSPAccessSuiteVersion, (const void**)&sSPAccess);

    if (error) {

        fprintf(stderr, "coudln't acquire access suite\n");

    } else {

        fprintf(stderr, "acquired access suite\n");

    }

    SPPluginRef thisPlugin = NULL;

    error = sSPAccess->GetCurrentPlugin(&thisPlugin);

    if (error) {

        fprintf(stderr, "coudln't get current plugin\n");

    } else {

        fprintf(stderr, "got current plugin\n");

    }

    SPPluginsSuite *sSPPlugins;

    error = sSPBasic->AcquireSuite(kSPPluginsSuite,

      kSPPluginsSuiteVersion, (const void**)&sSPPlugins);

    if (error) {

        fprintf(stderr, "coudln't acquire plugins suite\n");

    } else {

        fprintf(stderr, "acquired plugins suite\n");

    }

    SPPlatformFileSpecification *fileSpec;

    error = sSPPlugins->GetPluginFileSpecification(thisPlugin, fileSpec);

    if (error) {
        fprintf(stderr, "coudln't get file spec\n");
    } else {
        fprintf(stderr, "got file spec\n");
    }

    //fprintf(stderr, "%s\n", fileSpec->nothingherecompiles);

Which results in the following output from gdb:

acquired access suite
got current plugin
acquired plugins suite

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x00000008

Based on that it seems that GetPluginFileSpecification crashes the program.  However, I'm fairly certain that 'thisPlugin' is not actually valid either, which makes me question whether any of the suites are valid as well.  Is there some sort of initialization I'm missing?  Any help is much appreciated.

TOPICS
SDK

Views

1.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Feb 10, 2011 Feb 10, 2011

Copy link to clipboard

Copied

Or that you failed to provide storage for the spec and just passed in a pointer to something that was supposed to get filled in....

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 11, 2011 Feb 11, 2011

Copy link to clipboard

Copied

I see... I was confused because there's a typo in the documentation that says it 'Files' it in and since we're dealing with files here my brain got confused.

Is it the same case with the SPPluginRef thisPlugin?  How do I determine how much space those pointers need?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 11, 2011 Feb 11, 2011

Copy link to clipboard

Copied

UPDATE: Here's the solution I've landed on:

   SPBasicSuite *sSPBasic = filterRecord->sSPBasic;

    SPAccessSuite *sSPAccess;
    sSPBasic->AcquireSuite(kSPAccessSuite,
      kSPAccessSuiteVersion, (const void**)&sSPAccess);

    SPPluginRef thisPlugin = (SPPluginRef)filterRecord->plugInRef;

    SPPluginsSuite *sSPPlugins;

    sSPBasic->AcquireSuite(kSPPluginsSuite,
      kSPPluginsSuiteVersion, (const void**)&sSPPlugins);

    SPPlatformFileSpecification fileSpec;

    sSPPlugins->GetPluginFileSpecification(thisPlugin, &fileSpec);

    PSGetPathSuite1 *sPSGetPath;
    sSPBasic->AcquireSuite(kPSGetPathSuite,
      kPSGetPathSuiteVersion1, (const void**)&sPSGetPath);

    char *path = (char*)malloc(256);
    sPSGetPath->GetPathName(&fileSpec, path, 256);

path now contains string of the form "Macintosh HD:Applications:Photoshop:etc"  and I just did some simple string manipulations to get it into the form I want.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 08, 2011 Mar 08, 2011

Copy link to clipboard

Copied

LATEST

Here's one way to do it, Windows only:

wchar_t DLLFilePath[MAX_PATH];

GetModuleFileNameW(GetDLLInstance(), DLLFilePath, _countof(DLLFilePath));

GetDLLInstance() is the HMODULE handle passed in by the caller in the first argument of the the DllMain entry point.

-Noel

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 14, 2011 Feb 14, 2011

Copy link to clipboard

Copied

Unportably but perhaps more concisely - for OS X only - you might be able to use some NSBundle methods on your plugin bundle, like resourcePath.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines