如何使用第三方提供的API(100分)

  • 主题发起人 主题发起人 wl_whu
  • 开始时间 开始时间
W

wl_whu

Unregistered / Unconfirmed
GUEST, unregistred user!
我有一个串口通讯的例子,他使用了两个dll文件。附带开发的函数,不知道如何的使用他们,请各位大虾门帮忙。
 
有没有关注的,比较急。请大家回答。我可以将例子的程序发给大家,请各位专家调通了以后回答我。
 
看参数呀!发给我,帮你看一下,另外,这个DLL是做什么用的?
 
忘了,我的邮箱是 ytalex@163.com
 
我是要调用这w95_s7m.dll,komfort.dll,两个dll里面的一些函数(安装后在system32目录下),函数的名称,参数我已经知道。其所在的dll文件我也找到了。Alex_Y我这就给你发过<br>去。麻烦你给我看一下马上回答我我的QQ:30321776有事情可以直接的问我。<br>下面是我从dll里得到的信息。其中as200_vs_field_read就是我要使用的函数。<br><br>Exports from w95_s7m.dll<br>&nbsp; 12 exported name(s), 70 export addresse(s). &nbsp;Ordinal base is 1.<br>&nbsp; Sorted by Name:<br>&nbsp; &nbsp; RVA &nbsp; &nbsp; &nbsp;Ord. Hint Name<br>&nbsp; &nbsp; -------- ---- ---- ----<br>&nbsp; &nbsp; 00005CA5 &nbsp; 24 0000 ag_info<br>&nbsp; &nbsp; 00006515 &nbsp; 58 0001 as200_ag_info<br>&nbsp; &nbsp; 00006362 &nbsp; 47 0002 as200_vs_field_read<br>&nbsp; &nbsp; 000063F4 &nbsp; 52 0003 as200_vs_field_write<br>&nbsp; &nbsp; 00005FA2 &nbsp; 15 0004 d_field_read<br>&nbsp; &nbsp; 0000623D &nbsp; 22 0005 d_field_write<br>&nbsp; &nbsp; 00005E2C &nbsp; 16 0006 db_read<br>&nbsp; &nbsp; 000060C7 &nbsp; 23 0007 db_write<br>&nbsp; &nbsp; 00003BF5 &nbsp; &nbsp;1 0008 load_tool<br>&nbsp; &nbsp; 00003EAB &nbsp; 70 0009 load_tool_ex<br>&nbsp; &nbsp; 00003A53 &nbsp; &nbsp;3 000A new_ss<br>&nbsp; &nbsp; 00003FFA &nbsp; &nbsp;2 000B unload_tool
 
太大了,发不过去。我现在精简出来,给你发过去。<br>现在的问题是,如何的使用dll里定义的函数,按照他上面的说明,只要将这个dll用<br>regsvr32注册,然后就可以象使用API一样使用他们,但是我老是注册不上去。<br>编译也不能通过。
 
哎,Alex_Y老兄,发不过去啊,老是被退回来。
 
不是有附带开发的函数吗,是c的h文件吗,用这个就可以写出delphi的定义了,不用看dll
 
和使用WINDOWS API一样使用,
 
to Pipi., 对是有c的h文件,但是如何使用,给个例子先。<br>我将此文件包含到我的工程文件中编译老是出现连接错误。语法错误到是没有。<br><br>to 张无忌, <br>看提示是说可能和WindowsAPI一样的使用,但是如何使用请给个例子先。<br>我想是先用regsvr32注册,但是老是出错
 
需要将你的.h文件转换成pas的声明。<br>其实使用第三方的“api”和使用Windows自己的api一样,不过windows的api已经被Borland给生成pas声明了。<br>贴出你的.h文件的声明吧。
 
