0

我尝试使用 LaunchServices 框架。不幸的是,某些功能仍然不可用。例如,函数 kLSSharedFileListFavoriteItems 已成功导入。但是,我无法加载函数 LSSharedFileListCreate。代码:

unit LSSharedFileList;
interface
uses MacApi.CoreFoundation, MacApi.CocoaTypes;
const
  LaunchServicesLib =
'/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/LaunchServices';
type 
{$EXTERNALSYM LSSHaredFileListRef}
LSSHaredFileListRef     = Pointer;
{$EXTERNALSYM LSSHaredFileListCreate}
function LSSHaredFileListCreate(inAlloccator : CFAllocatorRef; inListType : CFStringRef;
  listOptions : CFTypeRef) : LSSHaredFileListRef; cdecl;
{$EXTERNALSYM kLSSharedFileListFavoriteItems}
 function kLSSharedFileListFavoriteItems() : CFStringRef; cdecl;

implementation

uses Posix.Dlfcn;

var
_LSSHaredFileListCreate          : Pointer = nil;
_kLSSharedFileListFavoriteItems : Pointer = nil;
_libHandle                        : THandle = 0;
//--------------------------------------------------------------------------------
function LSSHaredFileListCreate(inAlloccator : CFAllocatorRef; inListType : CFStringRef;
 listOptions : CFTypeRef) : LSSHaredFileListRef;
begin
  if not Assigned(_LSSHaredFileListCreate) then
 _LSSHaredFileListCreate := dlSym(_libHandle, MarshaledAString('LSSHaredFileListCreate'));
 Result := nil;//
end;
//-----------------------------------------------------------------------
function kLSSharedFileListFavoriteItems() : CFStringRef;
begin
  if not Assigned(_kLSSharedFileListFavoriteItems) then
    _kLSSharedFileListFavoriteItems := dlSym(_libHandle, MarshaledAString('kLSSharedFileListFavoriteItems'));
  Result := CFStringRef(_kLSSharedFileListFavoriteItems^)
end;
//----------------------------
initialization
 _libHandle := dlOpen(MarshaledAString(LaunchServicesLib), RTLD_LAZY);
finalization
 dlclose(_libHandle)
end. 

因此,_LSSharedFileListCreate 与 _kLSSharedFileListFavoriteItems 不同,它始终为零,后者具有正确的地址。也许,“LSSharedFileListCreate”包含在另一个库中?任何想法?谢谢。

4

1 回答 1

0

错误在于库函数的名称。

_LSSHaredFileListCreate := dlSym(_libHandle, MarshaledAString('LSSHaredFileListCreate'));

正确的代码是

_LSSHaredFileListCreate := dlSym(_libHandle, MarshaledAString('LSSharedFileListCreate'));

(LSS* h *aredFileListCreate)

于 2013-10-18T13:41:36.483 回答