Delphi调用AdoFiltr.dll的问题。 ( 积分: 200 )

  • 主题发起人 主题发起人 superi
  • 开始时间 开始时间
S

superi

Unregistered / Unconfirmed
GUEST, unregistred user!
最近碰到一个麻烦问题,我在桌面pc上有一个数据库Manager.mdb,里面有数据表b,c ,d 。需要把数据库转换为掌上电脑pocket2003使用的数据库Manager.cdb,和把,Manager.cdb转换为Manager.mdb,转换其中的一个表或者,2个表都可以。也就是 Manager.mdb<---->Manager.cdb。不知道用Delphi如何实现?请教各位大虾了,就200分了,全送了,我查看了一些资料,用vb实现的代码,不知道用delphi如何实现,求救了……我把这个vb的代码也附上来吧,高手看看,帮帮忙。
定义了2个函数
从掌上电脑上载数据库,将*.cdb转换为*.mdb数据库

Declare Function DEVICETODESKTOP Lib &quot;adofiltr.dll&quot; _ ' (ByVal desktoplocn As String, _
ByVal tablelist As String, _
ByVal sync As Boolean, _
ByVal overwrite As Integer, _
ByVal devicelocn As String) As Long
'从桌面pc下载数据库,将*.mdb转换为*.cdb
Declare Function DESKTOPTODEVICE Lib &quot;adofiltr.dll&quot; _
(ByVal desktoplocn As String, _
ByVal tablelist As String, _
ByVal sync As Boolean, _
ByVal overwrite As Integer, _
ByVal devicelocn As String) As Long
'上载数据到桌面Access数据库
intRetVal = DEVICETODESKTOP(App.Path &amp; &quot;/Manager.mdb&quot;, &quot;&quot;, False, True, &quot;/Windows/Manager.cdb&quot;)


'下载数据到PDA数据库

intRetVal = DESKTOPTODEVICE(App.Path &amp; &quot;/Manager.mdb&quot;, &quot;&quot;, False, True, &quot;/Windows/Manager.cdb&quot;)
 
这个很简单的。察看VB文件可知,
DEVICETODESKTOP Lib &quot;adofiltr.dll&quot;
引用的其实就一个adofiltr.dll而已。
这个dll最新版本可以通过安装Microsoft ActiveSync获得,下载地址http://www.onlinedown.net/soft/21106.htm
研究VB中代码,发现这个DLL接口很简单,就2个函数DESKTOPTODEVICE 和 DEVICETODESKTOP。
OK,MSDN。
这2个函数的用法如下
DESKTOPTODEVICE 用于将表从 Microsoft Access 桌面数据库复制到 Pocket Access 设备数据库。该函数的语法为:(下面数据来自msdn)

DESKTOPTODEVICE(DesktopLocn, TableList, Sync, Overwrite, DeviceLocn)

其中:

DesktopLocn 是包含要传输的表的 Access 数据库的路径和文件名。您还可以将 DSN 用作该值。
TableList 是要复制的表和字段的列表。
该参数的格式为:

[!]表名.字段名。

前导 ! 用于指定表是只读的。

Sync 定义 ActiveSync 是否应维护桌面和设备数据库之间的同步。
Overwrite 指定是否应覆盖任何现有的表。
DeviceLocn 是指设备上的 Pocket Access 数据库的路径和文件名。

DEVICETODESKTOP:该函数用于将表从 Pocket Access 设备数据库复制到 Microsoft Access 桌面数据库。该函数的语法为:

DEVICETODESKTOP(DesktopLocn, TableList, Sync, Overwrite, DeviceLocn)

DEVICETODESKTOP 函数的参数与 DESKTOPTODEVICE 函数中所用参数完全相同。


剩下的怎么调用DLL中的这2个函数,把参数套上就easy的很了吧。
 
smsman,您好,很感谢您的回答,我对这些东西还是看过不少的,我在Delphi7里面是这样定义函数的, Function DESKTOPTODEVICE(desktoplocn,tablelist:String; sync: Boolean; overwrite:Integer; devicelocn:String):LongWord; stdcall; external 'c:/Windows/system32/adofiltr.dll';
function DEVICETODESKTOP(desktoplocn,tablelist:String; sync: Boolean; overwrite:Integer; devicelocn:String):LongWord; stdcall; external 'c:/Windows/system32/adofiltr.dll';

添加一个按钮后,代码如下:
var
result,overwrite :Integer;
sPath,sTableList:String;
begin
{ if copy(path.Text, length(path.text)-2, 3) = 'mdb' then
xt := DESKTOPTODEVICE(path.Text, 'test..', false, false, '')
else if copy(path.Text, length(path.text)-2, 3) = 'cdb' then
xt := DEVICETODESKTOP(path.Text, 'test..', false, false, ''); }

spath:='c:/Windows/manager.mdb';
sTableList:='bug..work..';
overwrite:=1;

//import table from remote device.
result := DEVICETODESKTOP (spath, sTableList, False ,0,'/Windows/manager.cdb');
external 'c:/Windows/system32/adofiltr.dll';

If result = 0 Then
showmessage('Transfer Successful')
else
showmessage('An error occurred transferring the data:');

