imradv3 / src /WeChatOcrCpp /MmmojoDll.cpp
fasdfsa's picture
todo: fix link err.
17f5b5c
#include "Constant.h"
#include "MmmojoDll.h"
#include <iostream>
HMODULE MmmojoDll::hModule = NULL;
bool MmmojoDll::initialized = false;
MmmojoDll::MmmojoDll() {
if (!initialized) {
LoadDll();
}
}
void MmmojoDll::LoadDll() {
if (initialized) return;
hModule = LoadLibraryA(Constant::MojoDllName.c_str());
if (hModule == NULL) {
DWORD error = GetLastError();
std::cerr << "Failed to load " << Constant::MojoDllName << ", error code: " << error << std::endl;
throw std::runtime_error("Failed to load MmmojoDll");
}
initialized = true;
}
// 函数实现
void MmmojoDll::InitializeMMMojo(int argc, void* argv) {
if (!initialized) LoadDll();
typedef void (*FuncType)(int, void*);
FuncType func = (FuncType)GetProcAddress(hModule, "InitializeMMMojo");
if (func) {
func(argc, argv);
}
}
void MmmojoDll::ShutdownMMMojo() {
if (!initialized) return;
typedef void (*FuncType)();
FuncType func = (FuncType)GetProcAddress(hModule, "ShutdownMMMojo");
if (func) {
func();
}
}
void* MmmojoDll::CreateMMMojoEnvironment() {
if (!initialized) LoadDll();
typedef void* (*FuncType)();
FuncType func = (FuncType)GetProcAddress(hModule, "CreateMMMojoEnvironment");
if (func) {
return func();
}
return nullptr;
}
void MmmojoDll::SetMMMojoEnvironmentCallbacks(void* mmmojo_env, int type, void* callback) {
if (!initialized) LoadDll();
typedef void (*FuncType)(void*, int, void*);
FuncType func = (FuncType)GetProcAddress(hModule, "SetMMMojoEnvironmentCallbacks");
if (func) {
func(mmmojo_env, type, callback);
}
}
void MmmojoDll::SetMMMojoEnvironmentInitParams(void* mmmojo_env, int type, void* param) {
if (!initialized) LoadDll();
typedef void (*FuncType)(void*, int, void*);
FuncType func = (FuncType)GetProcAddress(hModule, "SetMMMojoEnvironmentInitParams");
if (func) {
func(mmmojo_env, type, param);
}
}
void MmmojoDll::AppendMMSubProcessSwitchNative(void* mmmojo_env, void* switchStringPtr, void* valuePtr) {
if (!initialized) LoadDll();
typedef void (*FuncType)(void*, void*, void*);
FuncType func = (FuncType)GetProcAddress(hModule, "AppendMMSubProcessSwitchNative");
if (func) {
func(mmmojo_env, switchStringPtr, valuePtr);
}
}
void MmmojoDll::StartMMMojoEnvironment(void* mmmojo_env) {
if (!initialized) LoadDll();
typedef void (*FuncType)(void*);
FuncType func = (FuncType)GetProcAddress(hModule, "StartMMMojoEnvironment");
if (func) {
func(mmmojo_env);
}
}
void MmmojoDll::StopMMMojoEnvironment(void* mmmojo_env) {
if (!initialized) LoadDll();
typedef void (*FuncType)(void*);
FuncType func = (FuncType)GetProcAddress(hModule, "StopMMMojoEnvironment");
if (func) {
func(mmmojo_env);
}
}
void MmmojoDll::RemoveMMMojoEnvironment(void* mmmojo_env) {
if (!initialized) LoadDll();
typedef void (*FuncType)(void*);
FuncType func = (FuncType)GetProcAddress(hModule, "RemoveMMMojoEnvironment");
if (func) {
func(mmmojo_env);
}
}
void* MmmojoDll::GetMMMojoReadInfoRequest(void* mmmojo_readinfo, unsigned int* requestDataSize) {
if (!initialized) LoadDll();
typedef void* (*FuncType)(void*, unsigned int*);
FuncType func = (FuncType)GetProcAddress(hModule, "GetMMMojoReadInfoRequest");
if (func) {
return func(mmmojo_readinfo, requestDataSize);
}
return nullptr;
}
void* MmmojoDll::GetMMMojoReadInfoAttach(void* mmmojo_readinfo, unsigned int* attachDataSize) {
if (!initialized) LoadDll();
typedef void* (*FuncType)(void*, unsigned int*);
FuncType func = (FuncType)GetProcAddress(hModule, "GetMMMojoReadInfoAttach");
if (func) {
return func(mmmojo_readinfo, attachDataSize);
}
return nullptr;
}
void MmmojoDll::RemoveMMMojoReadInfo(void* mmmojo_readinfo) {
if (!initialized) LoadDll();
typedef void (*FuncType)(void*);
FuncType func = (FuncType)GetProcAddress(hModule, "RemoveMMMojoReadInfo");
if (func) {
func(mmmojo_readinfo);
}
}
int MmmojoDll::GetMMMojoReadInfoMethod(void* mmmojo_readinfo) {
if (!initialized) LoadDll();
typedef int (*FuncType)(void*);
FuncType func = (FuncType)GetProcAddress(hModule, "GetMMMojoReadInfoMethod");
if (func) {
return func(mmmojo_readinfo);
}
return 0;
}
bool MmmojoDll::GetMMMojoReadInfoSync(void* mmmojo_readinfo) {
if (!initialized) LoadDll();
typedef bool (*FuncType)(void*);
FuncType func = (FuncType)GetProcAddress(hModule, "GetMMMojoReadInfoSync");
if (func) {
return func(mmmojo_readinfo);
}
return false;
}
void* MmmojoDll::CreateMMMojoWriteInfo(int method, int sync, unsigned int requestId) {
if (!initialized) LoadDll();
typedef void* (*FuncType)(int, int, unsigned int);
FuncType func = (FuncType)GetProcAddress(hModule, "CreateMMMojoWriteInfo");
if (func) {
return func(method, sync, requestId);
}
return nullptr;
}
void* MmmojoDll::GetMMMojoWriteInfoRequest(void* mmmojo_writeinfo, unsigned int requestDataSize) {
if (!initialized) LoadDll();
typedef void* (*FuncType)(void*, unsigned int);
FuncType func = (FuncType)GetProcAddress(hModule, "GetMMMojoWriteInfoRequest");
if (func) {
return func(mmmojo_writeinfo, requestDataSize);
}
return nullptr;
}
void MmmojoDll::RemoveMMMojoWriteInfo(void* mmmojo_writeinfo) {
if (!initialized) LoadDll();
typedef void (*FuncType)(void*);
FuncType func = (FuncType)GetProcAddress(hModule, "RemoveMMMojoWriteInfo");
if (func) {
func(mmmojo_writeinfo);
}
}
void* MmmojoDll::GetMMMojoWriteInfoAttach(void* mmmojo_writeinfo, unsigned int attachDataSize) {
if (!initialized) LoadDll();
typedef void* (*FuncType)(void*, unsigned int);
FuncType func = (FuncType)GetProcAddress(hModule, "GetMMMojoWriteInfoAttach");
if (func) {
return func(mmmojo_writeinfo, attachDataSize);
}
return nullptr;
}
void MmmojoDll::SetMMMojoWriteInfoMessagePipe(void* mmmojo_writeinfo, int numOfMessagePipe) {
if (!initialized) LoadDll();
typedef void (*FuncType)(void*, int);
FuncType func = (FuncType)GetProcAddress(hModule, "SetMMMojoWriteInfoMessagePipe");
if (func) {
func(mmmojo_writeinfo, numOfMessagePipe);
}
}
void MmmojoDll::SetMMMojoWriteInfoResponseSync(void* mmmojo_writeinfo, void** mmmojo_readinfo) {
if (!initialized) LoadDll();
typedef void (*FuncType)(void*, void**);
FuncType func = (FuncType)GetProcAddress(hModule, "SetMMMojoWriteInfoResponseSync");
if (func) {
func(mmmojo_writeinfo, mmmojo_readinfo);
}
}
bool MmmojoDll::SendMMMojoWriteInfo(void* mmmojo_env, void* mmmojo_writeinfo) {
if (!initialized) LoadDll();
typedef bool (*FuncType)(void*, void*);
FuncType func = (FuncType)GetProcAddress(hModule, "SendMMMojoWriteInfo");
if (func) {
return func(mmmojo_env, mmmojo_writeinfo);
}
return false;
}
bool MmmojoDll::SwapMMMojoWriteInfoCallback(void* mmmojo_writeinfo, void* mmmojo_readinfo) {
if (!initialized) LoadDll();
typedef bool (*FuncType)(void*, void*);
FuncType func = (FuncType)GetProcAddress(hModule, "SwapMMMojoWriteInfoCallback");
if (func) {
return func(mmmojo_writeinfo, mmmojo_readinfo);
}
return false;
}
bool MmmojoDll::SwapMMMojoWriteInfoMessage(void* mmmojo_writeinfo, void* mmmojo_readinfo) {
if (!initialized) LoadDll();
typedef bool (*FuncType)(void*, void*);
FuncType func = (FuncType)GetProcAddress(hModule, "SwapMMMojoWriteInfoMessage");
if (func) {
return func(mmmojo_writeinfo, mmmojo_readinfo);
}
return false;
}