【问题标题】:How to add LaunchServices framework (mac os) to Delphi xe4?如何将 LaunchServices 框架(mac os)添加到 Delphi xe4?
【发布时间】:2013-10-14 13:20:38
【问题描述】:

我尝试使用 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”包含在另一个库中? 任何的想法? 谢谢。

【问题讨论】:

  • 相当老的话题,但您是否设法让 LaunchServices 代码正常工作?当我运行它时,对LSSharedFileListCreate(nil, kLSSharedFileListSessionLoginItems, nil) 的调用总是返回 nil,至少在 El Capitan 上是这样。在已签名或未签名的应用程序中。

标签: delphi osx-snow-leopard delphi-xe4 launch-services


【解决方案1】:

错误出现在库函数的名称中。

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

正确的代码是

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

(LSS*h*aredFileListCreate)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-02
    • 1970-01-01
    • 1970-01-01
    • 2012-03-22
    相关资源
    最近更新 更多