end;
编译通过,运行的时候,总是出错,应用程序正常初始化(0xc00000ba)失败,请单击“确定”,终止应用程序。 确定就什么也没有了,具体在什么地方,实在找不出来了,可不可以帮我调试一下,我把代码给你传过去。
 
QQ:150243423
 
unit Main;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls;
const
DllName:string = 'AdoFiltr.dll';
type
TDeviceToDesktop = function(desktoplocn:PChar;
tablist:PChar;
sync:Boolean;
overwrite:Integer;
decicelocn:PChar):LongInt;

TDesktopToDevice = function(desktoplocn:PChar;
tablelist:PChar;
sync:Boolean;
overwrite:Integer;
devicelocn:PChar):LongInt;

TForm1 = class(TForm)
Button1:TButton;
Button2:TButton;
procedure FormCreate(Sender:TObject);
procedure FormDestroy(Sender:TObject);
procedure Button1Click(Sender:TObject);
procedure Button2Click(Sender:TObject);
private
{ Private declarations }
DllHandle:THandle;
DeviceToDesktop:TDeviceToDesktop;
DesktopToDevice:TDesktopToDevice;
public
{ Public declarations }
end;

var
Form1:TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender:TObject);
begin
DllHandle := LoadLibrary(PChar(DllName));
if DllHandle > 0 then
begin
@DeviceToDesktop := GetProcAddress(DllHandle, PChar('DEVICETODESKTOP'));
@DesktopToDevice := GetProcAddress(DllHandle, PChar('DESKTOPTODEVICE'));
end
else
begin
Button1.Enabled := False;
Button2.Enabled := False;
Caption := 'Dll加载失败,请检查';
end;
end;

procedure TForm1.FormDestroy(Sender:TObject);
begin
if DllHandle <> 0 then
FreeLibrary(DllHandle);
end;

procedure TForm1.Button1Click(Sender:TObject);
begin

if DllHandle > 0 then
DEVICETODESKTOP(PChar(ExtractFilePath(Application.ExeName) + '/Manager.mdb')
, nil,
False,
1,
PChar('/Windows/Manager.cdb'));

end;

procedure TForm1.Button2Click(Sender:TObject);
begin
if DllHandle > 0 then
DESKTOPTODEVICE(PChar(ExtractFilePath(Application.ExeName) + '/Manager.mdb')
, nil,
False,
1,
PChar('/Windows/Manager.cdb'));
end;

end.


-----------------form文件

object Form1: TForm1
Left = 192
Top = 107
Width = 158
Height = 135
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
OnDestroy = FormDestroy
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 20
Top = 20
Width = 113
Height = 25
Caption = 'DeviceToDesktop'
TabOrder = 0
OnClick = Button1Click
end
object Button2: TButton
Left = 20
Top = 60
Width = 113
Height = 25
Caption = 'DesktopToDevice'
TabOrder = 1
OnClick = Button2Click
end
end
看看行不行
 
0桁骀,您好,能不能把您的demo发我邮箱一下,看一下,hicestone@126.com
 
怪。。我回复不起贴子????
 
procedure TForm1.Button1Click(Sender: TObject);
type
TDEVICETODESKTOP=function (desktoplocn:PChar;tablelist:PChar;sync:boolean;overwrite:integer;devicelocn:PChar):longint ;
var
convtHan:Thandle;
DEVICETODESKTOP:TDEVICETODESKTOP;
begin
convtHan:=loadlibrary('adofiltr.dll');
try
if convtHan<>0 then
begin
showmessage('loadLibrary successful');
@DEVICETODESKTOP := GetProcAddress(convtHan, PChar('DEVICETODESKTOP'));
if @DEVICETODESKTOP <>nil then
DEVICETODESKTOP(PChar(ExtractFilePath(Application.ExeName)+'dbdemos.mdb'),pchar('animals'),false,1,PChar('windows/dbdemos.cdb'));
end
else
showmessage('failed');
finally
FreeLibrary(convtHan);
end;
end;
 
不好意思,有两段代码,长了发不上去,只好用这种方法了,怪???
procedure TForm1.Button2Click(Sender: TObject);
type
TDesktopToDevice=function (desktoplocn:PChar;tablelist:PChar;sync:boolean;overwrite:integer;devicelocn:PChar):longint ;
var
convtHan:Thandle;
DesktopToDevice:TDesktopToDevice;
begin
convtHan:=loadlibrary('adofiltr.dll');
try
if convtHan<>0 then
begin
showmessage('loadLibrary successful');
@DesktopToDevice := GetProcAddress(convtHan, PChar('DesktopToDevice'));
if @DesktopToDevice <>nil then
DesktopToDevice(PChar(ExtractFilePath(Application.ExeName)+'dbdemos.mdb'),pchar('animals'),false,1,PChar('windows/dbdemos.cdb'));
end
else
showmessage('failed');
finally
FreeLibrary(convtHan);
end;
end;
end.
 
三位都写得不错,只能近乎平均分配积分了,不知道你们都乐意不乐意,在此表示感谢了!祝愿新年里工作顺利,爱情甜蜜~
 
后退
顶部