我比较菜,下面是dll文件的.h文件内容。请大家指点。#ifdef __cplusplus<br>&nbsp; &nbsp;extern "C" {<br>#endif<br><br>#define BST_IN_RAM &nbsp; 0x0010<br>#define BST_IN_EPROM 0x0020<br><br><br>/***************************************************************************/<br>/***************************************************************************/<br>/* typedef for addess table &nbsp; &nbsp;max 16 connections &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/<br>/***************************************************************************/<br>#pragma pack(1)<br>typedef struct <br> {<br> unsigned char &nbsp;adr; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* stationsadresse &nbsp; &nbsp; default 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/<br> unsigned char &nbsp;segmentid; &nbsp; &nbsp;/* segment id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;default 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/<br> unsigned char &nbsp;slotno; &nbsp; &nbsp; &nbsp; /* slot no &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; default 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/<br> unsigned char &nbsp;rackno; &nbsp; &nbsp; &nbsp; /* rack no &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; default 0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/<br> } adr_table_type;<br>#pragma pack()<br>/***************************************************************************/<br>/* connection no, device_name, connection adress table */<br>int WINAPI load_tool(char,char *,adr_table_type *);<br>int WINAPI unload_tool(void);<br>/* connection no */<br>int WINAPI new_ss(char);<br><br><br>/*************************************************************************/<br>/**************************************************************************/<br>// functions for AS300<br>/**************************************************************************/<br>/*************************************************************************/<br>int WINAPI ag_info(char *);<br>/*************************************************************************/<br>/* blockno, no, amount, buffer */<br>int WINAPI db_read(int,int,int*,void *);<br>int WINAPI db_write(int,int,int*,void *);<br>int WINAPI d_field_read(int,int,int,void *);<br>int WINAPI d_field_write(int,int,int,void *);<br>/*************************************************************************/<br>/************************************************************************/<br>/**************************************************************************/<br>// functions for AS200<br>/**************************************************************************/<br>/**************************************************************************/<br>// no, amount, value<br>int WINAPI as200_vs_field_read(int,int,void*);<br>int WINAPI as200_vs_field_write(int,int,void*);<br>// value<br>int WINAPI as200_ag_info(void*);<br>/**************************************************************************/<br>// functions for AS200<br>/**************************************************************************/<br><br><br><br>#ifdef __cplusplus<br>&nbsp; &nbsp; } /* extern "C" */<br>#endif<br><br>
 
其实我只想使用<br>// no, amount, value<br>int WINAPI as200_vs_field_read(int,int,void*);<br>int WINAPI as200_vs_field_write(int,int,void*);<br>函数,我编译时老是发现连接错误。<br>告诉我如何使用,分不够可以再加。
 
adr_table_type=packed record<br>&nbsp; adr:char;<br>&nbsp; segmentid:char;<br>&nbsp; slotno:char;<br>&nbsp; rackno:char;<br>end;<br>Padr_table_type=^adr_table_type;<br><br>function load_tool(AChar:char; szChar:PChar;PStruc:Padr_table_tyep):integer;stdcall;<br>function unload_tool():integer;stdcall;<br><br>function ag_info(szChar:PChar):integer;stdcall;<br>function new_ss(AChar:Char):integer;stdcall;<br><br>function ag_info(szChar:PChar):integer;stdcall;<br><br>function db_read(iRetA,iRetB:integer;var iLength:integer;PData:Pointer):integer;stdcall;<br><br>function db_write(iRetA,iRetB:integer;var iLength:integer;PData:Pointer):integer;stdcall;<br>function d_field_read(iRetA,iRetB,iRetC:integer;PData:Pointer):integer;stdcall;<br>function d_field_write(iRetA,iRetB,iRetC:integer;PData:Pointer):integer;stdcall;<br><br><br>function as200_vs_field_read(iRetA,iRetB:Integer;PData:Pointer):integer;stdcall;<br>function as200_vs_field_write(iRetA,iRetB:Integer;PData:Pointer):integer;stdcall;<br>function as200_ag_info(PData:Pointer):integer;stdcall;<br>都是一些函数申明,我大致的翻译了以下,应该可以使用了
 
下载个HeadConv, 在Dr. Bob's网站上有
 
