我可以使用 Carbon API 通过 jna 启动应用程序吗?

发布于 2024-11-27 17:00:01 字数 1668 浏览 4 评论 0原文

简而言之:Carbon 对于这项任务有效吗?或者我应该放弃它并寻找 Cocoa 解决方案?

尝试编写一个小程序来询问客户端系统(Snow Leopard 及更高版本)以列出声称能够编辑单个给定文件的应用程序。用户选择一个应用程序,然后我的小程序调用启动服务来启动该应用程序,并将该文件作为参数。

我可以通过调用 LSCopyApplicationURLsForURL 获取符合条件的应用程序列表。 我可以通过调用 FSPathMakeRef 将文件路径转换为 ​​FSRef 对象。 我不能做的是构造和使用 LSApplicationParameters 对象(其成员之一是 FSRef)以便成功调用 LSOPenURLsWithRole(其参数之一是 LSApplicationParameters)。

到目前为止我做了什么:

<代码> 接口 MyCarbonWrapper 扩展 com.sun.jna.Library
{
公共静态最终 MyCarbonWrapper 实例 =
  (MyCarbonWrapper) Native.loadLibrary("Carbon", MyCarbonWrapper.class);
// .. 各种函数声明,包括
  com.sun.jna.Pointer LSCopyApplicationURLsForURL(Object curlRef, int RolesMask);
  int FSPathMakeRef(对象路径, PointerByReference ref, Void isDirectory);
  int LSOpenURLsWithRole(指针 ptrArray, int 角色, Void inAEParam,
   结构 myLSApplicationParams, Void outPsns, int inMaxPSCount);
}

// 尝试定义映射的 LSApplicationParameters 失败
公共静态类 LSApplicationParameters
{
公共整数版本;
公共 int 标志;
公共指针应用程序;
公共无效asyncLaunchRefCon;
公共 Void 环境;
公共无效argv;
公共无效初始事件;
公共静态最终 int sizeof = 28;
}

公共无效openWith(字符串文件路径)
{
  // 为所选应用程序创建一个 CURLRef - OK
  // 从 CURLRef 创建 FSRef - OK
  // 创建一个 CFArray 来包含文件参数 - OK
  // 创建并尝试填充 LSApplicationParameters 实例 - 有问题
  // 调用 LSOpenURLsWithRole - 失败。返回的错误代码为-50
}


我通常将返回的错误代码理解为映射到消息:
“用户参数列表错误”。

据我所知,Snow Leopard 似乎已经放弃了对一系列以 FSRef 作为参数的 API 的支持。我根本不清楚我对什么受支持、什么不支持的立场。

那么我应该得出这样的结论:Carbon 对于这项活动来说是死定了?或者我比我想象的更接近?

发射机

In brief: is Carbon valid for this task, or should I dump it and look for a Cocoa solution?

Trying to write an applet which interrogates the client system (Snow Leopard and later) to list applications claim to be able to edit a single given file. User selects an application, and my applet then calls on Launch Services to launch the application, with the file as an argument.

I can get the list of eligible applications by calling LSCopyApplicationURLsForURL.
I can convert a file path to a FSRef object by calling FSPathMakeRef.
What I can't do is to construct and use a LSApplicationParameters object (one of whose members is a FSRef) in order to successfully call LSOPenURLsWithRole (one of whose arguments is a LSApplicationParameters).

What I done so far:


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
}

The returned error code I usually get I understand to map to the message:
"Error in user parameter list".

As far as I can tell, Snow Leopard seems to have dropped support for a range of APIs that take a FSRef as an argument. It's not at all clear to me just where I stand with what's supported and what isn't.

So I should conclude Carbon is a dead duck for this activity? Or am I closer than I think?

Tx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

染火枫林 2024-12-04 17:00:01

放弃了 Carbon 的 LSOpenApplication 后,我实现了一个使用 Rococoa 来桥接 Objective-C 和 Java 的解决方案。不需要将 Cocoa 复合方法名称(例如 openFile:withApplication)转换为 openFile_withApplication。

// Declare an interface which will call on a rococoa class:

public interface NSWorkspace extends NSObject
{

    public static final _Class CLASS = Rococoa.createClass("NSWorkspace", _Class.class);

    public interface _Class extends NSClass
    {
        // static method to get the workspace in
        NSWorkspace sharedWorkspace();
    }
    boolean openFile_withApplication(NSString fullPath, NSString appName);
}

// then we can call on it to do stuff

final NSWorkspace nsWorkspace = NSWorkspace.CLASS.sharedWorkspace();
boolean isRunning = nsWorkspace.openFile_withApplication(
    NSString.stringWithString(targetFilePathStr),
    NSString.stringWithString(executableApplicationPathStr));

我仍在将 Carbon 用于许多其他 LaunchApplication 服务。
java.net/projects/rococoa/ 是它的家,在 java.net/projects/rococoa/lists/users/archive 上有一些有用的(即使是最少的聊天)

Having given up on Carbon's LSOpenApplication, I've implemented a solution which uses Rococoa to bridge Objective-C and Java. Not the the necessity of translating Cocoa composite method names eg openFile:withApplication to openFile_withApplication.

// Declare an interface which will call on a rococoa class:

public interface NSWorkspace extends NSObject
{

    public static final _Class CLASS = Rococoa.createClass("NSWorkspace", _Class.class);

    public interface _Class extends NSClass
    {
        // static method to get the workspace in
        NSWorkspace sharedWorkspace();
    }
    boolean openFile_withApplication(NSString fullPath, NSString appName);
}

// then we can call on it to do stuff

final NSWorkspace nsWorkspace = NSWorkspace.CLASS.sharedWorkspace();
boolean isRunning = nsWorkspace.openFile_withApplication(
    NSString.stringWithString(targetFilePathStr),
    NSString.stringWithString(executableApplicationPathStr));

I'm still using Carbon for a number of other LaunchApplication services.
java.net/projects/rococoa/ is its home, with some useful if minimal chatter on java.net/projects/rococoa/lists/users/archive

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文