无效指针问题
我用ado连接数据库,做了两个子函数,两个函数里面都定义了RecordSet对象,分别连接同一数据库文件下的不同表,一起先后调用时就会出现错误,但只是单独调用时就没问题,错误都为无效指针,请问这是为什么
PROGRAM TEST
INTERFACE
SUBROUTINE DataInput2(t,a,b) !申明结点坐标数据输入函数
!DEC$ATTRIBUTES C,ALIAS:'_DataInput2'::DataInput2
INTEGER(4)::t
real(4)::a[reference]
real(4)::b[reference]
END SUBROUTINE
SUBROUTINE DataInput1(k,a,b,c,d) !申明单元结点数据输入函数
!DEC$ATTRIBUTES C,ALIAS:'_DataInput1'::DataInput1
INTEGER(4)::k
INTEGER(4)::a[reference]
INTEGER(4)::b[reference]
INTEGER(4)::c[reference]
INTEGER(4)::d[reference]
END SUBROUTINE
END INTERFACE
real a,b
integer c,d,e,f
call DataInput1(3,c,d,e,f)
call DataInput2(4,a,b)
write(*,*) a,b,c,d,e,f
end
#import "c:\Program Files\Common Files\System\ADO\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")
#include <stdio.h>
#include <icrsint.h>
class CCustomRs : public CADORecordBinding
{
BEGIN_ADO_BINDING(CCustomRs)
ADO_NUMERIC_ENTRY(1,adInteger,a[0],1,0,m_ul_fnameStatus1,true)
ADO_NUMERIC_ENTRY(2,adInteger,a[1],1,0,m_ul_fnameStatus2,true)
ADO_NUMERIC_ENTRY(3,adInteger,a[2],1,0,m_ul_fnameStatus3,true)
ADO_NUMERIC_ENTRY(4,adInteger,a[3],1,0,m_ul_fnameStatus3,true)
END_ADO_BINDING()
public:
int a[4];
ULONG m_ul_fnameStatus1;
ULONG m_ul_fnameStatus2;
ULONG m_ul_fnameStatus3;
ULONG m_ul_fnameStatus4;
};
inline void TESTHR(HRESULT _hr)
{ if FAILED(_hr) _com_issue_error(_hr); }
extern"C"void DataInput1(int k,int& a,int& b,int& c,int& d)
{
_COM_SMARTPTR_TYPEDEF(IADORecordBinding, __uuidof(IADORecordBinding));
::CoInitialize(NULL);
try
{
_RecordsetPtr pRs("ADODB.Recordset");
CCustomRs rs;
IADORecordBindingPtr picRs(pRs);
pRs->Open("SELECT * FROM 单元结点",
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=二维有压渗流数据.mdb",
adOpenStatic, adLockOptimistic, adCmdText);
TESTHR(picRs->BindToRecordset(&rs));
pRs->AbsolutePosition=(PositionEnum)k;
a=rs.a[0];
b=rs.a[1];
c=rs.a[2];
d=rs.a[3];
pRs->Close();
}
catch (_com_error &e)
{
printf("Error:\n");
printf("Code = %08lx\n", e.Error());
printf("Meaning = %s\n", e.ErrorMessage());
printf("Source = %s\n", (LPCSTR) e.Source());
printf("Description = %s\n", (LPCSTR) e.Description());
}
::CoUninitialize();
}
#import "c:\Program Files\Common Files\System\ADO\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")
#include <stdio.h>
#include <icrsint.h>
class CCustomRs : public CADORecordBinding
{
BEGIN_ADO_BINDING(CCustomRs)
ADO_NUMERIC_ENTRY(2,adSingle,a[1],0.00001,0,m_ul_fnameStatus2,true)
ADO_NUMERIC_ENTRY(3,adSingle,a[2],0.00001,0,m_ul_fnameStatus3,true)
END_ADO_BINDING()
public:
float a[3];
ULONG m_ul_fnameStatus2;
ULONG m_ul_fnameStatus3;
};
inline void TESTHR(HRESULT _hr)
{ if FAILED(_hr) _com_issue_error(_hr); }
extern"C"void DataInput2(int t,float& b,float& c)
{
_COM_SMARTPTR_TYPEDEF(IADORecordBinding, __uuidof(IADORecordBinding));
::CoInitialize(NULL);
try
{
_RecordsetPtr pRs("ADODB.Recordset");
CCustomRs rs;
int i;
IADORecordBindingPtr picRs(pRs);
pRs->Open("SELECT * FROM 坐标",
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=二维有压渗流数据.mdb",
adOpenStatic, adLockOptimistic, adCmdText);
TESTHR(picRs->BindToRecordset(&rs));
pRs->AbsolutePosition=(PositionEnum)t;
b=rs.a[1];
c=rs.a[2];
}
catch (_com_error &e) {
printf("Error:\n");
printf("Code = %08lx\n", e.Error());
printf("Meaning = %s\n", e.ErrorMessage());
printf("Source = %s\n", (LPCSTR) e.Source());
printf("Description = %s\n", (LPCSTR) e.Description());
}
::CoUninitialize();
}