0

我有一个 c++ 代码,它已被其他人连接到 Visual Basic 用户界面。这是将 c++ 连接到 Visual Basic 的函数代码之一:

   extern "C" void PASCAL EXPORT RCS( stAct* act,stResourceDirectory* resDir,   stCalendar* calendar, short  numOfAct, short numOfRes, short numOfCal, int nDataDate )
{
Network network;
short id;
Activity* p_act;
node<Activity>* p_node;

    // Setting
    network.create_calendars (calendar, numOfCal);
    network.set_data_date (nDataDate);
    set_activity(network, act, numOfAct );
// only for id, duration, and description   
    set_resource(network, act, resDir, numOfAct, numOfRes);
// create resource profile and add required resource for every activity

    network.CPM ();

    p_node = network.get_network_head_p();  

    while (p_node != NULL ) {
    p_act = p_node->refer_data();
    id = p_act->get_ID ();

    act[id].TF_in_CPM = p_act->get_TF_min ();
    act[id].FF_in_CPM = p_act->get_FF();
    act[id].EST_in_CPM = p_act->get_EST ();
    act[id].EFT_in_CPM = p_act->get_EFT ();
    act[id].LST_in_CPM = p_act->get_LST ();
    act[id].LFT_in_CPM = p_act->get_LFT ();
    p_node = p_node->get_link();
    }
    network.RCS();  
p_node = network.get_network_head_p();  

while (p_node != NULL ) {
    p_act = p_node->refer_data();
    id = p_act->get_ID ();

    act[id].TF_in_RCS = p_act->get_TF_min ();
    act[id].FF_in_RCS = p_act->get_FF();
    act[id].EST_in_RCS = p_act->get_EST ();
    act[id].EFT_in_RCS = p_act->get_EFT ();
    act[id].LST_in_RCS = p_act->get_LST ();
    act[id].LFT_in_RCS = p_act->get_LFT ();

    p_node = p_node->get_link();
    }
}

我想用 Java GUI 替换 Visual Basic 部分,编写连接代码似乎让我感到困惑。有没有人可以帮助我调用三个 c++ 函数,通过 JNA/SWIG/Runtime 或您认为它会更容易和更好地工作的任何其他方法将参数传递给本机方法并从中接收结果?

4

1 回答 1

0

这是一个指导示例,可帮助您入门。在此代码段中,Java2Win64 是包含要执行的本机代码的 DLL。函数 functionMaryam() 将 1 个参数作为 int 并返回一个 int。易于扩展任何数据类型。公共类 JnaExampleMaryam {

// ------------------------------------------
// Java2Win.class
// ------------------------------------------
public interface Java2Win extends Library {
    Java2Win call = (Java2Win) Native.loadLibrary("Java2Win64", Java2Win.class);
    int functionMaryam(int i);
}
// ------------------------------------------

// ------------------------------------------
// Test
// ------------------------------------------
public static void main(final String args[]) throws Exception {
    final File file = new File("rootToDLL", "Java2Win64.dll");
    LibraryLoader.loadLibrary(file);

    int result = Java2Win.call.functionMaryam(42);
}
// ------------------------------------------
于 2013-04-08T21:27:29.847 回答