Commit 1120503a by 李定达

1.将依赖dll路径修改为设置程序当前的环境变量

parent 28827eb8
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include <Windows.h> #include <Windows.h>
#include <Winbase.h> #include <Winbase.h>
#include <string> #include <string>
#include <iostream>
#pragma comment(lib, "Kernel32.lib") #pragma comment(lib, "Kernel32.lib")
...@@ -40,29 +41,44 @@ int init_sign = 0; ...@@ -40,29 +41,44 @@ int init_sign = 0;
HMODULE GetInstance() HMODULE GetInstance()
{ {
char current_dir[MAX_PATH] = { 0 }; char current_dir[MAX_PATH] = { 0 };
if (0 < GetCurrentDirectoryA(MAX_PATH, current_dir)) { char chBuf[10240]={0};
char mod[MAX_PATH] = { 0 }; char mod[MAX_PATH] = { 0 };
GetModuleFileNameA((HMODULE)&__ImageBase, mod, MAX_PATH); GetModuleFileNameA((HMODULE)&__ImageBase, mod, MAX_PATH);
char *ch = strrchr(mod,'\\'); char *ch = strrchr(mod,'\\');
if (ch++) { if (ch++) {
*ch = '\0'; *ch = '\0';
}
printf("Current directory: %s\nModule path: %s\n", current_dir, mod); DWORD dwSize =GetEnvironmentVariable("path", chBuf, 10240);
printf("Changing current to: %s\n", mod); std::string currpath(chBuf);
SetCurrentDirectory(mod);
currpath += (std::string(";") + std::string(mod));
std::cout << currpath;
char instance[MAX_PATH] = { 0 }; char instance[MAX_PATH] = { 0 };
sprintf(instance, "%s%s", mod, SBKPAYDLL); sprintf(instance, "%s%s", mod, SBKPAYDLL);
//if(init_sign == 0)
// DoCopyFile(mod);
//init_sign = 1;
HMODULE hMod = LoadLibraryA(instance);
//HMODULE hModw = LoadLibraryW(L"C:\\Users\\dingda.li\\Desktop\\sbkpay\\sbkpay.dll");
printf("Changing current to: %s\n", current_dir);
SetCurrentDirectory(current_dir);
SetEnvironmentVariable("path", currpath.data());
HMODULE hMod = LoadLibraryA(instance);
return hMod; return hMod;
// printf("Current directory: %s\nModule path: %s\n", current_dir, mod);
// printf("Changing current to: %s\n", mod);
// SetCurrentDirectory(mod);
// char instance[MAX_PATH] = { 0 };
// sprintf(instance, "%s%s", mod, SBKPAYDLL);
////if(init_sign == 0)
//// DoCopyFile(mod);
////init_sign = 1;
// HMODULE hMod = LoadLibraryA(instance);
////HMODULE hModw = LoadLibraryW(L"C:\\Users\\dingda.li\\Desktop\\sbkpay\\sbkpay.dll");
// printf("Changing current to: %s\n", current_dir);
// SetCurrentDirectory(current_dir);
// return hMod;
} }
return NULL; return NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment