D10DJkaimengwenshang/项目代码/wenshangkm/G03贸易布匹检验/U_DeviceJkDll.pas

101 lines
2.6 KiB
ObjectPascal
Raw Normal View History

2025-09-27 14:24:10 +08:00
unit U_DeviceJkDll;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, cxGraphics, cxControls, cxLookAndFeels,
cxLookAndFeelPainters, cxClasses, dxLayoutContainer,
dxLayoutControl, dxLayoutcxEditAdapters, cxContainer, cxEdit, Vcl.StdCtrls,
cxTextEdit, Vcl.ExtCtrls, dxLayoutControlAdapters, U_BaseList, Data.DB,
Data.Win.ADODB, Vcl.Buttons, Vcl.ComCtrls, Vcl.ToolWin, cxImage, cxDBEdit,
cxStyles, cxCustomData, cxData, cxDataStorage, cxNavigator,
dxDateRanges, dxScrollbarAnnotations, cxDBData, dxBarBuiltInMenu, cxPC,
cxGridLevel, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
cxGridCustomView, cxGrid, cxMemo, cxRichEdit, U_frameBads,
Datasnap.DBClient, RM_Common, RM_Class, RM_GridReport,
cxCheckBox, cxMaskEdit, cxDropDownEdit, Vcl.Menus, cxButtonEdit, RM_Dataset,
cxGeometry, dxFramedControl, dxPanel, U_KeyBoard, cxGroupBox,
cxGridCustomPopupMenu, cxGridPopupMenu, MovePanel;
procedure OpenCom(mHandle:Thandle;DllName: string;var fIsCommopen:boolean);
procedure CloseCom(DllName: string);
implementation
procedure OpenCom(mHandle:Thandle;DllName: string;var fIsCommopen:boolean);
type
TMyFunc = function(fhandle: hwnd; sCommName: PAnsiChar; IntTime: Integer;
IsMessage: Integer): hwnd; stdcall;
var
Tf: TMyFunc;
Tp: TFarProc;
Th: Thandle;
newh: hwnd;
begin
Th := LoadLibrary(pchar(trim(DllName)));
if Th > 0 then
begin
try
Tp := GetProcAddress(Th, 'CommOpen');
if Tp <> nil then
begin
Tf := TMyFunc(Tp);
newh := Tf(mHandle, 'Comm1', 500, 1);
if newh < 1 then
begin
Application.MessageBox(pchar('<27>򿪴<EFBFBD><F2BFAAB4><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>'), '<27><>ʾ');
end
else
fIsCommopen := true;
end
else
begin
fIsCommopen := false;
end;
finally
// FreeLibrary(Th);
end;
end
else
begin
fIsCommopen := false;
Application.MessageBox(pchar('<27>Ҳ<EFBFBD><D2B2><EFBFBD> ' + trim(DllName) + ' <20>ļ<EFBFBD><C4BC><EFBFBD>'), '<27><>ʾ');
end;
end;
procedure CloseCom(DllName: string);
type
TMyFunc = function(sCommName: PAnsiChar): hwnd; stdcall;
var
Tf1: TMyFunc;
Tp1: TFarProc;
Th1: Thandle;
newh1: hwnd;
begin
Th1 := LoadLibrary(pchar(trim(DllName)));
if Th1 > 0 then
begin
try
Tp1 := GetProcAddress(Th1, 'CommClose');
if Tp1 <> nil then
begin
Tf1 := TMyFunc(Tp1);
newh1 := Tf1('Comm1');
end
else
begin
end;
finally
// FreeLibrary(Th1);
end;
end
else
begin
Application.MessageBox(pchar('<27>Ҳ<EFBFBD><D2B2><EFBFBD> ' + trim(DllName) + ' <20>ļ<EFBFBD><C4BC><EFBFBD>'), '<27><>ʾ');
end;
end;
end.