gpt4 book ai didi

java - 使用来自 Adob​​e AIR 的 native 进程的 .dll 运行 Java 程序

转载 作者:行者123 更新时间:2023-11-30 11:58:38 25 4
gpt4 key购买 nike

我希望能够从我的 AIR 应用程序操作扫描仪。由于 native 不支持此功能,因此我尝试使用 NativeProcess 类来启动可以运行扫描仪的 jar 文件。 Java 代码使用 JTwain 库来操作扫描仪。 Java应用程序本身运行良好,AIR应用程序可以启动并与Java应用程序通信。问题似乎是,每当我尝试使用 JTwain 中的函数(它依赖于 JTwain.dll)时,如果 AIR 启动它,应用程序就会死掉。

我不确定从 native 进程引用 dll 文件是否有一些限制或什么。我在下面包含了我的代码

Java代码-

    while(true)
{
try {
System.out.println("Start");
text = in.readLine();
Source source = SourceManager.instance().getCurrentSource();
System.out.println("Java says: "+ text);
}
catch (IOException e)
{
System.err.println("Exception while reading the input. " + e);
}
catch (Exception e) {
System.out.println("Other exception occured: " + e.toString());
}
finally {
}
}
}

空气应用-

        import mx.events.FlexEvent;

private var nativeProcess:NativeProcess;
private var npInfo:NativeProcessStartupInfo;
private var processBuffer:ByteArray;
private var bLength:int = 0;

protected function windowedapplication1_applicationCompleteHandler(event:FlexEvent):void
{
var arg:Vector.<String> = new Vector.<String>;
arg.push("-jar");
arg.push(File.applicationDirectory.resolvePath("Hello2.jar").nativePath);

processBuffer = new ByteArray;

npInfo = new NativeProcessStartupInfo;
npInfo.executable = new File("C:/Program Files/Java/jre6/bin/javaw.exe");
npInfo.arguments = arg;

nativeProcess = new NativeProcess;
nativeProcess.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onStandardOutputData);
nativeProcess.start(npInfo);
}

private function onStandardOutputData(e:ProgressEvent):void
{
tArea.text += nativeProcess.standardOutput.readUTFBytes(nativeProcess.standardOutput.bytesAvailable);
}


protected function button1_clickHandler(event:MouseEvent):void
{
tArea.text += 'AIR app: '+tInput.text + '\n';
nativeProcess.standardInput.writeMultiByte(tInput.text + "\n", 'utf-8');
tInput.text = '';
}


protected function windowedapplication1_closeHandler(event:Event):void
{
nativeProcess.closeInput();
}

]]>
</fx:Script>
<s:Button label="Send" x="221" y="11" click="button1_clickHandler(event)"/>
<s:TextInput id="tInput" x="10" y="10" width="203"/>
<s:TextArea id="tArea" x="10" width="282" height="88" top="40"/>

我希望能解释一下为什么它会消亡。我已经做了足够多的测试,我完全知道杀死它的那一行是 SourceManager.instance().getCurrentSource()。我会喜欢任何建议。谢谢。

最佳答案

当调用 Java 时,将此 -Djava.library.path=location_of_dll 添加到命令行

关于java - 使用来自 Adob​​e AIR 的 native 进程的 .dll 运行 Java 程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3070903/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com