在Application中调用CreateOleObject成功,但是同样的代码封装到Dll中确失败,望高手指教。内详!(100分)

  • 主题发起人 主题发起人 syncpk99
  • 开始时间 开始时间
S

syncpk99

Unregistered / Unconfirmed
GUEST, unregistred user!
void __fastcall TForm1::btnokClick(TObject *Sender)
{
typedef struct
{
unsigned char name[31];
unsigned char sex;
unsigned char people;
unsigned char address[71];
unsigned char id[19];
unsigned char office[31];
unsigned char valid_year[11];
short int birthday[3];
short int startday[3];
}CIPS_V2ID;
typedef struct
{
void* pstruV2ID;
unsigned char* pstrHead;
int HeadSize;
}V2IDINFO;
Variant VCIPS_1200B1;
unsigned char* pt_pch_HeadBuffer = NULL;
int i;
long pt_l_PhotoSize;
long pt_l_HeadSize;
long ScanType;
VCIPS_1200B1 = CreateOleObject("CIPS_1200BLib.CIPS_1200B");

i = VCIPS_1200B1.OleFunction("SystemInitial");
if (i != CIPSIDENTIFY_SUCCESS)
{
ShowMessage(fnShowErrMsg(i));
return;
}
VCIPS_1200B1.OlePropertySet("SelectWorkMode",6);
VCIPS_1200B1.OleFunction("GetScanSize",&pt_l_PhotoSize,&pt_l_HeadSize);
VCIPS_1200B1.OleFunction("GetScanType",&ScanType);
CIPS_V2ID v2_id;
V2IDINFO pstruV2IDInfo;
pt_pch_HeadBuffer = new unsigned char [pt_l_HeadSize];
pstruV2IDInfo.HeadSize = pt_l_HeadSize;
pstruV2IDInfo.pstrHead = pt_pch_HeadBuffer;
pstruV2IDInfo.pstruV2ID = (void*)&v2_id;
pt_l_PhotoSize=0;
long pstruIDCardParameters = (long)&pstruV2IDInfo;
i = VCIPS_1200B1.OleFunction("IDCardIdentify",pstruIDCardParameters);
if (i != CIPSIDENTIFY_SUCCESS)
{
delete [] pt_pch_HeadBuffer;
ShowMessage(fnShowErrMsg(i));
return;
}
delete [] pt_pch_HeadBuffer;
VCIPS_1200B1 = Unassigned;
}
如上的代码,我新创建一个project,在一个Button的Click事件中调用,都能够正常使用,但是如果我把这段代码放到一个Dll中包含的Form的Button的Click事件中调用时,VCIPS_1200B1.OleFunction("SystemInitial")就会产生指针错误,具体错误是 Access violation at address 02FD4AB7 in module 'discnt.dll'. Read of address 00000800.
请高手指教,是不是Project默认调用了什么函数,我的Dll没有调用啊?
谢谢!!
 
function CoInitialize(pvReserved: Pointer): HResult;
stdcall;
external 'ole32.dll' Name 'CoInitialize';
procedure CoUninitialize;
stdcall;
external 'ole32.dll' Name 'CoUninitialize';
CoInitialize(Nil);
CoUninitialize;
未初始化OLE
 
后退
顶部