0

I try to use LaunchServices framework. Unfortunately, some functions remain unavailable. For example, function kLSSharedFileListFavoriteItems was imported successfully. However, I can't load function LSSHaredFileListCreate. Code:

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. 

So, _LSSHaredFileListCreate always nil unlike _kLSSharedFileListFavoriteItems, which has correct address. Maybe, "LSSharedFileListCreate" containt in the other lib? Any idea? Thanks.

RRUZ
  • 134,889
  • 20
  • 356
  • 483
mvp
  • 33
  • 1
  • 4
  • Quite an old topic, but did you manage to get that LaunchServices code working? A call to `LSSharedFileListCreate(nil, kLSSharedFileListSessionLoginItems, nil)` always returned **nil** when I ran it, at least on El Capitan. Both in a signed or unsigned app. – VGeorgiev Jan 13 '17 at 15:21

1 Answers1

0

Mistake was in the name of library function.

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

Correct code is

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

(LSS*h*aredFileListCreate)

mvp
  • 33
  • 1
  • 4