DLL(Delphi)与ADO(连接和查询)在Java中不起作用(使用jna) [英] DLL (Delphi) with ADO (connection and query) not work in Java (using jna)

查看:381
本文介绍了DLL(Delphi)与ADO(连接和查询)在Java中不起作用(使用jna)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含ADOConnection和ADOQuery的dll(Delphi),但是当在java(使用JNA)中运行被调用的DLL时,会出现一些错误信息到控制台(如下):


Java运行时环境检测到致命错误:



内部错误(0xeedfade),pid = 4400,tid = 3840



JRE版本:6.0_25-b06 Java VM:Java HotSpot(TM)客户端VM
(20.0-b11混合模式,共享windows-x86)有问题的框架:C
[KERNELBASE.dll + 0x812f]



具有更多信息的错误报告文件保存为:
C:\Users \Mmn1\Documents\NetBeansProjects\FLMOPDL\hs_err_pid4400.log



如果您想提交错误报告,请访问:

http://java.sun.com/webapps/bugreport/crash.jsp在nat中的Java虚拟机外发生崩溃
ive代码。看到有问题的
框架报告错误。


这是什么错误?
(我意识到,只有在ADOConnection ADOQuery的情况下,如果我有一个表单或组件,并且如果我删除这些组件并执行一个简单的功能,它才能正常工作)。



编辑:



类似的例子如下:

 库TESTLIB; 
{$ DEFINE TESTLIB}

使用
System.SysUtils,
System.Classes,
TestInt in'TestInt.pas',
Vcl.Dialogs,
sharemem,
Data.DB,Data.Win.ADODB;

{$ R * .res}

函数MyReturn(x:Integer; Test:PTest):Boolean; STDCALL;
var
ado:TADOQuery;
begin
结果:= True;
// ado:= TADOQuery.Create(nil); < - 这样我有错误!
结束

导出MyReturn;

开始
结束。

Java中的接口

公共接口TestInt扩展StdCallLibrary {
TestInt INSTANCE =(TestInt)Native.loadLibrary(C:/ test / Win32 / Debug / TESTLIB,TestInt.class);

class Test extends Structure {
public String vResult;

public Test(){}
public Test(int x,Pointer p){
super(p);
read();
}
protected List getFieldOrder(){return Arrays.asList(new String [] {vResult}); }
}

Boolean MyReturn(int x,Test test);
}

结论:当我使用组件时,此错误提高。感谢您的帮助。

解决方案

重新修改:



解决方案。问题是如何DLL已被做。下面的解决方案,我希望它可以帮助更多的人:



TESTLIB(Delphi)

 库TESTLIB; 
{$ DEFINE TESTLIB}

使用
System.SysUtils,
System.Classes,
TestInt in'TestInt.pas',//这是我的单位(界面)
Vcl.Dialogs,
ADODB,
Vcl.Forms;

{$ R * .res}


函数MyReturn(Test:PTest):Boolean; STDCALL;
var
ado:TADOQuery;
con:TADOConnection;
begin
con:= TADOConnection.Create(Application);
ado:= TADOQuery.Create(Application);

con.ConnectionString:='Provider = SQLOLEDB.1; Password = aaa; Persist Security Info = True;用户ID = aa;初始目录= aa;数据源= 127.0.0.1';
con.LoginPrompt:= False;
con.Open();

如果con.Connected = True然后
ShowMessage('connected ok')
else
ShowMessage('not connected');

ado.Active:= False;
ado.Connection:= con;
ado.SQL.Clear;
ado.SQL.Add('select lalala from table where codlala = 1');
try
ado.Open();
测试^ .vResult:= PAnsiChar(AnsiString(ado.FieldByName('fantasia')。AsString));
结果:= True;
除了
在E:Exception do
begin
ShowMessage('打开查询'+ 13 +'错误:'+ E.Message)
结果:= False;
结束
结束
结束

导出MyReturn;

开始
结束。

接口Ole32(java)

  import com.sun.jna.Native; 
import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.WinNT.HRESULT;
import com.sun.jna.win32.StdCallLibrary;

public interface Ole32 extends StdCallLibrary {

Ole32 INSTANCE =(Ole32)Native.loadLibrary(Ole32,Ole32.class);

public HRESULT CoInitialize(指针p);

public HRESULT CoUninitialize();

}

特别感谢kobik和technomage关于 CoInitialize



帮助我的链接:



