首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在JNA中使用GetProcAddress?

如何在JNA中使用GetProcAddress?

提问于 2022-11-27 16:01:47
回答 0关注 0查看 58

已知C++代码

// dllmain.cpp : 定义 DLL 应用程序的入口点。

#include "pch.h"

#include <stdio.h>

#include <WTypes.h>

//定义CTXStringW为BSTR

typedef BSTR CTXStringW;

CTXStringW AllocTXString(const wchar_t* lpSrc)

{

if (lpSrc == NULL) return NULL;

BYTE* bBuffer = new BYTE[16 + (wcslen(lpSrc) + 1) * 2];

if (bBuffer == NULL) return NULL;

DWORD dwZero = 0;

DWORD dwCount = 3;

DWORD dwLenth = wcslen(lpSrc) + 1;

memmove(bBuffer + 0 * 4, &dwZero, 4);

memmove(bBuffer + 1 * 4, &dwCount, 4);

memmove(bBuffer + 2 * 4, &dwLenth, 4);

memmove(bBuffer + 3 * 4, &dwLenth, 4);

wcscpy((wchar_t*)(bBuffer + 4 * 4), lpSrc);

return CTXStringW(bBuffer + 16);

}

VOID GETQQ()

{

do {

HMODULE hKernelUtil = GetModuleHandle(L"KernelUtil.dll");

if (hKernelUtil == NULL)

{

OutputDebugStringA("Get KernelUtil Module failed \n");

break;

}

PVOID PtrGetSelfUin = GetProcAddress(hKernelUtil, "?GetSelfUin@Contact@Util@@YAKXZ");

if (PtrGetSelfUin == NULL)

{

OutputDebugStringA("Get GetSelfUin Function failed \n");

break;

}

DWORD uin = ((int(*)(int))PtrGetSelfUin)(1);

if (uin == NULL)

{

OutputDebugStringA("Invoke GetSelfUin Function failed \n");

break;

}

// Print QQ number

char szUin[MAX_PATH] = { 0 };

sprintf(szUin, "%d", uin);

} while (0);

}

BOOL APIENTRY DllMain( HMODULE hModule,

DWORD ul_reason_for_call,

LPVOID lpReserved

)

{

switch (ul_reason_for_call)

{

case DLL_PROCESS_ATTACH:

GETQQ();

break;

case DLL_THREAD_ATTACH:

case DLL_THREAD_DETACH:

case DLL_PROCESS_DETACH:

break;

}

return TRUE;

}

能不能拿Java代码实现获取当前登录的QQ号功能呢?

回答

和开发者交流更多问题细节吧,去 写回答
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档