Build
[Linker Error] Unresolved external 'TYbCommDevice::' referenced from E:\LOCKDLL\MAIN.OBJ
[Linker Error] Unresolved external '__fastcall TYbCommDevice::TYbCommDevice(Classes::TComponent *)' referenced from E:\LOCKDLL\MAIN.OBJ
[Linker Error] Unresolved external '__fastcall TYbCustomCommDevice::fSetPort(int)' referenced from E:\LOCKDLL\MAIN.OBJ
[Linker Error] Unresolved external '__fastcall TYbCustomCommDevice::fSetBaud(TYbCustomCommDevice::TBaudRate)' referenced from E:\LOCKDLL\MAIN.OBJ
[Linker Error] Unresolved external '__fastcall TYbCustomCommDevice::fSetParity(TYbCustomCommDevice::TParity)' referenced from E:\LOCKDLL\MAIN.OBJ
[Linker Error] Unresolved external '__fastcall TYbCustomCommDevice::fSetByteSize(int)' referenced from E:\LOCKDLL\MAIN.OBJ
[Linker Error] Unresolved external '__fastcall TYbCustomCommDevice::fSetStopBits(TYbCustomCommDevice::TStopBits)' referenced from E:\LOCKDLL\MAIN.OBJ
[Linker Error] Unresolved external '__fastcall TYbCustomCommDevice::fSetActive(bool)' referenced from E:\LOCKDLL\MAIN.OBJ
[Linker Error] Unresolved external '__fastcall TYbCustomCommDevice::fGetActive()' referenced from E:\LOCKDLL\MAIN.OBJ
//=============================================
不取消此选项时编译正常!
--------------------next---------------------
////////////////////////
// Unit2.h 文件的内容 //
////////////////////////
//---------------------------------------------------------------------------
#ifndef Unit2H
#define Unit2H
//---------------------------------------------------------------------------
#include
//---------------------------------------------------------------------------
#ifdef __cplusplus
extern "C" { //DLL 导出的接口函数从这里开始
#endif
//---------------------------------------------------------------------------
extern int __export WINAPI OpenComm(int iPortNo);
extern void __export WINAPI CloseComm(void);
//在此处添加其他 DLL 导出的函数
//---------------------------------------------------------------------------
#ifdef __cplusplus
} //extern "C" //DLL 导出的接口函数到这里结束
#endif
//---------------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------
//////////////////////////
// Unit2.cpp 文件的内容 //
//////////////////////////
//---------------------------------------------------------------------------
#pragma hdrstop
#include "Unit2.h"
#include "YbCommDevice.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
//---------------------------------------------------------------------------
class TMyDllEntry
{
public:
TMyDllEntry();
~TMyDllEntry();
int OpenComm(int iPortNo);
void CloseComm(void);
//在此处添加其他公用函数
__property TYbCommDevice *Comm = {read=_Comm}; //通过这个属性可以安全的访问_Comm私有成员变量
private:
TYbCommDevice *_Comm;
void __fastcall CommPackage(TObject *Sender, int NotifyType);
//在此处添加私有函数
};
//---------------------------------------------------------------------------
TMyDllEntry::TMyDllEntry()
{
_Comm = new TYbCommDevice(NULL); //分配内存 (DLL 文件装载时自动运行)
_Comm->OnPackage = CommPackage; //OnPackage 事件: CommPackage 成员函数
}
//---------------------------------------------------------------------------
TMyDllEntry::~TMyDllEntry()
{
_Comm->Active = false; //如果程序结束运行时未关闭串口,在这里关闭
delete _Comm; //在析构函数里释放内存 (当DLL文件结束运行时自动执行)
}
//---------------------------------------------------------------------------
int TMyDllEntry::OpenComm(int iPortNo)
{
int iErr = 0;
try
{
_Comm->PortNo = iPortNo;
_Comm->PackageType = cptFrameHeadTail;
_Comm->CommPort->Baud = 57600;
_Comm->Active = true;
}
catch(EComm32Error &e)
{
iErr = e.ErrorCode; //串口的错误号
}
catch(Exception &e)
{
iErr = -1; //其他错误
}
return iErr; //返回错误号 (没有错误=0)
}
//---------------------------------------------------------------------------
void TMyDllEntry::CloseComm(void)
{
_Comm->Active = false;
}
//---------------------------------------------------------------------------
void __fastcall TMyDllEntry::CommPackage(TObject *Sender, int NotifyType)
{
//在这里处理 OnPackage 事件
}
//---------------------------------------------------------------------------
TMyDllEntry MyDll; //使用全局变量,DLL 装载时自动调用构造函数,退出时运行析构函数
//---------------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------
#ifdef __cplusplus
extern "C" { //DLL 导出的接口函数从这里开始
#endif
//---------------------------------------------------------------------------
int __export WINAPI OpenComm(int iPortNo)
{
return MyDll.OpenComm(iPortNo); //打开串口,返回错误码,没有错误返回零
}
//---------------------------------------------------------------------------
void __export WINAPI CloseComm(void)
{
MyDll.CloseComm(); //关闭串口
}
//---------------------------------------------------------------------------
// 在此处添加其他 DLL 导出的函数
//---------------------------------------------------------------------------
#ifdef __cplusplus
} //extern "C" //DLL 导出的接口函数到这里结束
#endif
//---------------------------------------------------------------------------
--------------------next---------------------
阅读(1465) | 评论(0) | 转发(0) |