在delphi中如何使用VC编写的Dll中的类?(100分)

  • 主题发起人 主题发起人 星空
  • 开始时间 开始时间

星空

Unregistered / Unconfirmed
GUEST, unregistred user!
将DLL导入Delphi后,有类、有接口,我该使用哪一个,有什么区别?
 
tlb文件如下:
unit PTALib_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 : 1.2
// File generated on 2003-5-6 9:46:29 from Type Library described below.

// ************************************************************************ //
// Type Lib: C:/Inetpub/wwwroot/iTrusPTA/PTA.dll (1)
// LIBID: {E8B8B678-A852-424F-9D0C-6FCF65C167B8}
// LCID: 0
// Helpfile:
// HelpString: iTrusPTA 2.0 Type Library
// DepndLst:
// (1) v2.0 stdole, (C:/WINNT/System32/stdole2.tlb)
// Errors:
// Error creating palette bitmap of (TiTrusPTA) : Server C:/Inetpub/wwwroot/iTrusPTA/pta.dll contains no icons
// Error creating palette bitmap of (TCertificate) : Server C:/Inetpub/wwwroot/iTrusPTA/pta.dll contains no icons
// Error creating palette bitmap of (TCertificates) : Server C:/Inetpub/wwwroot/iTrusPTA/pta.dll contains no icons
// Error creating palette bitmap of (TCertFilter) : Server C:/Inetpub/wwwroot/iTrusPTA/pta.dll contains no icons
// ************************************************************************ //
// *************************************************************************//
// 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.
{$TYPEDADDRESS OFF} // Unit must be compiled without type-checked pointers.
{$WARN SYMBOL_PLATFORM OFF}
{$WRITEABLECONST ON}
{$VARPROPSETTER ON}
interface

uses Windows, ActiveX, Classes, Graphics, OleServer, StdVCL, Variants;


// *********************************************************************//
// 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
PTALibMajorVersion = 1;
PTALibMinorVersion = 0;

LIBID_PTALib: TGUID = '{E8B8B678-A852-424F-9D0C-6FCF65C167B8}';

IID_IiTrusPTA: TGUID = '{19247043-F8F5-4F31-AF80-0068D63B1E84}';
CLASS_iTrusPTA: TGUID = '{1E0DFFCF-27FF-4574-849B-55007349FEDA}';
IID_ICertFilter: TGUID = '{814C8B22-2F2D-4E1A-8835-F1A3DD45C46A}';
IID_IObjectCollection: TGUID = '{587746E9-7BA1-43A3-99D6-BE1D960E2DBA}';
IID_ICertificates: TGUID = '{51C9E94B-FB8B-47A4-ABE4-FE91806DC7C7}';
IID_ICertificate: TGUID = '{860F2720-D3C8-47EC-B073-A10607DDCA80}';
CLASS_Certificate: TGUID = '{D8E0863D-7643-4553-89AD-A4EBCCDAA710}';
CLASS_Certificates: TGUID = '{66F50F46-70A0-4A05-BD5E-FBCC0F9641EC}';
CLASS_CertFilter: TGUID = '{BE3EB81F-5C69-419A-A4AA-856A2E30A61F}';

// *********************************************************************//
// Declaration of Enumerations defined in Type Library
// *********************************************************************//
// Constants for enum __MIDL___MIDL_itf_PTA_0000_0002
type
__MIDL___MIDL_itf_PTA_0000_0002 = TOleEnum;
const
INPUT_BASE64 = $00000001;
INPUT_HEX = $00000002;
OUTPUT_BASE64 = $00000004;
OUTPUT_HEX = $00000008;
MSG_BASE64 = $00000004;
MSG_HEX = $00000008;

// Constants for enum __MIDL___MIDL_itf_PTA_0000_0001
type
__MIDL___MIDL_itf_PTA_0000_0001 = TOleEnum;
const
KEY_USAGE_CRL_SIGN = $00000002;
KEY_USAGE_CERT_SIGN = $00000004;
KEY_USAGE_KEY_AGREEMENT = $00000008;
KEY_USAGE_DATA_ENCIPHERMENT = $00000010;
KEY_USAGE_KEY_ENCIPHERMENT = $00000020;
KEY_USAGE_NON_REPUDIATION = $00000040;
KEY_USAGE_DIGITAL_SIGNATURE = $00000080;

type

// *********************************************************************//
// Forward declaration of types defined in TypeLibrary
// *********************************************************************//
IiTrusPTA = interface;
IiTrusPTADisp = dispinterface;
ICertFilter = interface;
ICertFilterDisp = dispinterface;
IObjectCollection = interface;
ICertificates = interface;
ICertificatesDisp = dispinterface;
ICertificate = interface;
ICertificateDisp = dispinterface;

// *********************************************************************//
// Declaration of CoClasses defined in Type Library
// (NOTE: Here we map each CoClass to its Default Interface)
// *********************************************************************//
iTrusPTA = IiTrusPTA;
Certificate = ICertificate;
Certificates = ICertificates;
CertFilter = ICertFilter;


// *********************************************************************//
// Declaration of structures, unions and aliases.
// *********************************************************************//

OPTION = __MIDL___MIDL_itf_PTA_0000_0002;
KEY_USAGE_TYPE = __MIDL___MIDL_itf_PTA_0000_0001;

// *********************************************************************//
// Interface: IiTrusPTA
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {19247043-F8F5-4F31-AF80-0068D63B1E84}
// *********************************************************************//
IiTrusPTA = interface(IDispatch)
['{19247043-F8F5-4F31-AF80-0068D63B1E84}']
function Get_Filter: ICertFilter; safecall;
function Get_MyCertificates: ICertificates; safecall;
function Get_RootCertificates: ICertificates; safecall;
function Get_CACertificates: ICertificates; safecall;
function Get_OtherCertificates: ICertificates; safecall;
function DecryptMessage(const p7msg: WideString; opt: OPTION): WideString; safecall;
function VerifySignature(const msg: WideString; const sign: WideString; opt: OPTION): ICertificate; safecall;
property Filter: ICertFilter read Get_Filter;
property MyCertificates: ICertificates read Get_MyCertificates;
property RootCertificates: ICertificates read Get_RootCertificates;
property CACertificates: ICertificates read Get_CACertificates;
property OtherCertificates: ICertificates read Get_OtherCertificates;
end;

