2011-08-04 15 views
0

要約:Carbonはこのタスクに有効ですか、それをダンプしてCocoaソリューションを探すべきですか?Carbon APIを使用してjna経由でアプリケーションを起動できますか?

クライアントシステム(Snow Leopard以降)に質問するアプレットを作成しようとすると、アプリケーションを一覧表示するために、与えられた1つのファイルを編集できると主張しています。ユーザーがアプリケーションを選択すると、アプレットはLaunch Servicesを呼び出して、ファイルを引数としてアプリケーションを起動します。

対象となるアプリケーションのリストは、LSCopyApplicationURLsForURLを呼び出して取得できます。 FSPathMakeRefを呼び出すことによって、ファイルパスをFSRefオブジェクトに変換できます。 LSOPenURLsWithRole(引数の1つがLSApplicationParameters)を正常に呼び出すために、LSApplicationParametersオブジェクト(そのメンバーの1つがFSRef)を作成して使用することはできません。私がこれまで行って何



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がこの活動のための死んだアヒルであると結論付けるべきですか?それとも私は私が思うよりも近くにいるのですか?

のTx

答えて

0

はカーボンのLSOpenApplicationをあきらめたので、私はObjective-CのとJavaを埋めるためRococoaを使用するソリューションを実装しました。 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)); 

私はまだ多くの他のLaunchApplicationサービスにCarbonを使用しています。 java.net/projects/rococoa/は自宅であり、java.net/projects/rococoa/lists/users/archiveで最小限のチャタリングがあれば便利です。

関連する問題