无效指针问题

langwhu 2011-01-09 07:09:12
我用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();
}
...全文
174 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
langwhu 2011-01-10
  • 打赏
  • 举报
回复
不行啊 大哥
WWWWA 2011-01-10
  • 打赏
  • 举报
回复
使用不同的名称试试
比如pRs1
langwhu 2011-01-09
  • 打赏
  • 举报
回复
不好意思 前几次大意了没给分,这次解决了一定给分

7,714

社区成员

发帖
与我相关
我的任务
社区描述
Microsoft Office Access是由微软发布的关系数据库管理系统。它结合了 MicrosoftJet Database Engine 和 图形用户界面两项特点。
社区管理员
  • Access
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