// *********************************************************************//
// DispIntf: IiTrusPTADisp
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {19247043-F8F5-4F31-AF80-0068D63B1E84}
// *********************************************************************//
IiTrusPTADisp = dispinterface
['{19247043-F8F5-4F31-AF80-0068D63B1E84}']
property Filter: ICertFilter readonly dispid 1;
property MyCertificates: ICertificates readonly dispid 2;
property RootCertificates: ICertificates readonly dispid 3;
property CACertificates: ICertificates readonly dispid 4;
property OtherCertificates: ICertificates readonly dispid 5;
function DecryptMessage(const p7msg: WideString; opt: OPTION): WideString; dispid 1610743813;
function VerifySignature(const msg: WideString; const sign: WideString; opt: OPTION): ICertificate; dispid 1610743814;
end;

// *********************************************************************//
// Interface: ICertFilter
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {814C8B22-2F2D-4E1A-8835-F1A3DD45C46A}
// *********************************************************************//
ICertFilter = interface(IDispatch)
['{814C8B22-2F2D-4E1A-8835-F1A3DD45C46A}']
procedure Clear; safecall;
function Get_Subject: WideString; safecall;
procedure Set_Subject(const pVal: WideString); safecall;
function Get_Issuer: WideString; safecall;
procedure Set_Issuer(const pVal: WideString); safecall;
function Get_SerialNumber: WideString; safecall;
procedure Set_SerialNumber(const pVal: WideString); safecall;
function Get_CSP: WideString; safecall;
procedure Set_CSP(const pVal: WideString); safecall;
property Subject: WideString read Get_Subject write Set_Subject;
property Issuer: WideString read Get_Issuer write Set_Issuer;
property SerialNumber: WideString read Get_SerialNumber write Set_SerialNumber;
property CSP: WideString read Get_CSP write Set_CSP;
end;

// *********************************************************************//
// DispIntf: ICertFilterDisp
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {814C8B22-2F2D-4E1A-8835-F1A3DD45C46A}
// *********************************************************************//
ICertFilterDisp = dispinterface
['{814C8B22-2F2D-4E1A-8835-F1A3DD45C46A}']
procedure Clear; dispid 1610743808;
property Subject: WideString dispid 1;
property Issuer: WideString dispid 2;
property SerialNumber: WideString dispid 3;
property CSP: WideString dispid 4;
end;

// *********************************************************************//
// Interface: IObjectCollection
// Flags: (4096) Dispatchable
// GUID: {587746E9-7BA1-43A3-99D6-BE1D960E2DBA}
// *********************************************************************//
IObjectCollection = interface(IDispatch)
['{587746E9-7BA1-43A3-99D6-BE1D960E2DBA}']
function Get__NewEnum(out pVal: IUnknown): HResult; stdcall;
function Get_Item(idx: Integer; out pVal: OleVariant): HResult; stdcall;
function Get_Count(out pVal: Integer): HResult; stdcall;
function Add(const cert: IUnknown): HResult; stdcall;
function Remove(idx: SYSINT): HResult; stdcall;
end;

// *********************************************************************//
// Interface: ICertificates
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {51C9E94B-FB8B-47A4-ABE4-FE91806DC7C7}
// *********************************************************************//
ICertificates = interface(IObjectCollection)
['{51C9E94B-FB8B-47A4-ABE4-FE91806DC7C7}']
procedure GhostMethod_ICertificates_0_1; safecall;
procedure GhostMethod_ICertificates_4_2; safecall;
procedure GhostMethod_ICertificates_8_3; safecall;
procedure GhostMethod_ICertificates_12_4; safecall;
procedure GhostMethod_ICertificates_16_5; safecall;
procedure GhostMethod_ICertificates_20_6; safecall;
procedure GhostMethod_ICertificates_24_7; safecall;
procedure GhostMethod_ICertificates_28_8; safecall;
procedure GhostMethod_ICertificates_32_9; safecall;
procedure GhostMethod_ICertificates_36_10; safecall;
procedure GhostMethod_ICertificates_40_11; safecall;
procedure GhostMethod_ICertificates_44_12; safecall;
function EncryptMessage(const msg: WideString; opt: OPTION): WideString; safecall;
end;

// *********************************************************************//
// DispIntf: ICertificatesDisp
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {51C9E94B-FB8B-47A4-ABE4-FE91806DC7C7}
// *********************************************************************//
ICertificatesDisp = dispinterface
['{51C9E94B-FB8B-47A4-ABE4-FE91806DC7C7}']
procedure GhostMethod_ICertificates_0_1; dispid 1610678272;
procedure GhostMethod_ICertificates_4_2; dispid 1610678273;
procedure GhostMethod_ICertificates_8_3; dispid 1610678274;
procedure GhostMethod_ICertificates_12_4; dispid 1610678275;
procedure GhostMethod_ICertificates_16_5; dispid 1610678276;
procedure GhostMethod_ICertificates_20_6; dispid 1610678277;
procedure GhostMethod_ICertificates_24_7; dispid 1610678278;
procedure GhostMethod_ICertificates_28_8; dispid 1610678279;
procedure GhostMethod_ICertificates_32_9; dispid 1610678280;
procedure GhostMethod_ICertificates_36_10; dispid 1610678281;
procedure GhostMethod_ICertificates_40_11; dispid 1610678282;
procedure GhostMethod_ICertificates_44_12; dispid 1610678283;
function EncryptMessage(const msg: WideString; opt: OPTION): WideString; dispid 1610809344;
property _NewEnum: IUnknown readonly dispid -4;
property Item[idx: Integer]: OleVariant readonly dispid 0; default;
property Count: Integer readonly dispid 1610743810;
procedure Add(const cert: IUnknown); dispid 1610743811;
procedure Remove(idx: SYSINT); dispid 1610743812;
end;

