Skip to content

读取数据库配置项 - GetDbConfigEx

函数简介

读取自定义的配置项,默认使用 SetConfig 接口配置的数据库,如果未配置则返回失败。

接口名称

GetDbConfigEx

DLL调用

cpp
long GetDbConfigEx(long ola, string key);

参数说明

参数名类型说明
ola长整数型OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。
key字符串配置项名,如"width"、"height"。

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
ola.SetDbConfigEx("height", "1080");
string val = ola.GetDbConfigEx("height");
csharp
using OLAPlug;

var ola = new OLAPlugServer();
ola.SetDbConfigEx("height", "1080");
string val = ola.GetDbConfigEx("height");
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
ola.SetDbConfigEx("height", "1080")
val = ola.GetDbConfigEx("height")
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();
ola.SetDbConfigEx("height", "1080");
String val = ola.GetDbConfigEx("height");
cpp
var ola = com("OlaPlug.OlaSoft")
ola.SetDbConfigEx("height", "1080");
var val = ola.GetDbConfigEx("height")
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
ola.SetDbConfigEx("height", "1080");
val = ola.GetDbConfigEx("height")
text
.局部变量 ola, OLAPlug
ola.创建 ()
ola.SetDbConfigEx("height", "1080")
val = ola.GetDbConfigEx(“height“)
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
ola.SetDbConfigEx("height", "1080");
var val = ola.GetDbConfigEx("height");
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
ola.SetDbConfigEx("height", "1080");
文本型 val = ola.GetDbConfigEx("height")
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
ola.SetDbConfigEx("height", "1080");
string val = ola.GetDbConfigEx("height");

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
SetDbConfigEx(instance, "height", "1080");
long valPtr = GetDbConfigEx(instance, "height");
if (valPtr != 0) {
    char val[512] = {0};
    GetStringFromPtr(valPtr, val, sizeof(val));
    FreeStringPtr(valPtr);
}
csharp
using System.Runtime.InteropServices;
using System.Text;

[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringFromPtr(long ptr, StringBuilder lpString, int size);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int FreeStringPtr(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringSize(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();

long instance = CreateCOLAPlugInterFace();
SetDbConfigEx(instance, "height", "1080");
long valPtr = GetDbConfigEx(instance, "height");
if (valPtr != 0) {
    StringBuilder val = new StringBuilder(GetStringSize(valPtr) + 1);
    GetStringFromPtr(valPtr, val, val.Capacity);
    FreeStringPtr(valPtr);
    string valStr = val.ToString();
}
python
from ctypes import CDLL, c_int, c_int64, create_string_buffer

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
SetDbConfigEx(instance, "height", "1080")
valPtr = GetDbConfigEx(instance, "height")
if valPtr:
    buf = create_string_buffer(512)
    ola.GetStringFromPtr(valPtr, buf, 512)
    ola.FreeStringPtr(valPtr)
    val = buf.value.decode("utf-8")

返回值

返回值说明
(返回值)字符串指针:对应配置项的值。DLL调用返回字符串指针地址,需要调用 FreeStringPtr 接口释放内存。

注意事项

项目说明
该函数用于读取用户自定义数据该函数用于读取用户自定义数据,如账号密码、软件默认配置等信息。