主题
计算文件MD5哈希值 - MD5File
函数简介
计算指定文件的MD5哈希值。
接口名称
MD5FileDLL调用
c
long MD5File(long instance, string filePath);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| instance | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| filePath | 字符串 | 要计算MD5哈希值的文件路径。 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
string hash = ola.MD5File("data/readme.txt");csharp
using OLAPlug;
var ola = new OLAPlugServer();
string hash = ola.MD5File("data/readme.txt");python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
hash = ola.MD5File("data/readme.txt")java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
String hash = ola.MD5File("data/readme.txt");cpp
var ola = com("OlaPlug.OlaSoft")
var hash = ola.MD5File("data/readme.txt")vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
hash = ola.MD5File("data/readme.txt")text
.局部变量 ola, OLAPlug
ola.创建 ()
hash = ola.MD5File("data/readme.txt")aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var hash = ola.MD5File("data/readme.txt");text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
文本型 hash = ola.MD5File("data/readme.txt")cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
std::string hash = ola.MD5File("data/readme.txt");原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
long ptr = MD5File(instance, "data/readme.txt");
if (ptr != 0) {
char buffer[4096] = {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 CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long MD5File(long ola, string filePath);
long instance = CreateCOLAPlugInterFace();
long ptr = MD5File(instance, "data/readme.txt");
if (ptr != 0) {
StringBuilder sb = new StringBuilder(GetStringSize(ptr) + 1);
GetStringFromPtr(ptr, sb, sb.Capacity);
FreeStringPtr(ptr);
string hash = sb.ToString();
}python
from ctypes import CDLL, c_int, c_int64
ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
ptr = ola.MD5File(instance, b"data/readme.txt")返回值
| 返回值 | 说明 |
|---|---|
非 0 | 成功,返回 MD5哈希值的字符串指针。 |
0 | 失败。 |
注意事项
| 项目 | 说明 |
|---|---|
| 路径 | 文件路径必须是有效的文件路径。 |