// *********************************************************************//
// Interface: ICertificate
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {860F2720-D3C8-47EC-B073-A10607DDCA80}
// *********************************************************************//
ICertificate = interface(IDispatch)
['{860F2720-D3C8-47EC-B073-A10607DDCA80}']
function Get_CommonName: WideString; safecall;
function Get_Subject: WideString; safecall;
function Get_Issuer: WideString; safecall;
function Get_CSP: WideString; safecall;
function Get_KeyContainer: WideString; safecall;
function Get_SerialNumber: WideString; safecall;
function Get_ValidFrom: TDateTime; safecall;
function Get_ValidTo: TDateTime; safecall;
function Get_KeyUsage: KEY_USAGE_TYPE; safecall;
function SignMessage(const msg: WideString; opt: OPTION): WideString; safecall;
property CommonName: WideString read Get_CommonName;
property Subject: WideString read Get_Subject;
property Issuer: WideString read Get_Issuer;
property CSP: WideString read Get_CSP;
property KeyContainer: WideString read Get_KeyContainer;
property SerialNumber: WideString read Get_SerialNumber;
property ValidFrom: TDateTime read Get_ValidFrom;
property ValidTo: TDateTime read Get_ValidTo;
property KeyUsage: KEY_USAGE_TYPE read Get_KeyUsage;
end;

// *********************************************************************//
// DispIntf: ICertificateDisp
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {860F2720-D3C8-47EC-B073-A10607DDCA80}
// *********************************************************************//
ICertificateDisp = dispinterface
['{860F2720-D3C8-47EC-B073-A10607DDCA80}']
property CommonName: WideString readonly dispid 1;
property Subject: WideString readonly dispid 2;
property Issuer: WideString readonly dispid 3;
property CSP: WideString readonly dispid 4;
property KeyContainer: WideString readonly dispid 5;
property SerialNumber: WideString readonly dispid 6;
property ValidFrom: TDateTime readonly dispid 7;
property ValidTo: TDateTime readonly dispid 8;
property KeyUsage: KEY_USAGE_TYPE readonly dispid 9;
function SignMessage(const msg: WideString; opt: OPTION): WideString; dispid 10;
end;

// *********************************************************************//
// The Class CoiTrusPTA provides a Create and CreateRemote method to
// create instances of the default interface IiTrusPTA exposed by
// the CoClass iTrusPTA. The functions are intended to be used by
// clients wishing to automate the CoClass objects exposed by the
// server of this typelibrary.
// *********************************************************************//
CoiTrusPTA = class
class function Create: IiTrusPTA;
class function CreateRemote(const MachineName: string): IiTrusPTA;
end;


// *********************************************************************//
// OLE Server Proxy class declaration
// Server Object : TiTrusPTA
// Help String : iTrusPTA Class
// Default Interface: IiTrusPTA
// Def. Intf. DISP? : No
// Event Interface:
// TypeFlags : (2) CanCreate
// *********************************************************************//
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
TiTrusPTAProperties= class;
{$ENDIF}
TiTrusPTA = class(TOleServer)
private
FIntf: IiTrusPTA;
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
FProps: TiTrusPTAProperties;
function GetServerProperties: TiTrusPTAProperties;
{$ENDIF}
function GetDefaultInterface: IiTrusPTA;
protected
procedure InitServerData; override;
function Get_Filter: ICertFilter;
function Get_MyCertificates: ICertificates;
function Get_RootCertificates: ICertificates;
function Get_CACertificates: ICertificates;
function Get_OtherCertificates: ICertificates;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Connect; override;
procedure ConnectTo(svrIntf: IiTrusPTA);
procedure Disconnect; override;
function DecryptMessage(const p7msg: WideString; opt: OPTION): WideString;
function VerifySignature(const msg: WideString; const sign: WideString; opt: OPTION): ICertificate;
property DefaultInterface: IiTrusPTA read GetDefaultInterface;
property Filter: ICertFilter read Get_Filter;
property MyCertificates: ICertificates read Get_MyCertificates;
property RootCertificates: ICertificates read Get_RootCertificates;
property CACertificates: ICertificates read Get_CACertificates;
property OtherCertificates: ICertificates read Get_OtherCertificates;
published
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
property Server: TiTrusPTAProperties read GetServerProperties;
{$ENDIF}
end;

