C++通过dll查询数据库,接口已经有了,怎么查询?
答案:1 悬赏:0
解决时间 2021-02-13 06:10
- 提问者网友:星空下的寂寞
- 2021-02-12 06:52
C++通过dll查询数据库,接口已经有了,怎么查询?
最佳答案
- 二级知识专家网友:输掉的尊严
- 2021-02-12 07:29
调用dll有动态调用和静态调用两种方法,我看你的代码基本上是动态调用,那么我就跟你说一下动态调用的方法吧.下面以FanSelect函数为例.
在你的原文件中,按下面的顺序进行:
1.首先要包含必要的头文件,这里要记得包含dll自带的那个头文件.
#include <iostream>
#include <stdio.h>
#include <windows.h>
#include "VSQS.h" //假如是叫这个名字
using namespace std;
2.定义函数指针,这里要加上__stdcll,请注意.
typedef void (__stdcll *FanSelect)(
void *pSeriesNames,//系列名称 YLDStr * (typedef struct{char Data[255];} YLDStr;)
const int pSeriesNameCount,//系列名称个数,-1时表示全部选择
void *pSubSeriesNames,//系列名称 YLDStr * (typedef struct{char Data[255];} YLDStr;)
const int pSubSeriesNameCount,//子系列名称个数,-1时表示全部选择
const double &pFlow, //风量
const int &pFlowUnitType, //风量单位类型 0-m^3/h 1-m^3/s 2-l/s 3-cfm
const double &pPres, //风压
const int &pPresUnitType, //风压单位类型 0-Pa 1-mmH2O 2-kgf/cm^2 3-inH2O
const int &pPresType, //风压类型 0-全压 1-静压
const int &pOutFanType,//出风方式 0-管道出风 1-自由出风
const double &pAirDensity,//空气密度
const double &pMotorSafeCoff,//电机容量安全系数(%)
const bool &pUserSetMotorSafeCoff,//用户设定了电机容量安全系数
double &rFlow_STDUnit,//标准单位下的风量
fun_AddResult pAddResult//函数指针,用于回传数据
);
3.使用函数.代码如下:
int main(int argc, char *argv[])
{
HINSTANCE hDll; //DLL句柄
FanSelect Select; //函数指针
hDll = LoadLibrary("VSQS.dll");//要注意路径,可以写上dll的详细路径
if (hDll != NULL)
{
cout<<"DLL is ok\n";
Select = (FanSelect)GetProcAddress(hDll, "FanSelect");
if (Select != NULL)
{
cout<<"Function is ok\n";
//参入如何传进去?参数直接定义相应的局部变量,带入函数即可.拿第一个参数YLDStr为例
YLDStr test;
test.Data[0] = 'a';
test.Data[1] = '\0';
FanSelect( &test, -1, 0, -1, 6000, 0, 800, 0, 0, 0, 1.195, 10, 0, 6000, HD);
cout<<"\nFanSelect finished.\n";
}
FreeLibrary(hDll);
}
getchar();
return 0;
}
这样就可以查询了,查询结果会放到pAddResult指针中,你需要事先给这个指针足够的空间.
在你的原文件中,按下面的顺序进行:
1.首先要包含必要的头文件,这里要记得包含dll自带的那个头文件.
#include <iostream>
#include <stdio.h>
#include <windows.h>
#include "VSQS.h" //假如是叫这个名字
using namespace std;
2.定义函数指针,这里要加上__stdcll,请注意.
typedef void (__stdcll *FanSelect)(
void *pSeriesNames,//系列名称 YLDStr * (typedef struct{char Data[255];} YLDStr;)
const int pSeriesNameCount,//系列名称个数,-1时表示全部选择
void *pSubSeriesNames,//系列名称 YLDStr * (typedef struct{char Data[255];} YLDStr;)
const int pSubSeriesNameCount,//子系列名称个数,-1时表示全部选择
const double &pFlow, //风量
const int &pFlowUnitType, //风量单位类型 0-m^3/h 1-m^3/s 2-l/s 3-cfm
const double &pPres, //风压
const int &pPresUnitType, //风压单位类型 0-Pa 1-mmH2O 2-kgf/cm^2 3-inH2O
const int &pPresType, //风压类型 0-全压 1-静压
const int &pOutFanType,//出风方式 0-管道出风 1-自由出风
const double &pAirDensity,//空气密度
const double &pMotorSafeCoff,//电机容量安全系数(%)
const bool &pUserSetMotorSafeCoff,//用户设定了电机容量安全系数
double &rFlow_STDUnit,//标准单位下的风量
fun_AddResult pAddResult//函数指针,用于回传数据
);
3.使用函数.代码如下:
int main(int argc, char *argv[])
{
HINSTANCE hDll; //DLL句柄
FanSelect Select; //函数指针
hDll = LoadLibrary("VSQS.dll");//要注意路径,可以写上dll的详细路径
if (hDll != NULL)
{
cout<<"DLL is ok\n";
Select = (FanSelect)GetProcAddress(hDll, "FanSelect");
if (Select != NULL)
{
cout<<"Function is ok\n";
//参入如何传进去?参数直接定义相应的局部变量,带入函数即可.拿第一个参数YLDStr为例
YLDStr test;
test.Data[0] = 'a';
test.Data[1] = '\0';
FanSelect( &test, -1, 0, -1, 6000, 0, 800, 0, 0, 0, 1.195, 10, 0, 6000, HD);
cout<<"\nFanSelect finished.\n";
}
FreeLibrary(hDll);
}
getchar();
return 0;
}
这样就可以查询了,查询结果会放到pAddResult指针中,你需要事先给这个指针足够的空间.
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯
• 手机登qq时,显示手机磁盘不足,清理后重新登 |
• 刺客的套装怎么选啊? |