2012-11-17 26 views
0

我有一個C++ DLL公開以下函數。該函數立即調用回調函數(GetProperty)。我不能改變的C++ DLLJava Native使用浮點指針訪問回調函數

// c++ 
DllExport unsigned int RegisterCallbackGetPropertyReal(bool (*GetProperty)(UINT property_identifer, float * value)) ; 

我有一個使用com.sun.jna訪問DLL的這個功能的C#應用​​程序。我已經如此嚴重,回調函數被從C++ DLL調用正確的點,但我看不出找到一種方法來設置float * value

// Java 
public class main { 
    public interface CBlargAPI extends Library { 
     interface GetPropertyReal_t extends Callback { 
      boolean invoke (int property_identifer, FloatByReference value); 
     } 
     int RegisterCallbackGetPropertyReal(GetPropertyReal_t getProperty) ; 
    } 

    public static void main(String[] args) throws Exception 
    { 
     // Register call back functions   
     CBlargAPI.GetPropertyReal_t GetPropertyReal_fn = new CBACnetAPI.GetPropertyReal_t() { 
      @Override 
      public boolean invoke(int property_identifer, FloatByReference value) { 
       System.out.println("GetPropertyReal_t: ") ; 
       value.setValue(97.5f); 
       return false; // [Edit] This is where the problem was. this should be `return true;` See my answer below. 
      } 
     }; 
     CBlargAPI.INSTANCE.RegisterCallbackGetPropertyReal(GetPropertyReal_fn) ;    
    } 
} 

我本來期望的是,該值應爲當它回到C++ DLL時,設置爲97.5f。相反,我得到的0.000f

我的問題的默認值是:

  • 如何正確地與JNA設定一個浮動指針值在Java?

回答

0

這是一個沒有其他人可以找到的錯字。基本上,如果我在GetPropertyReal_fn回調中返回false,將使用默認值0.000f

我編輯了問題以顯示錯誤的位置。