无效指针问题
我用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();
}
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();
}
...全文
相关推荐
NULL指针、零指针、野指针定义及区别
在实际编程过程中,建议使用现代编程语言提供的安全特性,如智能指针等,来管理和操作指针,以减少因指针管理不当导致的问题。
野指针问题
本文将详细探讨野指针的定义、产生的原因以及如何避免这些问题。#### 二、野指针定义野指针是指向不确定或无效内存区域的指针。
函数参数的传递问题(指针的指针)
栈内存指针作为函数返回值是非常危险的,因为返回后栈内存已经无效。2. **函数参数传递规则**: - 在C++中,函数参数传递默认是按值传递的,这意味着函数内部的参数副本不会影响到函数外部的原始变量。
C野指针处理
#### 五、返回指向栈内存的指针另一个需要注意的问题是:不要返回指向栈内存的指针或引用,因为栈内存在函数结束时会被释放。
C/C++指针经典资料大全
**指针安全** - 空指针:`NULL`或`nullptr`表示未初始化或无效的指针,避免空指针解引用是必要的。 - 野指针:未初始化或已释放内存后的指针,使用野指针可能导致未定义行为。


