如何让Mac OS Component Manager组件对其他进程可见?

时间:2009-12-06 10:53:10

标签: macos macos-carbon

这有点深奥,但这里必须有一些人知道OS X的Carbon Component Manager是如何工作的。我制作了几个小应用程序来制作组件(有关背景,请参阅here)。实际上,其中一个应用程序是直接来自Apple的示例程序,名为“Fiendishthngs”。它列出了组件管理器可用的所有组件。我的程序是一个简单的小东西,它注册一个Component,列出了Component Manager拥有的所有组件,然后无限期地等待(以避免清除它注册的Component)。

在我的系统上,组件管理器正在跟踪873个组件(主要是一种类型的编解码器)。我的注册组件的程序会注册它,然后计算874组件,因为它本身只注册了一个组件。这是来源:

void RegisterBasicComponent()
{
    ComponentDescription desc;
    desc.componentType = kMyComponentType;
    desc.componentSubType = kMyComponentSubType;
    desc.componentManufacturer = kMyComponentManufacturer;
    desc.componentFlags = 0;
    desc.componentFlagsMask = cmpIsMissing;

    ComponentRoutineUPP MyComponentRoutineUPP 
        = NewComponentRoutineUPP( &MyComponentRoutineProc );

    //  Handle name_handle = NewHandle( sizeof( kMyComponentName ) );
    //strcpy( *(char**)name_handle, kMyComponentName );

    //RegisterComponent( &desc, MyComponentRoutineUPP, registerComponentGlobal, name_handle, NULL, NULL );
    Component component = RegisterComponent( &desc, MyComponentRoutineUPP, registerComponentGlobal, NULL, NULL, NULL );
    if ( NULL != component )
        printf("The registration seems to have worked!\n");
    else
        printf("Nope - didn't work for some reason.\n");

}


int main( void )
{
    RegisterBasicComponent();

    ComponentDescription looking;
//  OSType              componentType;          /* A unique 4-byte code indentifying the command set */
//  OSType              componentSubType;       /* Particular flavor of this instance */
//  OSType              componentManufacturer;  /* Vendor indentification */
//  UInt32              componentFlags;         /* 8 each for Component,Type,SubType,Manuf/revision */
//  UInt32              componentFlagsMask;     /* Mask for specifying which flags to consider in search, zero during registration */
    looking.componentType           = kAnyComponentType;          
    looking.componentSubType        = kAnyComponentSubType;
//  looking.componentSubType        = kComponentResourceType
    looking.componentManufacturer   = kAnyComponentManufacturer;
    looking.componentFlags          = 0;
    looking.componentFlagsMask      = cmpIsMissing;

    long numComponents = CountComponents ( &looking );

    printf("Found %ld components.\n", numComponents);

    Component component = 0;
    int i = 0;
    while (true) 
    {
        component = FindNextComponent(component, &looking);

        if ( 0 == component )
            break;

        ComponentDescription desc;
        Handle componentName = NewHandle(256);
        Handle componentInfo = NewHandle(1024);
        Handle componentIcon = 0;
        OSErr err = GetComponentInfo( component,
                                &desc,
                                componentName,
                                componentInfo,
                                componentIcon );

        if ( err != noErr )
        {
            printf("Couldn't find any info on component %d of %ld in list!\n", i
                   , numComponents);
            break;
        }


        printf( "%d of %ld: '%c%c%c%c', '%c%c%c%c', '%c%c%c%c', '%s'\n", 
            i, numComponents,
            SPLAT_WORD( desc.componentManufacturer ),
            SPLAT_WORD( desc.componentType ),
            SPLAT_WORD( desc.componentSubType ),
            *componentName );

        RecoverHandle( *componentName );
        RecoverHandle( *componentInfo );

        ++i;
    }

    while (true) 
    {
        printf("Waiting around for someone to use me...\n");
        sleep( 3 );
    }
}

无论如何,当我运行它时,保持它运行(因此Component可能会保持在Component Manager中注册),然后运行Fiendishthngs,Fiendishthngs看不到我注册的测试组件 - 它只能看到873组件。传递给RegisterComponent()的'registerComponentGlobal'标志应该使Component可用于其他进程,但似乎出现了问题。

有什么想法吗?

1 个答案:

答案 0 :(得分:3)

好吧,我把这个问题抛在脑后,让我自己承认OS X的组件管理器可能不再支持'全局'选项。

这真的很有道理。从你的进程到其他进程使你的组件“全局”需要进程外调用编组,比如RPC,OS X.另一方面,在OS 9及更早版本中,它会很有意义,因为所有进程存在于公共地址空间中。对于OS 9,使一个组件全局可用于所有进程是微不足道的。

无论如何,今天我正在拆解相关代码似乎驻留的RegisterComponentFileRefEntries(),当然,我在函数的前导中看到了这个(评论是我的):

0x9841a026  <+0018>  mov    eax, DWORD PTR [ebp+0x8]        // load param spec
0x9841a029  <+0021>  mov    DWORD PTR [ebp-0xdc],eax        // local spec = param spec
0x9841a02f  <+0027>  mov    edx,DWORD PTR [ebp+0x10]        // load param toRegister
0x9841a032  <+0030>  mov    DWORD PTR [ebp-0xe0],edx        // local toRegister = param toRegister

RegisterComponentFileRefEntries的签名是

extern OSErr 
RegisterComponentFileEntries(
  const FSSpec *                spec,
  short                         global,
  const ComponentDescription *  toRegister,          /* can be NULL */
  UInt32                        registerCount)   

RegisterComponentFileRefEntries遇到的唯一两个参数是spec(在ebp + 0x8处)和toRegister(在ebp + 0x10处)。全局(在ebp + 0xc处)和registerCount(在ebp + 0x14处)被完全忽略。