
C++通过dll查询数据库,接口已经有了,怎么查询? 100
//dll接口说明,有很多函数基本相同,给出一个例子,求大家帮忙,谢谢typedefvoid__stdcall(*fun_AddResult)(charpDataStr[...
//dll接口说明, 有很多函数基本相同, 给出一个例子, 求大家帮忙,谢谢
typedef void __stdcall (*fun_AddResult)(char pDataStr[10][255],double pDataDouble[100]);
extern "C" void __declspec(dllimport) __stdcall 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//函数指针,用于回传数据
);
//写了一部分程序, 可能问题很大,我 不是专业搞这个的
#include <iostream>
#include <stdio.h>
#include <windows.h>
using namespace std;
typedef void (*fun_AddResult)(char pDataStr[10][255],double pDataDouble[100]);
typedef void (*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//函数指针,用于回传数据
);
void GiveResult(char pDataStr[10][255],double pDataDouble[100])
{
cout<<"GiveResult is ok\n";
}
int main(int argc, char *argv[])
{
fun_AddResult HD;
HINSTANCE hDll; //DLL句柄
FanSelect Select; //函数指针
HD=GiveResult;
char pd[10][255];
double pda[100];
HD(pd,pda);
hDll = LoadLibrary("VSQS.dll");
if (hDll != NULL)
{
cout<<"DLL is ok\n";
Select = (FanSelect)GetProcAddress(hDll, "FanSelect");
if (Select != NULL)
{
cout<<"Function is ok\n";
//参入如何传进去?
FanSelect( 0, -1, 0, -1, 6000, 0, 800, 0, 0, 0, 1.195, 10, 0, 6000, HD);
cout<<"\nFanSelect finished.\n";
}
FreeLibrary(hDll);
}
getchar();
return 0;
} 展开
typedef void __stdcall (*fun_AddResult)(char pDataStr[10][255],double pDataDouble[100]);
extern "C" void __declspec(dllimport) __stdcall 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//函数指针,用于回传数据
);
//写了一部分程序, 可能问题很大,我 不是专业搞这个的
#include <iostream>
#include <stdio.h>
#include <windows.h>
using namespace std;
typedef void (*fun_AddResult)(char pDataStr[10][255],double pDataDouble[100]);
typedef void (*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//函数指针,用于回传数据
);
void GiveResult(char pDataStr[10][255],double pDataDouble[100])
{
cout<<"GiveResult is ok\n";
}
int main(int argc, char *argv[])
{
fun_AddResult HD;
HINSTANCE hDll; //DLL句柄
FanSelect Select; //函数指针
HD=GiveResult;
char pd[10][255];
double pda[100];
HD(pd,pda);
hDll = LoadLibrary("VSQS.dll");
if (hDll != NULL)
{
cout<<"DLL is ok\n";
Select = (FanSelect)GetProcAddress(hDll, "FanSelect");
if (Select != NULL)
{
cout<<"Function is ok\n";
//参入如何传进去?
FanSelect( 0, -1, 0, -1, 6000, 0, 800, 0, 0, 0, 1.195, 10, 0, 6000, HD);
cout<<"\nFanSelect finished.\n";
}
FreeLibrary(hDll);
}
getchar();
return 0;
} 展开
展开全部
调用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指针中,你需要事先给这个指针足够的空间.

2025-03-10 广告
批量创建广告,可以试用小鹿管家。小鹿管家是广告批量管理工具,支持快速多账户搭建计划、跨账户复制计划、智能盯盘、多账户报告聚合等提效功能,助力广告投放效率,监控广告投放效果,提升ROI。通过批量创建、智能提醒、BI报表等技术手段帮助广告运营团...
点击进入详情页
本回答由小鹿管家提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询