vc++ 调用dll 转换 成delphi 比较程序差别(100分)

  • 主题发起人 主题发起人 lanxy
  • 开始时间 开始时间
L

lanxy

Unregistered / Unconfirmed
GUEST, unregistred user!
#include &quot;windows.h&quot;<br>#include &lt;conio.h&gt;<br>#include &lt;time.h&gt;<br>#include &lt;stdio.h&gt;<br>enum { ESC = 0x1B }; <br><br>/* 车牌识别模块库函数 */<br>typedef BOOL (__stdcall * CISDllInitFun)(void);<br>typedef void (__stdcall * CISDllReleaseFun)(void);<br>typedef BOOL (__stdcall * CISProcessFrameFun)(char*, int, int, int, int, char*);<br><br>/* 图像读取模块库函数 */<br>typedef BOOL (__stdcall * CISLoadImageFun)(LPSTR);<br>typedef void (__stdcall * CISGetImageFun)(char**, int*, int*, int*, int*);<br>typedef void (__stdcall * CISImageDllReleaseFun)(void);<br><br>int main(int argc, char* argv[])<br>{<br><br><br>// 是否退出循环<br>BOOL bQuit = FALSE;<br>// 起始时间<br>clock_t start;<br>start = clock();<br>// 终止时间<br>clock_t stop;<br>stop = clock();<br>// 时间差<br>double timeSpan;<br>// 累计循环数<br>int ci = 20; // for calc frame rate<br>// 最大累计数<br>double cmax = (double)ci;<br><br><br>/*------------------------------------------------------------<br>*----------------- 图 像 读 取 部 分 ------------------------<br>*-----------------------------------------------------------*/<br><br>// 图像数据指针<br>char* imageData = NULL;<br>// 图像宽度<br>int width = 0;<br>// 图像高度<br>int height = 0;<br>// 图像深度<br>int depth = 0;<br>// 图像通道数<br>int channels = 0;<br>// 图像是否读取<br>BOOL bImageLoaded = FALSE;<br><br>// 图像读取动态链接库句柄<br>HINSTANCE hImageDll; <br><br>// 图像读取函数<br>CISLoadImageFun CISLoadImage;<br>// 图像参数获取函数<br>CISGetImageFun CISGetImage;<br>// 图像读取动态链接库释放函数<br>CISImageDllReleaseFun CISImageDllRelease;<br><br>// 载入图像读取模块<br>hImageDll = LoadLibrary(&quot;D://MyCom//CISImageDll//Release//CISImage.dll&quot;);<br><br>// 如果载入成功<br>if (hImageDll != NULL)<br>{<br><br><br>// 获得图像读取函数入口<br>CISLoadImage = (CISLoadImageFun)GetProcAddress(hImageDll,&quot;CISLoadImage&quot;);<br>// 获得图像参数获取函数入口<br>CISGetImage = (CISGetImageFun)GetProcAddress(hImageDll,&quot;CISGetImage&quot;);<br>// 获得图像读取动态链接库释放函数入口<br>CISImageDllRelease = (CISImageDllReleaseFun)GetProcAddress(hImageDll,&quot;CISImageDllRelease&quot;);<br><br>// 读取图像文件<br>bImageLoaded = CISLoadImage(&quot;512x384.jpg&quot;);<br>//bImageLoaded = CISLoadImage(&quot;1024x768.jpg&quot;);<br>// 720x288 为半场图像, 相应地需要修改 PlateConfigure.ini 中的参数<br>//bImageLoaded = CISLoadImage(&quot;720x288.jpg&quot;);<br><br>// 如果成功<br>if (bImageLoaded)<br>{<br><br><br>// 获得图像参数<br>CISGetImage(&imageData, &width, &height, &depth, &channels);<br><br><br>}<br><br><br>}<br>else<br>{<br><br><br>printf(&quot;The CISImage.dll can't be loaded, please check the path and name /n&quot;);<br>return 0;<br><br><br>} <br><br>/*------------------------------------------------------------<br>*----------------- 车 牌 识 别 模 块 载 入 -------------------<br>*-----------------------------------------------------------*/<br><br>// 车牌识别动态链接库句柄<br>HINSTANCE hPlateDll; <br><br>// 车牌识别模块初始化函数<br>CISDllInitFun CISDllInit;<br>// 车牌识别模块释放函数<br>CISDllReleaseFun CISDllRelease;<br>// 车牌识别模块图像处理函数<br>CISProcessFrameFun CISProcessFrame;<br><br>// 载入车牌识别模块<br>hPlateDll = LoadLibrary(&quot;D://MyCom//CubicPlateDll//Release//CubicPlate.dll&quot;);<br>// 如果载入不成功<br>if (hPlateDll == NULL)<br>{<br><br><br>printf(&quot;The CubicPlate.dll can't be loaded, please check the path and name /n&quot;);<br>return 0;<br><br><br>}<br><br>// 存放车牌识别字符<br>char pPlateChars[8];<br>// 是否发现车牌<br>BOOL bFindPlate = FALSE;<br>// 获得识别模块初始化函数入口<br>CISDllInit = (CISDllInitFun)GetProcAddress(hPlateDll,&quot;CISDllInit&quot;); <br>// 获得识别模块释放函数入口<br>CISDllRelease = (CISDllReleaseFun)GetProcAddress(hPlateDll,&quot;CISDllRelease&quot;); <br>// 获得识别模块图像处理函数入口<br>CISProcessFrame = (CISProcessFrameFun)GetProcAddress(hPlateDll,&quot;CISProcessFrame&quot;); <br><br>// 如果车牌识别模块载入且图像已经读取,开始测试<br>if (hPlateDll != NULL && bImageLoaded)<br>{<br><br><br>// 识别模块初始化<br>BOOL bIniDll = CISDllInit();<br><br><br>/*---------------------------------------------------<br>*------------- 循 环 处 理 部 分 ----------------------<br>*--------------------------------------------------*/<br><br>// 如果不退出<br>while( !bQuit)<br>{<br><br><br>// 如果有键盘输入<br>if( _kbhit() )//Non-blocking<br>{<br><br><br>// 得到键盘字符 <br>char inputChar = _getch();<br><br>// 如果为ESC键<br>if(inputChar == ESC)<br>{ <br><br><br>// 退出<br>bQuit = true;<br><br><br>}<br><br><br>}<br><br>// 处理此帧图像<br>bFindPlate = CISProcessFrame(imageData, width, height, depth, channels, pPlateChars);<br><br>// 显示识别结果并计算处理速度(帧率和每帧处理时间)<br>// 由cmax的设置决定每隔多少循环输出结果<br>if (ci == (int)cmax)<br>{<br><br><br>// 如果发现车牌<br>if (bFindPlate)<br>{<br><br><br>// 输出识别结果<br>printf(&quot;%s /n&quot;,pPlateChars);<br><br><br>}<br><br>// 截至时间(以处理器时钟计)<br>stop = clock();<br>// (stop - start)/CLK_TCK 从处理器时间转换为实际秒数<br>timeSpan = double(stop - start)/CLK_TCK; <br>// 并显示处理速度(帧率和每帧处理时间)<br>printf(&quot;Performance: %4.1f fps : %2.12f spf/n&quot;, 1.0/( timeSpan / cmax), timeSpan / cmax);<br><br>// 开始时间(以处理器时钟计)<br>start = clock();<br>ci = 0;<br><br><br>}<br>ci++; <br><br><br>}<br>/*------------------- 循 环 处 理 结 束 ---------------------*/<br><br><br>}<br><br><br>// 释放车牌识别模块<br>CISDllRelease();<br>// 释放图像读取模块<br>CISImageDllRelease();<br>// 释放车牌识别模块句柄<br>FreeLibrary(hPlateDll);<br>// 释放图像读取模块句柄<br>FreeLibrary(hImageDll);<br><br><br>return 0;<br><br>}
 
请高手写出vc++调用 dll 转换成delphi示例
 
请大家讨论下,看看有多少种方法
 
Module Module1<br> &nbsp; &nbsp;Public Declare Function GetCpuSpeed Lib &quot;DLL2.dll&quot; Alias &quot;GetCpuSpeed&quot; () As Integer<br> &nbsp; &nbsp;Public Declare Sub InitCommonControls Lib &quot;comctl32.dll&quot; Alias &quot;InitCommonControls&quot; ()<br><br> &nbsp; &nbsp;'车牌识别模块库函数<br> &nbsp; &nbsp;Public Declare Function CISDllInitFun Lib &quot;CubicPlate.dll&quot; Alias &quot;CISDllInit&quot; () As Boolean<br> &nbsp; &nbsp;Public Declare Sub CISDllReleaseFun Lib &quot;CubicPlate.dll&quot; Alias &quot;CISDllRelease&quot; ()<br> &nbsp; &nbsp;Public Declare Function CISProcessFrameFun Lib &quot;CubicPlate.dll&quot; Alias &quot;CISProcessFrame&quot; (ByVal a As IntPtr, ByVal b As Integer, ByVal Byvalc As Integer, ByVal d As Integer, ByVal e As Integer, ByRef f As Byte()) As Boolean<br><br> &nbsp; &nbsp;' 图像读取模块库函数<br> &nbsp; &nbsp;Public Declare Auto Function CISLoadImageFun Lib &quot;CISImage.dll&quot; Alias &quot;CISLoadImage&quot; (ByRef LPSTR As String) As Long<br> &nbsp; &nbsp;Public Declare Sub CISGetImageFun Lib &quot;CISImage.dll&quot; Alias &quot;CISGetImage&quot; (ByRef p1 As IntPtr, ByRef p2 As Int32, ByRef p3 As Int32, ByRef p4 As Int32, ByRef p5 As Int32)<br> &nbsp; &nbsp;Public Declare Sub CISImageDllReleaseFun Lib &quot;CISImage.dll&quot; Alias &quot;CISGetImage&quot; ()<br><br> &nbsp; &nbsp;'定时器API<br> &nbsp; &nbsp;Public Declare Function QueryPerformanceFrequency Lib &quot;kernel32&quot; Alias &quot;QueryPerformanceFrequency&quot; (ByRef lpFrequency As Double) As Long<br> &nbsp; &nbsp;Public Declare Function QueryPerformanceCounter Lib &quot;kernel32&quot; Alias &quot;QueryPerformanceCounter&quot; (ByRef lpPerformanceCount As Double) As Long<br><br> &nbsp; &nbsp;'委托声明<br> &nbsp; &nbsp;Public Delegate Function CISLoadImageA(ByRef LPSTR As String) As Long<br> &nbsp; &nbsp;Public Delegate Sub CISGetImageA(ByRef p1 As IntPtr, ByRef p2 As Int32, ByRef p3 As Int32, ByRef p4 As Int32, ByRef p5 As Int32)<br> &nbsp; &nbsp;Public Delegate Sub CISImageDllReleaseA()<br> &nbsp; &nbsp;Public Delegate Function CISDllInitA() As Boolean<br> &nbsp; &nbsp;Public Delegate Sub CISDllReleaseA()<br> &nbsp; &nbsp;Public Delegate Function CISProcessFrameA(ByVal a As IntPtr, ByVal b As Integer, ByVal c As Integer, ByVal d As Integer, ByVal e As Integer, ByRef f As Byte()) As Boolean<br><br> &nbsp; &nbsp;Public Delegate Function QPFA(ByRef lpFrequency As Double) As Long<br> &nbsp; &nbsp;Public Delegate Function QPCA(ByRef lpPerformanceCount As Double) As Long<br><br> &nbsp; &nbsp;Sub Main()<br> &nbsp; &nbsp; &nbsp; &nbsp;Try<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.Console.Title = &quot;Picture Proc&quot;<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'Dim GetCpuSpeedFun As New GetCpuSpeedA(AddressOf GetCpuSpeed)<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'System.Console.WriteLine(&quot;CPU Speed is:&quot; + GetCpuSpeedFun.Invoke().ToString)<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Dim Ctr1, Ctr2, Freq As Double<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Call SetHook()<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Dim InStream As IO.TextReader = Console.In<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Dim ci As Integer = 1000 '循环次数<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Dim n As Long = 0<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Dim imageData As IntPtr = 0<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Dim channels As Integer = 0<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Dim width As Integer = 0<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Dim height As Integer = 0<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Dim depth As Integer = 0<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Dim bImageLoaded As Boolean = False<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Dim bIniDll As Boolean = False<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Dim hImageDll As Long = 0<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Dim hPlateDll As Long = 0<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Dim pPlateChars(8) As Byte<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Dim bFindPlate As Boolean = False<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Dim cmax As Double = 0<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Dim KeyAscii As Integer = 0<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Dim bQuit As Boolean = False<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Dim CISLoadImage As New CISLoadImageA(AddressOf CISLoadImageFun)<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Dim CISGetImage As New CISGetImageA(AddressOf CISGetImageFun)<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Dim CISImageDllRelease As New CISImageDllReleaseA(AddressOf CISImageDllReleaseFun)<br><br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Dim nSpeed As Integer<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nSpeed = GetCpuSpeed()<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Global.System.Console.WriteLine(&quot; cpu &nbsp;speed is &quot; & Str(nSpeed))<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bImageLoaded = CISLoadImage.Invoke(&quot;512x384.jpg&quot;)<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;If bImageLoaded = True Then<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CISGetImage.Invoke(imageData, width, height, depth, channels)<br><br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;End If<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Dim CISDllInit As New CISDllInitA(AddressOf CISDllInitFun)<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Dim CISDllRelease As New CISDllReleaseA(AddressOf CISDllReleaseFun)<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Dim CISProcessFrame As New CISProcessFrameA(AddressOf CISProcessFrameFun)<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;If bImageLoaded = True Then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bIniDll = CISDllInit.Invoke<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;End If<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Dim QPF As New QPFA(AddressOf QueryPerformanceFrequency)<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Dim QPC As New QPCA(AddressOf QueryPerformanceCounter)<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Dim Count As Long<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Count = QPF.Invoke(Freq)<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Count = QPC.Invoke(Ctr1)<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SetHook()<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;While Not bQuit = True<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bFindPlate = CISProcessFrame.Invoke(imageData, width, height, depth, channels, pPlateChars)<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;If bFindPlate = True Then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Global.System.Console.WriteLine(pPlateChars)<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;End If<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;If n = ci Then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Count = QPC.Invoke(Ctr2)<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.Console.WriteLine(&quot;fps:&quot; + Str(((Ctr2 - Ctr1) / Freq / n)))<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'bQuit = True<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Else<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;n = n + 1<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;End If<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;End While<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.Console.WriteLine()<br> &nbsp; &nbsp; &nbsp; &nbsp;Catch ex As Exception<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Global.System.Console.WriteLine(ex.Message)<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Throw ex<br> &nbsp; &nbsp; &nbsp; &nbsp;End Try<br> &nbsp; &nbsp;End Sub<br><br>End Module
 
Module Module2<br> &nbsp; &nbsp;Public Declare Function GetCurrentThreadId Lib &quot;kernel32&quot; () As Integer<br> &nbsp; &nbsp;Public Declare Function SetWindowsHookEx Lib &quot;user32&quot; Alias &quot;SetWindowsHookExA&quot; (ByVal idHook As Integer, ByVal lpfn As HookProc, ByVal hmod As Integer, ByVal dwThreadId As Integer) As Integer<br> &nbsp; &nbsp;Public Declare Function UnhookWindowsHookEx Lib &quot;user32&quot; (ByVal hHook As Integer) As Integer<br> &nbsp; &nbsp;Public Declare Function CallNextHookEx Lib &quot;user32&quot; (ByVal hHook As Integer, ByVal nCode As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer<br><br> &nbsp; &nbsp;'Public Declare Function SetHookEx Lib &quot;The Dynamic Linking Library.dll&quot; Alias &quot;SetHook&quot; (ByVal iCode As Long, ByVal lpfn As HookProc) As Long<br> &nbsp; &nbsp;'Public Declare Function UnHookEx Lib &quot;The Dynamic Linking Library.dll&quot; Alias &quot;UnHook&quot; (ByVal HModule As Long) As Long<br> &nbsp; &nbsp;'Public Declare Function GetCpuSpeed Lib &quot;DLL2.dll&quot; () As Integer<br><br> &nbsp; &nbsp;Public Delegate Function HookProc(ByVal nCode As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer<br> &nbsp; &nbsp;Public Delegate Function GetCpuSpeedA() As Integer<br><br> &nbsp; &nbsp;Public Thread1 As New Threading.Thread(AddressOf SetHook)<br><br> &nbsp; &nbsp;Public hnexthookproc As Integer<br> &nbsp; &nbsp;Public Const PM_KEY_SPACE As Short = &H20S<br><br> &nbsp; &nbsp;Public Enum HookType<br> &nbsp; &nbsp; &nbsp; &nbsp;WH_KEYBOARD = 2<br> &nbsp; &nbsp;End Enum<br><br> &nbsp; &nbsp;Public Sub UnHook() '解Hook<br> &nbsp; &nbsp; &nbsp; &nbsp;If hnexthookproc &lt;&gt; 0 Then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;UnhookWindowsHookEx(hnexthookproc)<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;hnexthookproc = 0<br> &nbsp; &nbsp; &nbsp; &nbsp;End If<br> &nbsp; &nbsp;End Sub<br><br> &nbsp; &nbsp;Public Sub SetHook() '设置Hook<br> &nbsp; &nbsp; &nbsp; &nbsp;If hnexthookproc &lt;&gt; 0 Then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Exit Sub<br> &nbsp; &nbsp; &nbsp; &nbsp;End If<br> &nbsp; &nbsp; &nbsp; &nbsp;hnexthookproc = SetWindowsHookEx(HookType.WH_KEYBOARD, AddressOf MyKeyboardProc, 0, GetCurrentThreadId)<br> &nbsp; &nbsp; &nbsp; &nbsp;'hnexthookproc = SetHookEx(HookType.WH_KEYBOARD, AddressOf MyKeyboardProc)<br> &nbsp; &nbsp;End Sub<br><br> &nbsp; &nbsp;Public Function MyKeyboardProc(ByVal nCode As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer<br> &nbsp; &nbsp; &nbsp; &nbsp;MyKeyboardProc = 0<br> &nbsp; &nbsp; &nbsp; &nbsp;If nCode &lt; 0 Then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MyKeyboardProc = CallNextHookEx(hnexthookproc, nCode, wParam, lParam)<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Exit Function<br> &nbsp; &nbsp; &nbsp; &nbsp;End If<br> &nbsp; &nbsp; &nbsp; &nbsp;If wParam = System.Windows.Forms.Keys.Down Then 'Please use the key you want to catch!<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MyKeyboardProc = 1<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'写入你自己的代码<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Console.WriteLine(&quot;OK!&quot;)<br> &nbsp; &nbsp; &nbsp; &nbsp;End If<br> &nbsp; &nbsp;End Function<br><br> &nbsp; &nbsp;Public Sub SetHookEx()<br> &nbsp; &nbsp; &nbsp; &nbsp;Thread1.Start()<br> &nbsp; &nbsp;End Sub<br><br>End Module<br>vb榜完毕
 
我对vc++和vb都不是很了解! 帮不了什么.
 
里面没有特殊的东西,翻译起来并不复杂,是一个费力气的工作,<br>估计没有人愿意帮你转换,建议你还是自己转换吧,遇到问题可以给我发邮件<br>tseug@263.net
 
typedef BOOL (__stdcall * CISProcessFrameFun)(char*, int, int, int, int, char*);就上面这个来改写为delphi 的:<br>type<br> &nbsp;TCISProcessFrameFun= function(P1: PChar; A, B, C, D: integer; P2: PChar): boolean; stdcall;<br>应该句是这样吧! 你试试看.
 
问题已经解决,谢谢各位参与讨论!谢谢俺们的肖老师:欢迎程序爱好者参考。<br>最终正确版:<br>unit test;<br>interface<br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, &nbsp; StdCtrls,mmsystem;<br>type<br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;Button1: TButton;<br> &nbsp; &nbsp;Button2: TButton;<br> &nbsp; &nbsp;Edit1: TEdit;<br> &nbsp; &nbsp;procedure Button1Click(Sender: TObject);<br> &nbsp; &nbsp;procedure Button2Click(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br>var<br> &nbsp;Form1: TForm1;<br>implementation<br>{$R *.dfm}<br>procedure TForm1.Button1Click(Sender: TObject);<br>type<br> &nbsp;//图象导入<br> &nbsp;TCISLoadImageFun = function(PImgName: PChar): Boolean; stdcall;<br> &nbsp;TCISGetImageFun &nbsp;= procedure(PImageData: PChar; &nbsp;Pwidth, Pheight, Pdepth, Pchannels: PInteger);stdcall;<br> &nbsp;TCISImageDllReleaseFun = procedure; stdcall;<br>//车牌处理<br>CISDllInitFun &nbsp;= function(): Boolean; stdcall;<br> CISDllReleaseFun = procedure; stdcall;<br>CISProcessFrameFun = function(PimageData: PChar; &nbsp;width, height,<br>depth, channels: Integer; pPlateChars:pchar ): Boolean;stdcall;<br>var<br>CISImageHandle: THandle;<br> CubicPlateHandle: THandle;<br><br> &nbsp;//图片导入<br> &nbsp;CISGetImage: TCISGetImageFun;<br> CISLoadImage: TCISLoadImageFun;<br> &nbsp;CISImageRelease: TCISImageDllReleaseFun;<br> //车牌识别<br> &nbsp;CISDllInit:CISDllInitFun;<br> &nbsp;CISDllRelease:CISDllReleaseFun;<br> &nbsp;CISProcessFrame:CISProcessFrameFun;<br> loadpic: Boolean;<br> // 图像数据指针 存放车牌识别字符<br> &nbsp;PimageData, pPlateChars : PChar;<br> &nbsp; //,pPlateChars<br> &nbsp; //pPlateChars:array[0..8] of pchar ;<br> &nbsp;//图像宽度 &nbsp;图像高度 图像深度 图像通道数<br> &nbsp;Pwidth, &nbsp;pheight, Pdepth, Pchannels: PInteger;<br> width, &nbsp;height, depth, channels: Integer;<br> //计时<br> &nbsp;//计时频率<br> &nbsp; c1:int64;<br> &nbsp;// 起始时间 结束时间<br> &nbsp; t1,t2:int64;<br> &nbsp;//用去时间<br> &nbsp; r1:double;<br> &nbsp; xxs : &nbsp; Boolean;<br> &nbsp; Tp,Tp2:TFarProc;<br>begin<br> &nbsp;new(PimageData);<br> &nbsp;New(Pwidth);<br> &nbsp;New(pheight);<br> &nbsp;New(Pdepth);<br> &nbsp;New(Pchannels);<br> &nbsp;New(pPlateChars);<br> &nbsp; &nbsp;//申请内存保存车拍<br> &nbsp;getmem(pPlateChars, 8);<br> &nbsp;//计时 开始<br> &nbsp; &nbsp;QueryPerformanceFrequency(c1);//WINDOWS API 返回计数频率(Intel86:1193180)(获得系统的高性能频率计数器在一毫秒内的震动次数)<br> &nbsp; &nbsp;QueryPerformanceCounter(t1);//WINDOWS API 获取开始计数值<br> &nbsp;//图片导入、<br> &nbsp;CISImageHandle := LoadLibrary('CISImage.dll');<br> &nbsp;if CISImageHandle &gt; 0 then<br> &nbsp; try<br> &nbsp; &nbsp;Tp := GetProcAddress(CISImageHandle, PChar('CISLoadImage'));<br> &nbsp; CISLoadImage := TCISLoadImageFun(Tp);<br> &nbsp; @CISGetImage := GetProcAddress(CISImageHandle, PChar('CISGetImage'));<br> &nbsp; @CISImageRelease := &nbsp;GetProcAddress(CISImageHandle,PChar('CISImageDllRelease'));<br> &nbsp; if Tp &lt;&gt; nil &nbsp;then // or (CISLoadImage = nil)<br> &nbsp; begin<br> &nbsp; loadpic := CISLoadImage('1024.jpg');<br> &nbsp; if loadpic then<br> &nbsp; &nbsp; CISGetImage(@PimageData, Pwidth, &nbsp;Pheight,Pdepth, Pchannels);<br> &nbsp; ShowMessage(IntToStr(Pwidth^) + ':' + IntToStr(pheight^) + ':' &nbsp;+ IntToStr(Pdepth^) + ':' + IntToStr(Pchannels^));<br> &nbsp; &nbsp;// &nbsp;width := Pwidth^;<br> &nbsp; &nbsp;// &nbsp;height := Pheight^;<br> &nbsp; &nbsp; &nbsp;//depth &nbsp;:= Pdepth^;<br> &nbsp; &nbsp;// &nbsp;channels := Pchannels^;<br> &nbsp; &nbsp;//车牌识别<br> &nbsp; &nbsp;CubicPlateHandle := LoadLibrary('CubicPlate.dll');<br> &nbsp; &nbsp;if &nbsp;CubicPlateHandle &lt;=0 then exit;<br> &nbsp; &nbsp; &nbsp;Tp2 := GetProcAddress(CubicPlateHandle, PChar('CISDllInit'));<br> &nbsp; &nbsp; &nbsp;CISDllInit := CISDllInitFun(Tp2);<br> &nbsp; &nbsp; &nbsp;@CISProcessFrame := GetProcAddress(CubicPlateHandle, PChar('CISProcessFrame'));<br> &nbsp; &nbsp; &nbsp; @CISDllRelease &nbsp;:= GetProcAddress(CubicPlateHandle, PChar('CISDllRelease'));<br> &nbsp; if Tp2 &lt;&gt; nil then<br> &nbsp; &nbsp; &nbsp;xxs :=CISDllInit()<br> &nbsp; &nbsp;else exit;<br> &nbsp; &nbsp; &nbsp;xxs :=CISProcessFrame(PimageData,Pwidth^, Pheight^, Pdepth^, Pchannels^,pPlateChars);<br> &nbsp; &nbsp; if xxs then<br> &nbsp; &nbsp; &nbsp;Edit1.Text := pPlateChars<br> &nbsp; &nbsp; else<br> &nbsp; &nbsp; &nbsp;Edit1.Text := '无法识别';<br> &nbsp; // 计时结束<br> &nbsp; &nbsp;QueryPerformanceCounter(t2);//获取结束计数值<br><br>// &nbsp; r1:=(t2-t1)/c1*1000;//取得计时时间,单位毫秒(ms)<br> &nbsp; &nbsp;r1:=(t2-t1)/c1*1000000;//取得计时时间,单位微秒<br> &nbsp; // showmessage(floattostr(r1); &nbsp; IntToStr(width) + ':' + IntToStr(height) + ':' &nbsp; &nbsp; &nbsp;+ IntToStr(depth) + ':' + IntToStr(channels)+':'+<br> &nbsp; &nbsp;ShowMessage( pPlateChars &nbsp;+' &nbsp;共用去时间'+floattostr(r1)+ '微秒');<br> &nbsp; end<br> &nbsp; else<br> &nbsp; &nbsp; &nbsp;ShowMessage( 'CISGetImage函数没有找到');<br><br> &nbsp; &nbsp;finally<br> &nbsp; &nbsp;if &nbsp;CubicPlateHandle &nbsp;&gt;0 then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; CISDllRelease;<br> &nbsp; &nbsp; FreeLibrary(CubicPlateHandle);<br> &nbsp; &nbsp;end;<br> &nbsp; &nbsp; CISImageRelease;<br> &nbsp; &nbsp; FreeLibrary(CISImageHandle);<br> // Dispose(PimageData);<br>// &nbsp; &nbsp;Dispose(Pwidth);<br>// &nbsp; &nbsp;Dispose(pheight);<br>// &nbsp; &nbsp;Dispose(Pdepth);<br>// &nbsp; &nbsp;Dispose(Pchannels);<br> &nbsp; &nbsp;freemem (pPlateChars);<br> &nbsp;end;<br>end;<br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br>close;<br>end;<br>end.
 
多人接受答案了。
 
后退
顶部