- 积分
- 0
- 注册时间
- 2009-12-17
- 仿真币
-
- 最后登录
- 1970-1-1
|
该例是关于vc用ADO连接access数据库,然后一次返回四个值给fortran程序
我改了好久都不能编译通过,很可能是调用参数的错误 但是我不知道怎么改正
应该是k的问题,我用k来定位记录在数据库的位置,应该是值引用啊
fotran程序如下:
PROGRAM MAIN
IMPLICIT NONE
INTEGER:: E,F,G,H
INTEGER:: J
INTERFACE
SUBROUTINE datainput1(a,b,c,d,k)
!DEC$ATTRIBUTES STDCALL,ALIAS:'_datainput1@16'::datainput1
INTEGER(4)::k[value]
INTEGER(4)::a[reference]
INTEGER(4)::b[reference]
INTEGER(4)::c[reference]
INTEGER(4)::d[reference]
END SUBROUTINE
END INTERFACE
J=1
CALL datainput1(E,F,G,H,J)
WRITE(*,*)E,F,G,H
END PROGRAM
VC++程序如下:
#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_fnameStatus4,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 _stdcall datainput1(int& a,int& b,int& c,int& d,int k)
{
_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];
}
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();
}
附件为数据库文件 解压即可 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
×
|