首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

求高手将VC的代码转成VB6的.该如何处理

2012-04-11 
求高手将VC的代码转成VB6的.*/#include windows.h#include stdio.h#include tlhelp32.h#include ps

求高手将VC的代码转成VB6的.
*/


#include <windows.h>
#include <stdio.h>
#include <tlhelp32.h>
#include <psapi.h>

#pragma comment(lib, "Psapi.lib")

#define __printf printf

void HideLibrary(HMODULE hModule, LPVOID pCallBackAddr, LPVOID lParam);

typedef struct
{
  HMODULE lpDllBase;
  LPVOID lpNewDllBase;
  PTHREAD_START_ROUTINE pAddress;
  LPVOID lParam;
}UNLOADLIB_CALLBACK, *PUNLOADLIB_CALLBACK;

typedef
LPVOID WINAPI VIRTUALALLOC(
  LPVOID lpAddress,
  SIZE_T dwSize,
  DWORD flAllocationType,
  DWORD flProtect
);

typedef
BOOL WINAPI VIRTUALFREE(
  LPVOID lpAddress,
  SIZE_T dwSize,
  DWORD dwFreeType
);


typedef
BOOL WINAPI HEAPDESTROY(
  HANDLE hHeap
);

typedef
HMODULE WINAPI LOADLIBRARY(
  LPCTSTR lpFileName
);

typedef
HANDLE WINAPI CREATETHREAD(
  LPSECURITY_ATTRIBUTES lpThreadAttributes,
  SIZE_T dwStackSize,
  LPTHREAD_START_ROUTINE lpStartAddress,
  LPVOID lpParameter,
  DWORD dwCreationFlags,
  LPDWORD lpThreadId
);

typedef void * __cdecl MEMCPY(void *, const void *, size_t);


BOOL incLibraryCount(HMODULE hMe)
{
  //FreeLibrary后很多系统dll也会free掉,所以将所有已加载的再load一次以增加计数
   
  HANDLE hModsSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, 0);

  if(INVALID_HANDLE_VALUE == hModsSnap)
  {
  return FALSE;
  }

  MODULEENTRY32 meModuleEntry;
  meModuleEntry.dwSize = sizeof(MODULEENTRY32);

  if(!Module32First(hModsSnap, &meModuleEntry))
  {
  CloseHandle(hModsSnap);
  return FALSE;
  }
  do
  {
  if(LoadLibrary(meModuleEntry.szModule) == hMe)
  FreeLibrary(hMe);

  } while(Module32Next(hModsSnap, &meModuleEntry));

  CloseHandle(hModsSnap);

  return TRUE;
}

//枚举指定进程的所有线程
DWORD WINAPI EnumAndSetThreadState(LPVOID lParam)
{
  HANDLE hThreadSnap = NULL;
  THREADENTRY32 te32;
  memset(&te32,0,sizeof(te32));
  te32.dwSize = sizeof(THREADENTRY32);
  hThreadSnap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD,0);

  DWORD myThreadId = GetCurrentThreadId();
  DWORD pid = GetCurrentProcessId();

  if (Thread32First(hThreadSnap, &te32))
  {
  do
  {
  if (pid == te32.th32OwnerProcessID)
  {
  if(myThreadId != te32.th32ThreadID)
  {
  HANDLE hThread = OpenThread(
  THREAD_SUSPEND_RESUME,
  FALSE,
  te32.th32ThreadID);

  if(hThread != NULL)
  {
  if((int)lParam)
  ResumeThread(hThread);
  else
  SuspendThread(hThread);

  CloseHandle(hThread);
  }
  }
  }
  }
  while (Thread32Next(hThreadSnap,&te32));
  }
  CloseHandle( hThreadSnap );

  return 0;
}

DWORD WINAPI GotoCallBackAddr(LPVOID lParam)
{
  PUNLOADLIB_CALLBACK cbFunc = (PUNLOADLIB_CALLBACK)lParam;

  DWORD dwThreadId;
  HANDLE hThread;

  if(cbFunc->pAddress)
  {
  hThread = CreateThread(
  NULL,
  0,
  cbFunc->pAddress,
  cbFunc->lParam,
  0,
  &dwThreadId);

  if(hThread)
  CloseHandle(hThread);
  }

  //那份dll的拷贝不需要了,释放~
  VirtualFree(cbFunc->lpNewDllBase, 0, MEM_DECOMMIT);
  delete cbFunc;

  return 0;
}


[解决办法]
直接用 VC++ 建成一个标准 DLL 供 VB 调用即可。

[解决办法]

探讨
直接用 VC++ 建成一个标准 DLL 供 VB 调用即可。

热点排行