2012-11-15 3 views
0

변경할 수없는 C++로 작성된 DLL이 있습니다. 다음과 같은 노출 된 함수가 있습니다.C++ 응용 프로그램의 Java com.sun.jna 콜백 함수

// c++ 
DllExport unsigned int ProcessMessage(char * in_message, USHORT in_message_length, char * connectionString, bool (SendMessage)(char * connectionString, BYTE * payload, USHORT iPayloadSize) ); 

이 DLL 함수를 호출해야하는 Java 응용 프로그램이 있습니다. 나는 현재 현재이가 override function thingy (#A)와 협력 자바 라이브러리 com.sun.jna

// Java 
public class main { 
    public interface CBlargAPI extends Library { 
     interface sendMessage_t extends Callback { 
      boolean invoke(String connectionString, Pointer payload, short iPayloadSize); 
     } 
     int ProcessMessage(byte[] in_message, short in_message_length, String connectionString, sendMessage_t SendMessage) ; 
    } 
    public static void main(String[] args) throws Exception 
    { 
     // Override function thingy (#A) 
     CBlarg.sendMessage_t sendMessage_fn = new CBlarg.sendMessage_t() { 
      @Override 
      public boolean invoke(String connectionString, Pointer payload, short iPayloadSize) { 
       System.out.println("sendMessage_t: ") ; 
       return false; 
       } 
      };   
     } 
     CBlargAPI.INSTANCE.ProcessMessage(receivePacket.getData(), (short) receivePacket.getLength(), connectionString, sendMessage_fn); 
    } 

    // static member function (#B) 
    public static boolean SendUDPMessage(String connectionString, Pointer payload, short length) {  
     // ToDo: I want to use this one. 
    } 
} 

를 사용하고 있지만 대신 static member function (#B)를 사용하고 싶습니다. 나는 같은

// Errors with "cannot find symbol, symbol: class SendUDPMessage, location: class main" 
CBACnetAPI.sendMessage_t sendMessage_fn = new main.SendUDPMessage(); 

가 나는 C++ 프로그래머 거의 만지지 자바 주입니다 성공하지 몇 가지를 시도

내 질문은 :

  • 나는 정적 멤버를 호출하려면 어떻게 Override function thingy (#A) 대신 콜백으로 SendUDPMessage() 함수가 있습니까?

답변

1

static member function(#B)으로 전화해야합니다. 자바는 함수 포인터를 가지고 있지 않으므로 그 목적을 달성하기 위해 인터페이스 객체가 필요하다.

왜 #A 이상 #B해야합니까?

+0

방금 ​​클래스를보다 깨끗하게 설정하고 싶었습니다. –