Ctypes 如何设置需要字符但定义为 unsigned int (OSX) 的 OSType
Ctypes How to set OSType which expects characters but is defined as unsigned int (OSX)
因此我尝试使用 CTypes 转换下面的代码。它使用 OSType
,OSType 定义为
FourCharCode = ctypes.c_uint32
OSType = FourCharCode
QTPropertyClass = OSType
我们在这里看到它是一个usngiend字符。但是我们在下面的代码片段中看到他们将其定义为
const OSType kFinderSig = 'MACS';
所以在 ctypes 中,将变量设置为 'MACS'
不会是 c_uint32 类型,而是字符类型?
请指教
谢谢
OSStatus SendFinderSyncEvent( const FSRef* inObjectRef )
{
AppleEvent theEvent = { typeNull, NULL };
AppleEvent replyEvent = { typeNull, NULL };
AliasHandle itemAlias = NULL;
const OSType kFinderSig = 'MACS';
OSStatus err = FSNewAliasMinimal( inObjectRef, &itemAlias );
if (err == noErr)
{
err = AEBuildAppleEvent( kAEFinderSuite, kAESync, typeApplSignature,
&kFinderSig, sizeof(OSType), kAutoGenerateReturnID,
kAnyTransactionID, &theEvent, NULL, "'----':alis(@@)", itemAlias );
if (err == noErr)
{
err = AESendMessage( &theEvent, &replyEvent, kAENoReply,
kAEDefaultTimeout );
AEDisposeDesc( &replyEvent );
AEDisposeDesc( &theEvent );
}
DisposeHandle( (Handle)itemAlias );
}
return err;
}
const OSType kFinderSig = 'MACS';
'MACS'
是字符常量,不是字符串!此代码使用 multi-character character constants.
的(有问题的)GCC 扩展
您可以使用(内置)struct
模块在 Python 中重现结果:
import struct
kFinderSig = struct.unpack(">L", "MACS")[0]
或者,只需将值硬编码为 0x4d414353
并留下它代表 "MACS".
的评论
因此我尝试使用 CTypes 转换下面的代码。它使用 OSType
,OSType 定义为
FourCharCode = ctypes.c_uint32
OSType = FourCharCode
QTPropertyClass = OSType
我们在这里看到它是一个usngiend字符。但是我们在下面的代码片段中看到他们将其定义为
const OSType kFinderSig = 'MACS';
所以在 ctypes 中,将变量设置为 'MACS'
不会是 c_uint32 类型,而是字符类型?
请指教
谢谢
OSStatus SendFinderSyncEvent( const FSRef* inObjectRef )
{
AppleEvent theEvent = { typeNull, NULL };
AppleEvent replyEvent = { typeNull, NULL };
AliasHandle itemAlias = NULL;
const OSType kFinderSig = 'MACS';
OSStatus err = FSNewAliasMinimal( inObjectRef, &itemAlias );
if (err == noErr)
{
err = AEBuildAppleEvent( kAEFinderSuite, kAESync, typeApplSignature,
&kFinderSig, sizeof(OSType), kAutoGenerateReturnID,
kAnyTransactionID, &theEvent, NULL, "'----':alis(@@)", itemAlias );
if (err == noErr)
{
err = AESendMessage( &theEvent, &replyEvent, kAENoReply,
kAEDefaultTimeout );
AEDisposeDesc( &replyEvent );
AEDisposeDesc( &theEvent );
}
DisposeHandle( (Handle)itemAlias );
}
return err;
}
const OSType kFinderSig = 'MACS';
'MACS'
是字符常量,不是字符串!此代码使用 multi-character character constants.
您可以使用(内置)struct
模块在 Python 中重现结果:
import struct
kFinderSig = struct.unpack(">L", "MACS")[0]
或者,只需将值硬编码为 0x4d414353
并留下它代表 "MACS".