无忌大哥,谢谢你的翻译,但是我的问题不是函数规则的问题。程序编译我没有语法错误,所以证明我的程序是对的,但是编译后的程序不能被连接成一个EXE文件,提示如下的错误。我不知道如何解决。<br>[Linker Error] Unresolved external 'as200_vs_field_read' referenced from D:/程序/TEST/UNIT1.OBJ<br>经过昨天一下午的加班,问题我已经解决。我是直接调用w95_s7m.dll来实现的。下面我将我的BC的例子程序贴出来,请大家指点。<br>&nbsp; int buffer[100];<br>&nbsp; ZeroMemory(buffer,sizeof(buffer));<br>&nbsp; int dbno,dwno,anzahl;<br>&nbsp; int error;<br>&nbsp; dbno=10;<br>&nbsp; dwno=4;<br>&nbsp; anzahl=45;<br>&nbsp; adr_table_type plc_adr_table[2]={{2,0,2,0},{0,0,2,0}};<br><br>&nbsp; &nbsp; String tempstr="";<br>&nbsp; &nbsp; TApplication *app=Application;<br>&nbsp; &nbsp; int (__stdcall *as200_vs_field_read)(int,int,void*);<br>&nbsp; &nbsp; int (__stdcall *load_tool)(char,char *,adr_table_type *);<br>&nbsp; &nbsp; int (__stdcall *unload_tool)(void);<br><br>&nbsp; &nbsp; HINSTANCE DLLInst=NULL;<br>&nbsp; &nbsp; DLLInst=LoadLibrary("w95_s7m.dll");<br>&nbsp; &nbsp; if(DLLInst)<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; load_tool=(int(__stdcall*)(char,char *,adr_table_type *))GetProcAddress(DLLInst,"load_tool");<br>&nbsp; &nbsp; &nbsp; &nbsp; as200_vs_field_read=(int(__stdcall*)(int,int,void*))GetProcAddress(DLLInst,"as200_vs_field_read");<br>&nbsp; &nbsp; &nbsp; &nbsp; unload_tool=(int(__stdcall*)(void))GetProcAddress(DLLInst,"unload_tool");<br>&nbsp; &nbsp; &nbsp; &nbsp; if(load_tool)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; error=load_tool(1,"S7ONLINE",plc_adr_table);<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; if(as200_vs_field_read)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; error=as200_vs_field_read(dwno,anzahl,buffer);<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; if(unload_tool)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; error=unload_tool();<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; FreeLibrary(DLLInst);<br>&nbsp; &nbsp; &nbsp; &nbsp; DLLInst=NULL;<br>&nbsp; &nbsp; &nbsp; &nbsp; if(!unload_tool||!as200_vs_field_read||!load_tool)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MessageBox(Application-&gt;Handle,"未找到函数地址。","错误",MB_ICONERROR+MB_OK);<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; }<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; String tempstr="ws_seldate.dll";<br>&nbsp; &nbsp; &nbsp; &nbsp; tempstr="不能打开动态联接文件: "+tempstr;<br>&nbsp; &nbsp; &nbsp; &nbsp; MessageBox(Application-&gt;Handle,tempstr.c_str(),"错误",MB_ICONERROR+MB_OK);<br>&nbsp; &nbsp; }<br>
 
我也碰到过<br>用implib把你用的dll编译成lib,再加到你的工程里试试
 
在这里我谢谢张无忌大哥的指点。如果方便的话给个Mail地址我,我发程序过去,你给我试一下,看看能不能解决下面的问题。<br>下面我想问一下,有没有其他的方法使用Dll程序里面的函数,我看程序的说明好象是可以实现就象使用WindowsAPI函数一样,不用任何调用就可直接的使用。这个也是我最初的想法,但我试了老是出现上面所说的错误。请大家指点。解决了这个问题就给分。如果不能解决。在过两天我就结束此贴。
 
如云<br>如何搞!说的详细一点。implib是个什么东东。我没用过。请指点。
 
是borland/cbuilder/bin下的一个实用工具,文件名implib.exe,具体用法<br>implib yourfile.lib yourfile.dll<br>然后把生成的lib Addto project,然后在引用的cpp里import你的动态库,比如<br>extern "C" __declspec(dllimport) _stdcall bool WINAPI Logout();<br>就ok了
 
后退
顶部