interface写法 ( 积分: 50 )

  • 主题发起人 主题发起人 pascal
  • 开始时间 开始时间
P

pascal

Unregistered / Unconfirmed
GUEST, unregistred user!
delphi中:
type
IPorte = interface
['{24F71F58-B71A-4430-86E6-6A4A183D7579}']
function Start(Device:byte) : boolean ;
procedure Shutdown();
function OpenDoor(Addr:byte) : boolean ;
function CloseDoor(Addr:byte) : boolean ;
function GetStatus(Addr:byte;var Status:word) : boolean ;
function GetCount(Addr:byte;
var Count:word) : boolean ;
function Reset(Addr:byte) : boolean ;
end;
翻译成c++:
typedef
__interface INTERFACE_UUID
["{3F969F98-1CC6-443F-9E1D-62AD08933925}"]
IPorte : public IInterface
{
virtual BOOL Start(unsigned char Device);
virtual void Shutdown();
virtual BOOL OpenDoor(unsigned char Addr);
virtual BOOL CloseDoor(unsigned char Addr);
virtual BOOL GetStatusGetStatus(unsigned char Addr,unsigned int *Status);
virtual BOOL GetCount(unsigned char Addr,unsigned int *Count);
virtual BOOL Reset(unsigned char Addr);
}
不对,该怎么写?
 
delphi中:
type
IPorte = interface
['{24F71F58-B71A-4430-86E6-6A4A183D7579}']
function Start(Device:byte) : boolean ;
procedure Shutdown();
function OpenDoor(Addr:byte) : boolean ;
function CloseDoor(Addr:byte) : boolean ;
function GetStatus(Addr:byte;var Status:word) : boolean ;
function GetCount(Addr:byte;
var Count:word) : boolean ;
function Reset(Addr:byte) : boolean ;
end;
翻译成c++:
typedef
__interface INTERFACE_UUID
["{3F969F98-1CC6-443F-9E1D-62AD08933925}"]
IPorte : public IInterface
{
virtual BOOL Start(unsigned char Device);
virtual void Shutdown();
virtual BOOL OpenDoor(unsigned char Addr);
virtual BOOL CloseDoor(unsigned char Addr);
virtual BOOL GetStatusGetStatus(unsigned char Addr,unsigned int *Status);
virtual BOOL GetCount(unsigned char Addr,unsigned int *Count);
virtual BOOL Reset(unsigned char Addr);
}
不对,该怎么写?
 
解决了,用BCB的COM向导.
新问题啊:我是写在DLL中的,如何输出接口啊:
extern "C"
XPORT_TYPE __stdcall IPorteCtl *CreatePorte;
不认啊
 
IPorte = interface
['{24F71F58-B71A-4430-86E6-6A4A183D7579}']
function GetStatus(Addr:byte;var Status:word) : boolean ;
function GetCount(Addr:byte;
var Count:word) : boolean ;
function Reset(Addr:byte) : boolean ;
end;

TPorte = class(TObject, IPorte)
function GetStatus(Addr:byte;var Status:word) : boolean ;
function GetCount(Addr:byte;
var Count:word) : boolean ;
function Reset(Addr:byte) : boolean ;
end;
翻译成c++:
__interface INTERFACE_UUID("{1DCCA889-3748-4FDA-8D4D-142BACC3BCF2}")
IPorte : public IInterface
{
public:
virtual bool __stdcall GetStatus(unsigned char Addr, unsigned int *Status);
virtual bool __stdcall GetCount(unsigned char Addr, unsigned int *Count);
virtual bool __stdcall Reset(unsigned char Addr);
};
class CPorte : public IPorte //这里不对的,多继承怎么写?public TObject, public IPorte 不对
{
CPorte();
~CPorte();
bool __stdcall GetStatus(unsigned char Addr, unsigned int *Status);
bool __stdcall GetCount(unsigned char Addr, unsigned int *Count);
bool __stdcall Reset(unsigned char Addr);
}
通过;以下未通过,请帮忙看看:
CPorte::CPorte()
{ //在这里提示共四个错: can't create instance of abstract class CPorte.
//class 'CPorte' is abstract because of '__stdcall IUnkown::Addref() = 0'
//type 'CPorte' may not be defined here
//constructor cannot have a return type specification
}
CPorte::~CPorte()
{
}
 
这句也没会写:
function CreatePorte : IPorte;
export;
stdcall;
翻译成c++:
#define XPORT_TYPE __declspec(dllexport)
extern "C"
XPORT_TYPE __stdcall IPorte *CreatePorte();//不正确,请教
 
终于完全解决:
头文件:
#include <system.hpp>
typedef
__interface INTERFACE_UUID(&quot;{1DCCA889-3748-4FDA-8D4D-142BACC3BCF2}&quot;)
_IPorte : public IInterface
{
public:
virtual bool Start(unsigned char Device) = 0;
virtual void Shutdown(void) = 0;
virtual bool Open(unsigned char Addr) = 0;
virtual bool Close(unsigned char Addr)= 0;
virtual bool Status(unsigned char Addr, unsigned int *Status) = 0;
virtual bool Get(unsigned char Addr, unsigned int *Count) = 0;
virtual bool Reset(unsigned char Addr) = 0;
} IPorte;
extern &quot;C&quot;
XPORT_TYPE IPorte *CreatePorte();
/////////////////////////////////////////////////////////////////////
cpp文件
typedef
class _CPorte : public TObject, public IPorte
{
private:
int PassCount[15];
bool commDialog(unsigned char Addr,unsigned char Cmd,int *Value);
public:
CPorte(){};
virtual HRESULT __stdcall QueryInterface(const GUID&amp;
IID, void **Obj)
{
return 0;
//IInterface::QueryInterface(IID, Obj);
}
virtual ULONG __stdcall AddRef()
{
return 0;
//IInterface::AddRef();
}
virtual ULONG __stdcall Release()
{
return 0;
//IInterface::Release();
}
virtual bool Start(unsigned char Device)
{
return InitComm(Device);
}
virtual void Shutdown(void)
{
CloseComm();
}
virtual bool Open(unsigned char Addr)
{
return OpenDoor(Addr);
}
virtual bool Close(unsigned char Addr)
{
return CloseDoor(Addr);
}
virtual bool Status(unsigned char Addr, unsigned int *Status)
{
return GetStatus(Addr, Status);
}
virtual bool Get(unsigned char Addr, unsigned int *Count)
{
return GetCount(Addr, Count);
}
virtual bool Reset(unsigned char Addr)
{
return ResetCount(Addr);
}
} CPorte;
IPorte *PorteHandle = NULL;
extern &quot;C&quot;
XPORT_TYPE IPorte *CreatePorte()
{
if (PorteHandle == NULL) PorteHandle = new CPorte;
return PorteHandle;
}
 
那我接分! [:D]
你这种学习方法值得学习和赞扬,不依赖别人!
 
ak_2005:你口真乖,就给了你吧
 
后退
顶部