【发布时间】:2011-08-04 01:29:34
【问题描述】:
简而言之:Carbon 是否适用于这项任务,还是我应该将其转储并寻找 Cocoa 解决方案?
试图编写一个小程序来询问客户端系统(Snow Leopard 及更高版本)以列出声称能够编辑单个给定文件的应用程序。用户选择一个应用程序,然后我的小程序调用 Launch Services 以启动应用程序,并将文件作为参数。
我可以通过调用 LSCopyApplicationURLsForURL 来获取符合条件的应用程序列表。 我可以通过调用 FSPathMakeRef 将文件路径转换为 FSRef 对象。 我不能做的是构造和使用 LSApplicationParameters 对象(其成员之一是 FSRef),以便成功调用 LSOPenURLsWithRole(其参数之一是 LSApplicationParameters)。
到目前为止我做了什么:
interface MyCarbonWrapper extends com.sun.jna.Library
{
public static final MyCarbonWrapper INSTANCE =
(MyCarbonWrapper) Native.loadLibrary("Carbon", MyCarbonWrapper.class);
// .. various function declarations, including
com.sun.jna.Pointer LSCopyApplicationURLsForURL(Object curlRef, int rolesMask);
int FSPathMakeRef(Object path, PointerByReference ref, Void isDirectory);
int LSOpenURLsWithRole(Pointer ptrArray, int roles, Void inAEParam,
Structure myLSApplicationParams, Void outPsns, int inMaxPSCount);
}
// unsuccessful attempt to define a mapped LSApplicationParameters
public static class LSApplicationParameters
{
public int version;
public int flags;
public Pointer Application;
public Void asyncLaunchRefCon;
public Void environment;
public Void argv;
public Void initialEvent;
public static final int sizeof = 28;
}
public void openWith(String filePath)
{
// create a CURLRef for the selected application - OK
// Create a FSRef from the CURLRef - OK
// Create a CFArray to contain the file argument - OK
// create and attempt to populate a LSApplicationParameters instance - problematic
// call LSOpenURLsWithRole - failure. Returned error code is -50
}
我通常理解的返回错误代码映射到消息:
“用户参数列表错误”。
据我所知,Snow Leopard 似乎已经放弃了对将 FSRef 作为参数的一系列 API 的支持。我完全不清楚我的立场是支持什么,什么不支持。
所以我应该得出结论,Carbon 对于这项活动来说是个死鸭子?还是我比我想象的更接近?
发送
【问题讨论】:
标签: osx-snow-leopard macos-carbon jna core-foundation