主题
获取最后一次错误字符串 - GetLastErrorString
函数简介
获取插件内部记录的最后一次错误描述字符串,通常在某个接口调用失败后配合 GetLastError 一起使用。
接口名称
GetLastErrorStringDLL调用
c
long GetLastErrorString();参数说明
此函数无参数。
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
std::string result = ola.GetLastErrorString();csharp
using OLAPlug;
var ola = new OLAPlugServer();
string result = ola.GetLastErrorString();python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
result = ola.GetLastErrorString()java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
String result = ola.GetLastErrorString();cpp
var ola = com("OlaPlug.OlaSoft")
var result = ola.GetLastErrorString()vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
result = ola.GetLastErrorString()text
.局部变量 ola, OLAPlug
ola.创建 ()
result = ola.GetLastErrorString()aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var result = ola.GetLastErrorString();text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
文本型 result = ola.GetLastErrorString()cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
std::string result = ola.GetLastErrorString();原生 DLL 调用
cpp
long ptr = GetLastErrorString(instance);
if (ptr != 0) {
char buffer[512] = {0};
GetStringFromPtr(ptr, buffer, sizeof(buffer));
FreeStringPtr(ptr);
}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 GetLastErrorString();
long ptr = GetLastErrorString(instance);
if (ptr != 0) {
StringBuilder sb = new StringBuilder(GetStringSize(ptr) + 1);
GetStringFromPtr(ptr, sb, sb.Capacity);
FreeStringPtr(ptr);
string result = sb.ToString();
}python
from ctypes import CDLL, c_int, c_int64, create_string_buffer
ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
ptr = ola.GetLastErrorString(instance)
if ptr:
buf = create_string_buffer(512)
ola.GetStringFromPtr(ptr, buf, 512)
ola.FreeStringPtr(ptr)
result = buf.value.decode("utf-8")返回值
| 返回值 | 说明 |
|---|---|
| (返回值) | 长整数型:成功返回错误字符串的指针地址,失败或无错误信息返回0。 |
注意事项
| 项目 | 说明 |
|---|---|
| 释放内存 | 返回的字符串指针需调用 FreeStringPtr 释放内存。 |
| 错误字符串仅表示"最后一次错误"的信息 | 错误字符串仅表示"最后一次错误"的信息,如中途调用了其他接口,错误信息可能被覆盖。 |
| 在接口调用失败后 | 建议在接口调用失败后,优先调用 GetLastError 获取错误码,再调用本接口获取错误描述。 |