Delphi ISAPI应用程序的应用程序初始化部分中的TADOConnection失败:



添加CoInitializing常量并改进文档



从Java通过JNA使用COM


I have a dll (Delphi) that contains a ADOConnection and ADOQuery, but when running the called DLL in java (using JNA) appear some error information to the console (below):

A fatal error has been detected by the Java Runtime Environment:

Internal Error (0xeedfade), pid=4400, tid=3840

JRE version: 6.0_25-b06 Java VM: Java HotSpot(TM) Client VM (20.0-b11 mixed mode, sharing windows-x86 ) Problematic frame: C [KERNELBASE.dll+0x812f]

An error report file with more information is saved as: C:\Users\Mmn1\Documents\NetBeansProjects\FLMOPDL\hs_err_pid4400.log

If you would like to submit a bug report, please visit:
http://java.sun.com/webapps/bugreport/crash.jsp The crash happened outside the Java Virtual Machine in native code. See problematic frame for where to report the bug.

What bug is this? (I realized that it is only happens if I have a form or as a component in the case ADOConnection ADOQuery and if I remove these components and perform a simple function, it works normally).

Edit:

A similar exemple bellow:

library TESTLIB;
{$DEFINE TESTLIB}

uses
  System.SysUtils,
  System.Classes,
  TestInt in 'TestInt.pas',
  Vcl.Dialogs,
  sharemem,
  Data.DB, Data.Win.ADODB;

{$R *.res}

function MyReturn(x: Integer; Test: PTest): Boolean; stdcall;
var
  ado: TADOQuery;
begin
    Result := True;
    //ado := TADOQuery.Create(nil); <- With this i got a error!
end;

exports MyReturn;

begin
end.

interface in Java

public interface TestInt extends StdCallLibrary {
    TestInt INSTANCE = (TestInt)Native.loadLibrary("C:/test/Win32/Debug/TESTLIB", TestInt.class);

    class Test extends Structure {
        public String vResult;

        public Test() { }
        public Test(int x, Pointer p) {
            super(p);
            read();
        }
        protected List getFieldOrder() { return Arrays.asList(new String[] { "vResult" }); }
    }

    Boolean MyReturn(int x, Test test);
}

conclusion: when I use a component, this error raise. Thanks for help.

解决方案

Re-edited:

I got the solution. The problem was "how to" DLL had been made. Below the solution and I hope it helps more people:

TESTLIB (Delphi)

library TESTLIB;
{$DEFINE TESTLIB}

uses
  System.SysUtils,
  System.Classes,
  TestInt in 'TestInt.pas', //here's my unit (interface)
  Vcl.Dialogs,
  ADODB,
  Vcl.Forms;

  {$R *.res}


function MyReturn(Test: PTest): Boolean; stdcall;
var
  ado: TADOQuery;
  con: TADOConnection;
begin
    con := TADOConnection.Create(Application);
    ado := TADOQuery.Create(Application);

    con.ConnectionString := 'Provider=SQLOLEDB.1;Password=aaa;Persist Security Info=True;User ID=aa;Initial Catalog=aa;Data Source=127.0.0.1';
    con.LoginPrompt := False;
    con.Open();

    if con.Connected = True then
        ShowMessage('connected ok')
    else
        ShowMessage('not connected');

    ado.Active := False;
    ado.Connection := con;
    ado.SQL.Clear;
    ado.SQL.Add('select lalala from table where codlala = 1');
    try
        ado.Open();
        Test^.vResult := PAnsiChar(AnsiString(ado.FieldByName('fantasia').AsString));
        Result := True;
    except
        on E: Exception do
        begin
          ShowMessage('error to open the query' + #13 + 'Error: ' + E.Message);
          Result := False;
        end;
    end;
end;

exports MyReturn;

begin
end.

Interface Ole32 (java)

import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.WinNT.HRESULT;
import com.sun.jna.win32.StdCallLibrary;

public interface Ole32 extends StdCallLibrary {

    Ole32 INSTANCE = (Ole32) Native.loadLibrary("Ole32", Ole32.class);

    public HRESULT CoInitialize(Pointer p);

    public HRESULT CoUninitialize();

}

Special thanks to kobik and technomage about CoInitialize

links that helped me:

TADOConnection failing in application initialization section of Delphi ISAPI App:

Add CoInitializing constants and improve documentation

Using COM from Java via JNA

这篇关于DLL(Delphi)与ADO(连接和查询)在Java中不起作用(使用jna)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