VC++操作SQLserver动态库【含源码】
动态库使用Demo程序演示
#include <iostream>
#include <windows.h>
#include "sqlDataBase.h"
int main()
{
if (SQLInit() == S_OK)
{
std::cout << "数据库连接成功" << std::endl;
}
return false;
}

【SqlDataBase】库头文件(.h)
/*
* "Copyright (c) 2021 by Sinux,Inc,liumeng"
*/
#ifndef __SQLDATABASE_H__
#define __SQLDATABASE_H__
#ifdef SQLDATABASE_EXPORTS
#define SQLDATABASEOPT_API __declspec(dllexport)
#else
#define SQLDATABASEOPT_API __declspec(dllimport)
#pragma comment(lib,"SqlDataBase.lib")
#endif
#include <string>
/**
* SQL connect stringt
* Provider=SQLOLEDB;Data Source=127.0.0.1,1433;Initial Catalog=sa;User Id=sa;Password=1
* MS Access connect string
* Provider=Microsoft.Jet.OLEDB.4.0;Data Source=../../../data/db/Demo.mdb
*/
int SQLDATABASEOPT_API SQLInit(
const std::string& strDataSource = "Provider=SQLOLEDB;Data Source=127.0.0.1;Initial Catalog=sa;User Id=sa;Password=123456",
const std::string& strName = "",
const std::string& strPwd = ""
);
void SQLDATABASEOPT_API SQLDestroy();
/*
* 查询数据
* strSQL : SQL 语句
* strResult: 结果 xml形式
* 返回值 > 0执行成功,返回记录的条数,否则失败
*/
int SQLDATABASEOPT_API SQLQuery(const std::string& strSQL, std::string& strResult);
/*
* 删除数据
*/
bool SQLDATABASEOPT_API SQLDelete(const std::string& value);
/*
* 添加数据,需要输入id
*/
bool SQLDATABASEOPT_API SQLInsert(const const std::string& str);
/*
* 更新数据
*/
bool SQLDATABASEOPT_API SQLUpdate(const std::string& str);
#endif
【SqlDataBase】库源代码(.cpp)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <mmsystem.h>
#include <atlbase.h>
#import "C:/Program Files/Common Files/System/ado/msado15.dll" rename("EOF","EndOfFile")
#include "SqlDataBase.h"
#include <string>
#include <sstream>
using std::string;
using namespace ADODB;
/************************************************************************/
/* 互斥体对象声明 */
/************************************************************************/
class Mutex
{
public:
Mutex()
{
/**
* 初始化临界区对象
* 返回值>无
*/
::InitializeCriticalSection(&m_cs);
}
~Mutex()
{
/**
* 释放临界区对象
* 返回值>无
*/
::DeleteCriticalSection(&m_cs);
}
void Lock()
{
/**
* 进入临界截面
* 返回值>无
*/
::EnterCriticalSection(&m_cs);
}
void UnLock()
{
/**
* 离开临界截面
* 返回值>无
*/
::LeaveCriticalSection(&

最低0.47元/天 解锁文章
657

被折叠的 条评论
为什么被折叠?