{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
// *********************************************************************//
// OLE Server Properties Proxy Class
// Server Object : TiTrusPTA
// (This object is used by the IDE's Property Inspector to allow editing
// of the properties of this server)
// *********************************************************************//
TiTrusPTAProperties = class(TPersistent)
private
FServer: TiTrusPTA;
function GetDefaultInterface: IiTrusPTA;
constructor Create(AServer: TiTrusPTA);
protected
function Get_Filter: ICertFilter;
function Get_MyCertificates: ICertificates;
function Get_RootCertificates: ICertificates;
function Get_CACertificates: ICertificates;
function Get_OtherCertificates: ICertificates;
public
property DefaultInterface: IiTrusPTA read GetDefaultInterface;
published
end;
{$ENDIF}


// *********************************************************************//
// The Class CoCertificate provides a Create and CreateRemote method to
// create instances of the default interface ICertificate exposed by
// the CoClass Certificate. The functions are intended to be used by
// clients wishing to automate the CoClass objects exposed by the
// server of this typelibrary.
// *********************************************************************//
CoCertificate = class
class function Create: ICertificate;
class function CreateRemote(const MachineName: string): ICertificate;
end;


// *********************************************************************//
// OLE Server Proxy class declaration
// Server Object : TCertificate
// Help String : Certificate Class
// Default Interface: ICertificate
// Def. Intf. DISP? : No
// Event Interface:
// TypeFlags : (2) CanCreate
// *********************************************************************//
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
TCertificateProperties= class;
{$ENDIF}
TCertificate = class(TOleServer)
private
FIntf: ICertificate;
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
FProps: TCertificateProperties;
function GetServerProperties: TCertificateProperties;
{$ENDIF}
function GetDefaultInterface: ICertificate;
protected
procedure InitServerData; override;
function Get_CommonName: WideString;
function Get_Subject: WideString;
function Get_Issuer: WideString;
function Get_CSP: WideString;
function Get_KeyContainer: WideString;
function Get_SerialNumber: WideString;
function Get_ValidFrom: TDateTime;
function Get_ValidTo: TDateTime;
function Get_KeyUsage: KEY_USAGE_TYPE;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Connect; override;
procedure ConnectTo(svrIntf: ICertificate);
procedure Disconnect; override;
function SignMessage(const msg: WideString; opt: OPTION): WideString;
property DefaultInterface: ICertificate read GetDefaultInterface;
property CommonName: WideString read Get_CommonName;
property Subject: WideString read Get_Subject;
property Issuer: WideString read Get_Issuer;
property CSP: WideString read Get_CSP;
property KeyContainer: WideString read Get_KeyContainer;
property SerialNumber: WideString read Get_SerialNumber;
property ValidFrom: TDateTime read Get_ValidFrom;
property ValidTo: TDateTime read Get_ValidTo;
property KeyUsage: KEY_USAGE_TYPE read Get_KeyUsage;
published
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
property Server: TCertificateProperties read GetServerProperties;
{$ENDIF}
end;

{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
// *********************************************************************//
// OLE Server Properties Proxy Class
// Server Object : TCertificate
// (This object is used by the IDE's Property Inspector to allow editing
// of the properties of this server)
// *********************************************************************//
TCertificateProperties = class(TPersistent)
private
FServer: TCertificate;
function GetDefaultInterface: ICertificate;
constructor Create(AServer: TCertificate);
protected
function Get_CommonName: WideString;
function Get_Subject: WideString;
function Get_Issuer: WideString;
function Get_CSP: WideString;
function Get_KeyContainer: WideString;
function Get_SerialNumber: WideString;
function Get_ValidFrom: TDateTime;
function Get_ValidTo: TDateTime;
function Get_KeyUsage: KEY_USAGE_TYPE;
public
property DefaultInterface: ICertificate read GetDefaultInterface;
published
end;
{$ENDIF}


// *********************************************************************//
// The Class CoCertificates provides a Create and CreateRemote method to
// create instances of the default interface ICertificates exposed by
// the CoClass Certificates. The functions are intended to be used by
// clients wishing to automate the CoClass objects exposed by the
// server of this typelibrary.
// *********************************************************************//
CoCertificates = class
class function Create: ICertificates;
class function CreateRemote(const MachineName: string): ICertificates;
end;


// *********************************************************************//
// OLE Server Proxy class declaration
// Server Object : TCertificates
// Help String : Certificates Class
// Default Interface: ICertificates
// Def. Intf. DISP? : No
// Event Interface:
// TypeFlags : (2) CanCreate
// *********************************************************************//
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
TCertificatesProperties= class;
{$ENDIF}
TCertificates = class(TOleServer)
private
FIntf: ICertificates;
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
FProps: TCertificatesProperties;
function GetServerProperties: TCertificatesProperties;
{$ENDIF}
function GetDefaultInterface: ICertificates;
protected
procedure InitServerData; override;
function Get__NewEnum(out pVal: IUnknown): HResult;
function Get_Item(idx: Integer; out pVal: OleVariant): HResult;
function Get_Count(out pVal: Integer): HResult;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Connect; override;
procedure ConnectTo(svrIntf: ICertificates);
procedure Disconnect; override;
function Add(const cert: IUnknown): HResult;
function Remove(idx: SYSINT): HResult;
function EncryptMessage(const msg: WideString; opt: OPTION): WideString;
property DefaultInterface: ICertificates read GetDefaultInterface;
published
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
property Server: TCertificatesProperties read GetServerProperties;
{$ENDIF}
end;

{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
// *********************************************************************//
// OLE Server Properties Proxy Class
// Server Object : TCertificates
// (This object is used by the IDE's Property Inspector to allow editing
// of the properties of this server)
// *********************************************************************//
TCertificatesProperties = class(TPersistent)
private
FServer: TCertificates;
function GetDefaultInterface: ICertificates;
constructor Create(AServer: TCertificates);
protected
function Get__NewEnum(out pVal: IUnknown): HResult;
function Get_Item(idx: Integer; out pVal: OleVariant): HResult;
function Get_Count(out pVal: Integer): HResult;
public
property DefaultInterface: ICertificates read GetDefaultInterface;
published
end;
{$ENDIF}


// *********************************************************************//
// The Class CoCertFilter provides a Create and CreateRemote method to
// create instances of the default interface ICertFilter exposed by
// the CoClass CertFilter. The functions are intended to be used by
// clients wishing to automate the CoClass objects exposed by the
// server of this typelibrary.
// *********************************************************************//
CoCertFilter = class
class function Create: ICertFilter;
class function CreateRemote(const MachineName: string): ICertFilter;
end;


// *********************************************************************//
// OLE Server Proxy class declaration
// Server Object : TCertFilter
// Help String : CertFilter Class
// Default Interface: ICertFilter
// Def. Intf. DISP? : No
// Event Interface:
// TypeFlags : (2) CanCreate
// *********************************************************************//
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
TCertFilterProperties= class;
{$ENDIF}
TCertFilter = class(TOleServer)
private
FIntf: ICertFilter;
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
FProps: TCertFilterProperties;
function GetServerProperties: TCertFilterProperties;
{$ENDIF}
function GetDefaultInterface: ICertFilter;
protected
procedure InitServerData; override;
function Get_Subject: WideString;
procedure Set_Subject(const pVal: WideString);
function Get_Issuer: WideString;
procedure Set_Issuer(const pVal: WideString);
function Get_SerialNumber: WideString;
procedure Set_SerialNumber(const pVal: WideString);
function Get_CSP: WideString;
procedure Set_CSP(const pVal: WideString);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Connect; override;
procedure ConnectTo(svrIntf: ICertFilter);
procedure Disconnect; override;
procedure Clear;
property DefaultInterface: ICertFilter read GetDefaultInterface;
property Subject: WideString read Get_Subject write Set_Subject;
property Issuer: WideString read Get_Issuer write Set_Issuer;
property SerialNumber: WideString read Get_SerialNumber write Set_SerialNumber;
property CSP: WideString read Get_CSP write Set_CSP;
published
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
property Server: TCertFilterProperties read GetServerProperties;
{$ENDIF}
end;

{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
// *********************************************************************//
// OLE Server Properties Proxy Class
// Server Object : TCertFilter
// (This object is used by the IDE's Property Inspector to allow editing
// of the properties of this server)
// *********************************************************************//
TCertFilterProperties = class(TPersistent)
private
FServer: TCertFilter;
function GetDefaultInterface: ICertFilter;
constructor Create(AServer: TCertFilter);
protected
function Get_Subject: WideString;
procedure Set_Subject(const pVal: WideString);
function Get_Issuer: WideString;
procedure Set_Issuer(const pVal: WideString);
function Get_SerialNumber: WideString;
procedure Set_SerialNumber(const pVal: WideString);
function Get_CSP: WideString;
procedure Set_CSP(const pVal: WideString);
public
property DefaultInterface: ICertFilter read GetDefaultInterface;
published
property Subject: WideString read Get_Subject write Set_Subject;
property Issuer: WideString read Get_Issuer write Set_Issuer;
property SerialNumber: WideString read Get_SerialNumber write Set_SerialNumber;
property CSP: WideString read Get_CSP write Set_CSP;
end;
{$ENDIF}


procedure Register;

resourcestring
dtlServerPage = 'ActiveX';

dtlOcxPage = 'ActiveX';

implementation

uses ComObj;

class function CoiTrusPTA.Create: IiTrusPTA;
begin
Result := CreateComObject(CLASS_iTrusPTA) as IiTrusPTA;
end;

class function CoiTrusPTA.CreateRemote(const MachineName: string): IiTrusPTA;
begin
Result := CreateRemoteComObject(MachineName, CLASS_iTrusPTA) as IiTrusPTA;
end;

procedure TiTrusPTA.InitServerData;
const
CServerData: TServerData = (
ClassID: '{1E0DFFCF-27FF-4574-849B-55007349FEDA}';
IntfIID: '{19247043-F8F5-4F31-AF80-0068D63B1E84}';
EventIID: '';
LicenseKey: nil;
Version: 500);
begin
ServerData := @CServerData;
end;

procedure TiTrusPTA.Connect;
var
punk: IUnknown;
begin
if FIntf = nil then
begin
punk := GetServer;
Fintf:= punk as IiTrusPTA;
end;
end;

procedure TiTrusPTA.ConnectTo(svrIntf: IiTrusPTA);
begin
Disconnect;
FIntf := svrIntf;
end;

procedure TiTrusPTA.DisConnect;
begin
if Fintf <> nil then
begin
FIntf := nil;
end;
end;

function TiTrusPTA.GetDefaultInterface: IiTrusPTA;
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 TiTrusPTA.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
FProps := TiTrusPTAProperties.Create(Self);
{$ENDIF}
end;

destructor TiTrusPTA.Destroy;
begin
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
FProps.Free;
{$ENDIF}
inherited Destroy;
end;

{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
function TiTrusPTA.GetServerProperties: TiTrusPTAProperties;
begin
Result := FProps;
end;
{$ENDIF}

function TiTrusPTA.Get_Filter: ICertFilter;
begin
Result := DefaultInterface.Filter;
end;

function TiTrusPTA.Get_MyCertificates: ICertificates;
begin
Result := DefaultInterface.MyCertificates;
end;

function TiTrusPTA.Get_RootCertificates: ICertificates;
begin
Result := DefaultInterface.RootCertificates;
end;

function TiTrusPTA.Get_CACertificates: ICertificates;
begin
Result := DefaultInterface.CACertificates;
end;

function TiTrusPTA.Get_OtherCertificates: ICertificates;
begin
Result := DefaultInterface.OtherCertificates;
end;

function TiTrusPTA.DecryptMessage(const p7msg: WideString; opt: OPTION): WideString;
begin
Result := DefaultInterface.DecryptMessage(p7msg, opt);
end;

function TiTrusPTA.VerifySignature(const msg: WideString; const sign: WideString; opt: OPTION): ICertificate;
begin
Result := DefaultInterface.VerifySignature(msg, sign, opt);
end;

{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
constructor TiTrusPTAProperties.Create(AServer: TiTrusPTA);
begin
inherited Create;
FServer := AServer;
end;

function TiTrusPTAProperties.GetDefaultInterface: IiTrusPTA;
begin
Result := FServer.DefaultInterface;
end;

function TiTrusPTAProperties.Get_Filter: ICertFilter;
begin
Result := DefaultInterface.Filter;
end;

function TiTrusPTAProperties.Get_MyCertificates: ICertificates;
begin
Result := DefaultInterface.MyCertificates;
end;

function TiTrusPTAProperties.Get_RootCertificates: ICertificates;
begin
Result := DefaultInterface.RootCertificates;
end;

function TiTrusPTAProperties.Get_CACertificates: ICertificates;
begin
Result := DefaultInterface.CACertificates;
end;

function TiTrusPTAProperties.Get_OtherCertificates: ICertificates;
begin
Result := DefaultInterface.OtherCertificates;
end;

{$ENDIF}

class function CoCertificate.Create: ICertificate;
begin
Result := CreateComObject(CLASS_Certificate) as ICertificate;
end;

class function CoCertificate.CreateRemote(const MachineName: string): ICertificate;
begin
Result := CreateRemoteComObject(MachineName, CLASS_Certificate) as ICertificate;
end;

procedure TCertificate.InitServerData;
const
CServerData: TServerData = (
ClassID: '{D8E0863D-7643-4553-89AD-A4EBCCDAA710}';
IntfIID: '{860F2720-D3C8-47EC-B073-A10607DDCA80}';
EventIID: '';
LicenseKey: nil;
Version: 500);
begin
ServerData := @CServerData;
end;

procedure TCertificate.Connect;
var
punk: IUnknown;
begin
if FIntf = nil then
begin
punk := GetServer;
Fintf:= punk as ICertificate;
end;
end;

procedure TCertificate.ConnectTo(svrIntf: ICertificate);
begin
Disconnect;
FIntf := svrIntf;
end;

procedure TCertificate.DisConnect;
begin
if Fintf <> nil then
begin
FIntf := nil;
end;
end;

function TCertificate.GetDefaultInterface: ICertificate;
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 TCertificate.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
FProps := TCertificateProperties.Create(Self);
{$ENDIF}
end;

destructor TCertificate.Destroy;
begin
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
FProps.Free;
{$ENDIF}
inherited Destroy;
end;

{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
function TCertificate.GetServerProperties: TCertificateProperties;
begin
Result := FProps;
end;
{$ENDIF}

function TCertificate.Get_CommonName: WideString;
begin
Result := DefaultInterface.CommonName;
end;

function TCertificate.Get_Subject: WideString;
begin
Result := DefaultInterface.Subject;
end;

function TCertificate.Get_Issuer: WideString;
begin
Result := DefaultInterface.Issuer;
end;

function TCertificate.Get_CSP: WideString;
begin
Result := DefaultInterface.CSP;
end;

function TCertificate.Get_KeyContainer: WideString;
begin
Result := DefaultInterface.KeyContainer;
end;

function TCertificate.Get_SerialNumber: WideString;
begin
Result := DefaultInterface.SerialNumber;
end;

function TCertificate.Get_ValidFrom: TDateTime;
begin
Result := DefaultInterface.ValidFrom;
end;

function TCertificate.Get_ValidTo: TDateTime;
begin
Result := DefaultInterface.ValidTo;
end;

function TCertificate.Get_KeyUsage: KEY_USAGE_TYPE;
begin
Result := DefaultInterface.KeyUsage;
end;

function TCertificate.SignMessage(const msg: WideString; opt: OPTION): WideString;
begin
Result := DefaultInterface.SignMessage(msg, opt);
end;

{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
constructor TCertificateProperties.Create(AServer: TCertificate);
begin
inherited Create;
FServer := AServer;
end;

function TCertificateProperties.GetDefaultInterface: ICertificate;
begin
Result := FServer.DefaultInterface;
end;

function TCertificateProperties.Get_CommonName: WideString;
begin
Result := DefaultInterface.CommonName;
end;

function TCertificateProperties.Get_Subject: WideString;
begin
Result := DefaultInterface.Subject;
end;

function TCertificateProperties.Get_Issuer: WideString;
begin
Result := DefaultInterface.Issuer;
end;

function TCertificateProperties.Get_CSP: WideString;
begin
Result := DefaultInterface.CSP;
end;

function TCertificateProperties.Get_KeyContainer: WideString;
begin
Result := DefaultInterface.KeyContainer;
end;

function TCertificateProperties.Get_SerialNumber: WideString;
begin
Result := DefaultInterface.SerialNumber;
end;

function TCertificateProperties.Get_ValidFrom: TDateTime;
begin
Result := DefaultInterface.ValidFrom;
end;

function TCertificateProperties.Get_ValidTo: TDateTime;
begin
Result := DefaultInterface.ValidTo;
end;

function TCertificateProperties.Get_KeyUsage: KEY_USAGE_TYPE;
begin
Result := DefaultInterface.KeyUsage;
end;

{$ENDIF}

class function CoCertificates.Create: ICertificates;
begin
Result := CreateComObject(CLASS_Certificates) as ICertificates;
end;

class function CoCertificates.CreateRemote(const MachineName: string): ICertificates;
begin
Result := CreateRemoteComObject(MachineName, CLASS_Certificates) as ICertificates;
end;

procedure TCertificates.InitServerData;
const
CServerData: TServerData = (
ClassID: '{66F50F46-70A0-4A05-BD5E-FBCC0F9641EC}';
IntfIID: '{51C9E94B-FB8B-47A4-ABE4-FE91806DC7C7}';
EventIID: '';
LicenseKey: nil;
Version: 500);
begin
ServerData := @CServerData;
end;

procedure TCertificates.Connect;
var
punk: IUnknown;
begin
if FIntf = nil then
begin
punk := GetServer;
Fintf:= punk as ICertificates;
end;
end;

procedure TCertificates.ConnectTo(svrIntf: ICertificates);
begin
Disconnect;
FIntf := svrIntf;
end;

procedure TCertificates.DisConnect;
begin
if Fintf <> nil then
begin
FIntf := nil;
end;
end;

function TCertificates.GetDefaultInterface: ICertificates;
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 TCertificates.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
FProps := TCertificatesProperties.Create(Self);
{$ENDIF}
end;

destructor TCertificates.Destroy;
begin
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
FProps.Free;
{$ENDIF}
inherited Destroy;
end;

{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
function TCertificates.GetServerProperties: TCertificatesProperties;
begin
Result := FProps;
end;
{$ENDIF}

function TCertificates.Get__NewEnum(out pVal: IUnknown): HResult;
begin
Result := DefaultInterface.Get__NewEnum(pVal);
end;

function TCertificates.Get_Item(idx: Integer; out pVal: OleVariant): HResult;
begin
Result := DefaultInterface.Get_Item(idx, pVal);
end;

function TCertificates.Get_Count(out pVal: Integer): HResult;
begin
Result := DefaultInterface.Get_Count(pVal);
end;

function TCertificates.Add(const cert: IUnknown): HResult;
begin
Result := DefaultInterface.Add(cert);
end;

function TCertificates.Remove(idx: SYSINT): HResult;
begin
Result := DefaultInterface.Remove(idx);
end;

function TCertificates.EncryptMessage(const msg: WideString; opt: OPTION): WideString;
begin
Result := DefaultInterface.EncryptMessage(msg, opt);
end;

{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
constructor TCertificatesProperties.Create(AServer: TCertificates);
begin
inherited Create;
FServer := AServer;
end;

function TCertificatesProperties.GetDefaultInterface: ICertificates;
begin
Result := FServer.DefaultInterface;
end;

function TCertificatesProperties.Get__NewEnum(out pVal: IUnknown): HResult;
begin
Result := DefaultInterface.Get__NewEnum(pVal);
end;

function TCertificatesProperties.Get_Item(idx: Integer; out pVal: OleVariant): HResult;
begin
Result := DefaultInterface.Get_Item(idx, pVal);
end;

function TCertificatesProperties.Get_Count(out pVal: Integer): HResult;
begin
Result := DefaultInterface.Get_Count(pVal);
end;

{$ENDIF}

class function CoCertFilter.Create: ICertFilter;
begin
Result := CreateComObject(CLASS_CertFilter) as ICertFilter;
end;

class function CoCertFilter.CreateRemote(const MachineName: string): ICertFilter;
begin
Result := CreateRemoteComObject(MachineName, CLASS_CertFilter) as ICertFilter;
end;

procedure TCertFilter.InitServerData;
const
CServerData: TServerData = (
ClassID: '{BE3EB81F-5C69-419A-A4AA-856A2E30A61F}';
IntfIID: '{814C8B22-2F2D-4E1A-8835-F1A3DD45C46A}';
EventIID: '';
LicenseKey: nil;
Version: 500);
begin
ServerData := @CServerData;
end;

procedure TCertFilter.Connect;
var
punk: IUnknown;
begin
if FIntf = nil then
begin
punk := GetServer;
Fintf:= punk as ICertFilter;
end;
end;

procedure TCertFilter.ConnectTo(svrIntf: ICertFilter);
begin
Disconnect;
FIntf := svrIntf;
end;

procedure TCertFilter.DisConnect;
begin
if Fintf <> nil then
begin
FIntf := nil;
end;
end;

function TCertFilter.GetDefaultInterface: ICertFilter;
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 TCertFilter.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
FProps := TCertFilterProperties.Create(Self);
{$ENDIF}
end;

destructor TCertFilter.Destroy;
begin
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
FProps.Free;
{$ENDIF}
inherited Destroy;
end;

{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
function TCertFilter.GetServerProperties: TCertFilterProperties;
begin
Result := FProps;
end;
{$ENDIF}

function TCertFilter.Get_Subject: WideString;
begin
Result := DefaultInterface.Subject;
end;

procedure TCertFilter.Set_Subject(const pVal: WideString);
{ Warning: The property Subject has a setter and a getter whose
types do not match. Delphi was unable to generate a property of
this sort and so is using a Variant as a passthrough. }
var
InterfaceVariant: OleVariant;
begin
InterfaceVariant := DefaultInterface;
InterfaceVariant.Subject := pVal;
end;

function TCertFilter.Get_Issuer: WideString;
begin
Result := DefaultInterface.Issuer;
end;

procedure TCertFilter.Set_Issuer(const pVal: WideString);
{ Warning: The property Issuer has a setter and a getter whose
types do not match. Delphi was unable to generate a property of
this sort and so is using a Variant as a passthrough. }
var
InterfaceVariant: OleVariant;
begin
InterfaceVariant := DefaultInterface;
InterfaceVariant.Issuer := pVal;
end;

function TCertFilter.Get_SerialNumber: WideString;
begin
Result := DefaultInterface.SerialNumber;
end;

procedure TCertFilter.Set_SerialNumber(const pVal: WideString);
{ Warning: The property SerialNumber has a setter and a getter whose
types do not match. Delphi was unable to generate a property of
this sort and so is using a Variant as a passthrough. }
var
InterfaceVariant: OleVariant;
begin
InterfaceVariant := DefaultInterface;
InterfaceVariant.SerialNumber := pVal;
end;

function TCertFilter.Get_CSP: WideString;
begin
Result := DefaultInterface.CSP;
end;

procedure TCertFilter.Set_CSP(const pVal: WideString);
{ Warning: The property CSP has a setter and a getter whose
types do not match. Delphi was unable to generate a property of
this sort and so is using a Variant as a passthrough. }
var
InterfaceVariant: OleVariant;
begin
InterfaceVariant := DefaultInterface;
InterfaceVariant.CSP := pVal;
end;

procedure TCertFilter.Clear;
begin
DefaultInterface.Clear;
end;

{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
constructor TCertFilterProperties.Create(AServer: TCertFilter);
begin
inherited Create;
FServer := AServer;
end;

function TCertFilterProperties.GetDefaultInterface: ICertFilter;
begin
Result := FServer.DefaultInterface;
end;

function TCertFilterProperties.Get_Subject: WideString;
begin
Result := DefaultInterface.Subject;
end;

procedure TCertFilterProperties.Set_Subject(const pVal: WideString);
{ Warning: The property Subject has a setter and a getter whose
types do not match. Delphi was unable to generate a property of
this sort and so is using a Variant as a passthrough. }
var
InterfaceVariant: OleVariant;
begin
InterfaceVariant := DefaultInterface;
InterfaceVariant.Subject := pVal;
end;

function TCertFilterProperties.Get_Issuer: WideString;
begin
Result := DefaultInterface.Issuer;
end;

procedure TCertFilterProperties.Set_Issuer(const pVal: WideString);
{ Warning: The property Issuer has a setter and a getter whose
types do not match. Delphi was unable to generate a property of
this sort and so is using a Variant as a passthrough. }
var
InterfaceVariant: OleVariant;
begin
InterfaceVariant := DefaultInterface;
InterfaceVariant.Issuer := pVal;
end;

function TCertFilterProperties.Get_SerialNumber: WideString;
begin
Result := DefaultInterface.SerialNumber;
end;

procedure TCertFilterProperties.Set_SerialNumber(const pVal: WideString);
{ Warning: The property SerialNumber has a setter and a getter whose
types do not match. Delphi was unable to generate a property of
this sort and so is using a Variant as a passthrough. }
var
InterfaceVariant: OleVariant;
begin
InterfaceVariant := DefaultInterface;
InterfaceVariant.SerialNumber := pVal;
end;

function TCertFilterProperties.Get_CSP: WideString;
begin
Result := DefaultInterface.CSP;
end;

procedure TCertFilterProperties.Set_CSP(const pVal: WideString);
{ Warning: The property CSP has a setter and a getter whose
types do not match. Delphi was unable to generate a property of
this sort and so is using a Variant as a passthrough. }
var
InterfaceVariant: OleVariant;
begin
InterfaceVariant := DefaultInterface;
InterfaceVariant.CSP := pVal;
end;

{$ENDIF}

procedure Register;
begin
RegisterComponents(dtlServerPage, [TiTrusPTA, TCertificate, TCertificates, TCertFilter]);
end;

end.


但当我进行如下操作时,老出错。请各位大虾帮看看:

procedure TForm1.Button1Click(Sender: TObject);
var
Item: OleVariant;
iCert: iCertificate;
tCert, iCerts: iCertificates;
pta: TiTrusPTA;
begin
pta := TiTrusPTA.Create(Application);
iCerts := PTA.MyCertificates ;

iCerts.Get_Item(1, Item);
iCert:=IUnKnown(Item) as iCertificate;

tCert:=createComObject(CLASS_Certificates) as ICertificates;
tCert.Add(iCert);
memo1.lines.add(tCert.EncryptMessage('aaaaa',4));
end;
 
主题:VC与Delphi之间动态链接库互相调用

内容:


Delphi 调用VC的DLL


VC中DLL声名格式:

Extern “C” void __declspec(dllexport) __stdcall ShowMess(HWND hwnd, char* mess);

输出格式为:_ShowMess@8,“8”为函数参数字节数

为了避免名称分裂,可采用以下方法解决:

1.声明中不加__stdcall,采用VC默认格式__cdecl,但在Delphi中要注明调用格式为cdecl。

2.在VC工程中添加def文件,如:

LIBRARY

EXPORTS

ShowMess @1

则DLL中输出函数名称不分裂。


Delphi中调用格式:

Procedure ShowMess (h:HWND; mess:PChar); Stdcall;{Cdecl;} external LibName;

如无Stdcall或Cdecl声名,Delphi默认Register(FastCall)调用格式。


注意Delphi与VC的对齐格式不同,在VC中定义结构时要用以下格式:

#pragma pack(4)

//结构定义

#pragma pack()


常用工具:

TDump.exe-Delphi 4 和 C++ Builder 3 提供

Impdef.exe 和 Implib.exe - C++ Builder 3提供

DumpBin.exe-VC5.0提供

Lib.exe-VC5.0提供


VC调用Delphi的DLL


Delphi中的声名格式:

Function ShowDialog( hMainWnd:THandle; Msg:PChar ):integer; stdcall;

输出到Dll文件中时,名称不分裂。


VC中的调用格式:

extern "C" __declspec(dllimport) int __stdcall ShowDialog( HWND hwnd,char* Msg );

.如带有__stdcall,则要求Lib文件中对应函数名称分裂,可有以下步骤生成Lib文件:

.用Impdef.exe生成def文件,格式为:Impdef def文件名 dll文件名

.手工调制def文件参数,如ShowDialog改为ShowDialog@8

.用Lib.exe生成lib文件,格式为:Lib /def:def文件名

.如声名中无__stdcall,默认调用格式仍为stdcall,但不要求名称分裂,用以下批处理文件MkLib.bat可生成Lib文件:

@echo off

if %1.==. goto error

impdef %1.def %1.dll

lib /def:%1.def

goto end

:error

echo Usage: MkLib DllName

echo Note: Don't add extension ".dll" to parameter "DllName"

:end
 
在DELPHI中:
interface
function Test(v1, v2: PChar): Integer; stdcall;

implementation
function Test; external 'Test.Dll' name 'Test';

这样写就可以调用了,至于用 VC 写 DLL ,只要用 Wizard 生成一个框架,把函数加入
就可以了。

在VC中
Reboot (2000-12-20 19:35:00)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
__declspec(dllexport) int max_ab(int,int);
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
__declspec(dllexport) int max_ab(int a, int b)
{
return a>b?a:b;
}

 
基础不好,看得我头大。老大们,帮我解决上面问题先,急用啊!!
 
在DELPHI里可以直接打开.tlb文件,你可以在里面看到相应的接口,然后你在工程文件引用你
在上面列出的文件,直接使用里面的COCLASS的类就可以了,可以调用方法,使用属性等等,跟
用普通的DELPHI类没什么两样,上面是接口文件它会根据COM的规范去直接调用相应的实现的
 
可我就是这么做的,但总是抱错,相同的语法VB VC++都没问题。
 
问题解决。
 
后退
顶部