Board index » delphi » Newbie - How to use Com DLL in App

Newbie - How to use Com DLL in App


2004-04-12 06:38:08 AM
delphi102
Hello All:
Delphi 5 Pro - I am an experienced Delphi programmer who has never used
comm automation or an external DLL before. I need to use an External DLL for
a critical function within my app.
So Far - I used TDump to determine that it is an OLE Automation DLL
I then used Project Import and imported the DLL into a declaration unit.
Now, I am lost as to what to do next. I assume that this unit is a
wrapper to the DLL in question -
1) Where can I get information on implementing this type of a DLL in
Delphi ???
2) Do I use this unit to create an instance of an object, then use that
object to access the properties and methods of the DLL ???
3) Once I make this a part of my application, do I need to register this
DLL when my app installs on customers computers ???
4) What other things do I need to watch for ???
Thank you for your help.
Neil Huhta
PS Contents of imported DLL are listed below
unit DFSSL_TLB;
// ************************************************************************
//
// WARNING
// -------
// The types declared in this file were generated from data read from a
// Type Library. If this type library is explicitly or indirectly (via
// another type library referring to this type library) re-imported, or the
// 'Refresh' command of the Type Library Editor activated while editing the
// Type Library, the contents of this file will be regenerated and all
// manual modifications will be lost.
// ************************************************************************
//
// PASTLWTR : $Revision: 1.88.1.0.1.0 $
// File generated on 4/11/2004 6:16:39 PM from Type Library described below.
//
*************************************************************************//
// NOTE:
// Items guarded by $IFDEF_LIVE_SERVER_AT_DESIGN_TIME are used by properties
// which return objects that may need to be explicitly created via a
function
// call prior to any access via the property. These items have been disabled
// in order to prevent accidental use from within the object inspector. You
// may enable them by defining LIVE_SERVER_AT_DESIGN_TIME or by selectively
// removing them from the $IFDEF blocks. However, such items must still be
// programmatically created via a method of the appropriate CoClass before
// they can be used.
// ************************************************************************
//
// Type Lib: C:\Documents and Settings\Administrator\My
Documents\Monster\Credco\ZackSDK\3.1 DataFlite SDK\DFSSL\DFSSL.dll (1)
// IID\LCID: {66950F55-CA30-425C-90F9-28603408BC93}\0
// Helpfile:
// DepndLst:
// (1) v2.0 stdole, (C:\WINNT\System32\STDOLE2.TLB)
// (2) v4.0 StdVCL, (C:\WINNT\System32\STDVCL40.DLL)
// Errors:
// Error creating palette bitmap of (TcDFSSL) : No Server registered for
this CoClass
// ************************************************************************
//
{$TYPEDADDRESS OFF} // Unit must be compiled without type-checked pointers.
interface
uses Windows, ActiveX, Classes, Graphics, OleServer, OleCtrls, StdVCL;
// *********************************************************************//
// GUIDS declared in the TypeLibrary. Following prefixes are used:
// Type Libraries : LIBID_xxxx
// CoClasses : CLASS_xxxx
// DISPInterfaces : DIID_xxxx
// Non-DISP interfaces: IID_xxxx
// *********************************************************************//
const
// TypeLibrary Major and minor versions
DFSSLMajorVersion = 1;
DFSSLMinorVersion = 0;
LIBID_DFSSL: TGUID = '{66950F55-CA30-425C-90F9-28603408BC93}';
IID__cDFSSL: TGUID = '{F2D96168-DE8F-4C92-B9D2-EFB288AF732E}';
DIID___cDFSSL: TGUID = '{7FC0E5B9-1EE8-45D7-82DE-B57193A95F90}';
CLASS_cDFSSL: TGUID = '{3D716E56-DC26-4A78-937E-D0D39C1312D6}';
// *********************************************************************//
// Declaration of Enumerations defined in Type Library
// *********************************************************************//
// Constants for enum Method
type
Method = TOleEnum;
const
vbPostData = $00000000;
vbGetData = $00000001;
type
// *********************************************************************//
// Forward declaration of types defined in TypeLibrary
// *********************************************************************//
_cDFSSL = interface;
_cDFSSLDisp = dispinterface;
__cDFSSL = dispinterface;
// *********************************************************************//
// Declaration of CoClasses defined in Type Library
// (NOTE: Here we map each CoClass to its Default Interface)
// *********************************************************************//
cDFSSL = _cDFSSL;
// *********************************************************************//
// Interface: _cDFSSL
// Flags: (4560) Hidden Dual NonExtensible OleAutomation Dispatchable
// GUID: {F2D96168-DE8F-4C92-B9D2-EFB288AF732E}
// *********************************************************************//
_cDFSSL = interface(IDispatch)
['{F2D96168-DE8F-4C92-B9D2-EFB288AF732E}']
function Get_SecureMode: WordBool; safecall;
procedure Set_SecureMode(Param1: WordBool); safecall;
function Get_CRO: WideString; safecall;
procedure Set_CRO(const Param1: WideString); safecall;
function Get_Method: Method; safecall;
procedure Set_Method(Param1: Method); safecall;
function Get_URL: WideString; safecall;
procedure Set_URL(const Param1: WideString); safecall;
procedure GetData; safecall;
function Get_Report: WideString; safecall;
property SecureMode: WordBool read Get_SecureMode write Set_SecureMode;
property CRO: WideString read Get_CRO write Set_CRO;
property Method: Method read Get_Method write Set_Method;
property URL: WideString read Get_URL write Set_URL;
property Report: WideString read Get_Report;
end;
// *********************************************************************//
// DispIntf: _cDFSSLDisp
// Flags: (4560) Hidden Dual NonExtensible OleAutomation Dispatchable
// GUID: {F2D96168-DE8F-4C92-B9D2-EFB288AF732E}
// *********************************************************************//
_cDFSSLDisp = dispinterface
['{F2D96168-DE8F-4C92-B9D2-EFB288AF732E}']
property SecureMode: WordBool dispid 1745027076;
property CRO: WideString dispid 1745027075;
property Method: Method dispid 1745027074;
property URL: WideString dispid 1745027073;
procedure GetData; dispid 1610809349;
property Report: WideString readonly dispid 1745027072;
end;
// *********************************************************************//
// DispIntf: __cDFSSL
// Flags: (4240) Hidden NonExtensible Dispatchable
// GUID: {7FC0E5B9-1EE8-45D7-82DE-B57193A95F90}
// *********************************************************************//
__cDFSSL = dispinterface
['{7FC0E5B9-1EE8-45D7-82DE-B57193A95F90}']
procedure SSLComplete; dispid 1;
procedure Status(const Message: WideString); dispid 2;
end;
// *********************************************************************//
// The Class CocDFSSL provides a Create and CreateRemote method to
// create instances of the default interface _cDFSSL exposed by
// the CoClass cDFSSL. The functions are intended to be used by
// clients wishing to automate the CoClass objects exposed by the
// server of this typelibrary.
// *********************************************************************//
CocDFSSL = class
class function Create: _cDFSSL;
class function CreateRemote(const MachineName: string): _cDFSSL;
end;
TcDFSSLStatus = procedure(Sender: TObject; var Message: OleVariant) of
object;
// *********************************************************************//
// OLE Server Proxy class declaration
// Server Object : TcDFSSL
// Help String :
// Default Interface: _cDFSSL
// Def. Intf. DISP? : No
// Event Interface: __cDFSSL
// TypeFlags : (2) CanCreate
// *********************************************************************//
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
TcDFSSLProperties= class;
{$ENDIF}
TcDFSSL = class(TOleServer)
private
FOnSSLComplete: TNotifyEvent;
FOnStatus: TcDFSSLStatus;
FIntf: _cDFSSL;
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
FProps: TcDFSSLProperties;
function GetServerProperties: TcDFSSLProperties;
{$ENDIF}
function GetDefaultInterface: _cDFSSL;
protected
procedure InitServerData; override;
procedure InvokeEvent(DispID: TDispID; var Params: TVariantArray);
override;
function Get_SecureMode: WordBool;
procedure Set_SecureMode(Param1: WordBool);
function Get_CRO: WideString;
procedure Set_CRO(const Param1: WideString);
function Get_Method: Method;
procedure Set_Method(Param1: Method);
function Get_URL: WideString;
procedure Set_URL(const Param1: WideString);
function Get_Report: WideString;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Connect; override;
procedure ConnectTo(svrIntf: _cDFSSL);
procedure Disconnect; override;
procedure GetData;
property DefaultInterface: _cDFSSL read GetDefaultInterface;
property Report: WideString read Get_Report;
property SecureMode: WordBool read Get_SecureMode write Set_SecureMode;
property CRO: WideString read Get_CRO write Set_CRO;
property Method: Method read Get_Method write Set_Method;
property URL: WideString read Get_URL write Set_URL;
published
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
property Server: TcDFSSLProperties read GetServerProperties;
{$ENDIF}
property OnSSLComplete: TNotifyEvent read FOnSSLComplete write
FOnSSLComplete;
property OnStatus: TcDFSSLStatus read FOnStatus write FOnStatus;
end;
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
// *********************************************************************//
// OLE Server Properties Proxy Class
// Server Object : TcDFSSL
// (This object is used by the IDE's Property Inspector to allow editing
// of the properties of this server)
// *********************************************************************//
TcDFSSLProperties = class(TPersistent)
private
FServer: TcDFSSL;
function GetDefaultInterface: _cDFSSL;
constructor Create(AServer: TcDFSSL);
protected
function Get_SecureMode: WordBool;
procedure Set_SecureMode(Param1: WordBool);
function Get_CRO: WideString;
procedure Set_CRO(const Param1: WideString);
function Get_Method: Method;
procedure Set_Method(Param1: Method);
function Get_URL: WideString;
procedure Set_URL(const Param1: WideString);
function Get_Report: WideString;
public
property DefaultInterface: _cDFSSL read GetDefaultInterface;
published
property SecureMode: WordBool read Get_SecureMode write Set_SecureMode;
property CRO: WideString read Get_CRO write Set_CRO;
property Method: Method read Get_Method write Set_Method;
property URL: WideString read Get_URL write Set_URL;
end;
{$ENDIF}
procedure Register;
implementation
uses ComObj;
class function CocDFSSL.Create: _cDFSSL;
begin
Result := CreateComObject(CLASS_cDFSSL) as _cDFSSL;
end;
class function CocDFSSL.CreateRemote(const MachineName: string): _cDFSSL;
begin
Result := CreateRemoteComObject(MachineName, CLASS_cDFSSL) as _cDFSSL;
end;
procedure TcDFSSL.InitServerData;
const
CServerData: TServerData = (
ClassID: '{3D716E56-DC26-4A78-937E-D0D39C1312D6}';
IntfIID: '{F2D96168-DE8F-4C92-B9D2-EFB288AF732E}';
EventIID: '{7FC0E5B9-1EE8-45D7-82DE-B57193A95F90}';
LicenseKey: nil;
Version: 500);
begin
ServerData := @CServerData;
end;
procedure TcDFSSL.Connect;
var
punk: IUnknown;
begin
if FIntf = nil then
begin
punk := GetServer;
ConnectEvents(punk);
Fintf:= punk as _cDFSSL;
end;
end;
procedure TcDFSSL.ConnectTo(svrIntf: _cDFSSL);
begin
Disconnect;
FIntf := svrIntf;
ConnectEvents(FIntf);
end;
procedure TcDFSSL.DisConnect;
begin
if Fintf <>nil then
begin
DisconnectEvents(FIntf);
FIntf := nil;
end;
end;
function TcDFSSL.GetDefaultInterface: _cDFSSL;
begin
if FIntf = nil then
Connect;
Assert(FIntf <>nil, 'DefaultInterface is NULL. Component is not connected
to Server. You must call ''Connect'' or ''ConnectTo'' before this
operation');
Result := FIntf;
end;
constructor TcDFSSL.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
FProps := TcDFSSLProperties.Create(Self);
{$ENDIF}
end;
destructor TcDFSSL.Destroy;
begin
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
FProps.Free;
{$ENDIF}
inherited Destroy;
end;
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
function TcDFSSL.GetServerProperties: TcDFSSLProperties;
begin
Result := FProps;
end;
{$ENDIF}
procedure TcDFSSL.InvokeEvent(DispID: TDispID; var Params: TVariantArray);
begin
case DispID of
-1: Exit; // DISPID_UNKNOWN
1: if Assigned(FOnSSLComplete) then
FOnSSLComplete(Self);
2: if Assigned(FOnStatus) then
FOnStatus(Self, Params[0] {const WideString});
end; {case DispID}
end;
function TcDFSSL.Get_SecureMode: WordBool;
begin
Result := DefaultInterface.Get_SecureMode;
end;
procedure TcDFSSL.Set_SecureMode(Param1: WordBool);
begin
DefaultInterface.Set_SecureMode(Param1);
end;
function TcDFSSL.Get_CRO: WideString;
begin
Result := DefaultInterface.Get_CRO;
end;
procedure TcDFSSL.Set_CRO(const Param1: WideString);
begin
DefaultInterface.Set_CRO(Param1);
end;
function TcDFSSL.Get_Method: Method;
begin
Result := DefaultInterface.Get_Method;
end;
procedure TcDFSSL.Set_Method(Param1: Method);
begin
DefaultInterface.Set_Method(Param1);
end;
function TcDFSSL.Get_URL: WideString;
begin
Result := DefaultInterface.Get_URL;
end;
procedure TcDFSSL.Set_URL(const Param1: WideString);
begin
DefaultInterface.Set_URL(Param1);
end;
function TcDFSSL.Get_Report: WideString;
begin
Result := DefaultInterface.Get_Report;
end;
procedure TcDFSSL.GetData;
begin
DefaultInterface.GetData;
end;
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
constructor TcDFSSLProperties.Create(AServer: TcDFSSL);
begin
inherited Create;
FServer := AServer;
end;
function TcDFSSLProperties.GetDefaultInterface: _cDFSSL;
begin
Result := FServer.DefaultInterface;
end;
function TcDFSSLProperties.Get_SecureMode: WordBool;
begin
Result := DefaultInterface.Get_SecureMode;
end;
procedure TcDFSSLProperties.Set_SecureMode(Param1: WordBool);
begin
DefaultInterface.Set_SecureMode(Param1);
end;
function TcDFSSLProperties.Get_CRO: WideString;
begin
Result := DefaultInterface.Get_CRO;
end;
procedure TcDFSSLProperties.Set_CRO(const Param1: WideString);
begin
DefaultInterface.Set_CRO(Param1);
end;
function TcDFSSLProperties.Get_Method: Method;
begin
Result := DefaultInterface.Get_Method;
end;
procedure TcDFSSLProperties.Set_Method(Param1: Method);
begin
DefaultInterface.Set_Method(Param1);
end;
function TcDFSSLProperties.Get_URL: WideString;
begin
Result := DefaultInterface.Get_URL;
end;
procedure TcDFSSLProperties.Set_URL(const Param1: WideString);
begin
DefaultInterface.Set_URL(Param1);
end;
function TcDFSSLProperties.Get_Report: WideString;
begin
Result := DefaultInterface.Get_Report;
end;
{$ENDIF}
procedure Register;
begin
RegisterComponents('NeilComp',[TcDFSSL]);
end;
end.
 
 

Re:Newbie - How to use Com DLL in App

Please disregard the above post - I have figured out how to use the
object within Delphi.
Thanks,
Neil Huhta
 

Re:Newbie - How to use Com DLL in App

"Huhtaman" <XXXX@XXXXX.COM>writes
Quote
Hello All:

Delphi 5 Pro - I am an experienced Delphi programmer who has never
used
comm automation or an external DLL before. I need to use an External DLL
for
a critical function within my app.
Hello Huhtaman,
FYI, posting that much code in your posts will probably not get you much
help.
In the future, you may want to post your code files in the attachments
newsgroup. This makes it eaiser to read and thus to help.
Here are some resources I found to be valuable in learning COM:
Peter van Ooijen Delphi Pages
www.gekko-software.nl/Delphi/index.htm
Excellent site.
Brian Long
Writing And Controlling Automation Servers
www.blong.com/Articles/Automation%20In%20Delphi/Automation.htm
Bin Ly COM Library
www.techvanguards.com/com/
This site is an excellent site for learning the in&outs of com
Allessandro Federici
www.msdelphi.com
Another excellent site.
Eric Harmon's Book
Delphi COM Programming.
This one is a must to have on your bookshelf.
hope this helps,
Steve-O