Appear to make up the gap between Java and COM

zhaozj2021-02-16  57

After reading the bridge of Zlyperson, Java connected to the bridge of the COM object, benefited a lot, here I want to supplement me to make a project in a project on the basis of ZlyPerson.

Project demand:

Read the data from the file, call the component's algorithm to complete the calculation, return the final result to the Java program and then achieve further operations and display of the results.

The strategy I take is:

1. How to pass the data.

Read the data from the file, if you are done in Java, you have to complete the data transfer from Java to COM, so I have done in COM, which is passed from Java to a file.

ActiveXComponent ActiveXcom = New ActiveXComponent ("ComponentName. SomeClass);

Dispatch.put (ActiveXcom, "FilePath", New Variant ("E: // Data"));

2, how to get the return result.

Public String [] getFinalResult ()

{

Variant Temp_var;

Temp_var = dispatch.get (ActiveXcom, "FinalResults");

/ * ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- * /

// The whole idea is similar to MFC, first turn into SafeArray, then get its size

/ * ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- * /

SafeArray IA = Temp_var.tosafeArray ();

INT TEMP_LLOWERBOUND = IA.Getlbound ();

INT TEMP_LUPPERBOUND = IA.Getubound ();

INT TEMP_LOPTIONALRESULTSNUM = TEMP_LUPPERBOUND - TEMP_LLOWERBOUND 1;

String Temp_sstring [] = new string [temp_loptionalResultsnum];

For (INT i = 0; i

{

Temp_sstring [i] = Ia.getstring (i);

System.out.println (Temp_sstring [i]);

}

Return Temp_sstring;

}

转载请注明原文地址:https://www.9cbs.com/read-22517.html

New Post(0)