Skip to content

Commit

Permalink
fix loading libobject* dll with recent RStudio
Browse files Browse the repository at this point in the history
fix loading libobject* dll for GP Tool execute
build 237
  • Loading branch information
dpavlushko committed Oct 10, 2019
1 parent a13b804 commit bd1e670
Show file tree
Hide file tree
Showing 10 changed files with 681 additions and 681 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: arcgisbinding
Version: 1.0.1.235
Date: 2019-08-14
Version: 1.0.1.237
Date: 2019-10-09
Title: Bindings for ArcGIS
Author: Esri
Maintainer: Esri <R_bridge@esri.com>
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: arcgisbinding
Version: 1.0.1.235
Date: 2019-08-14
Version: 1.0.1.237
Date: 2019-10-09
Title: Bindings for ArcGIS
Author: Esri
Maintainer: Esri <R_bridge@esri.com>
Expand Down
Binary file modified libs/Win32/libobjects.dll
Binary file not shown.
Binary file modified libs/Win32/rarcproxy.dll
Binary file not shown.
Binary file modified libs/x64/libobjects.dll
Binary file not shown.
Binary file modified libs/x64/libobjects_pro.dll
Binary file not shown.
Binary file modified libs/x64/rarcproxy.dll
Binary file not shown.
Binary file modified libs/x64/rarcproxy_pro.dll
Binary file not shown.
154 changes: 77 additions & 77 deletions src/msprojects/proxy/dllmain.cpp
Original file line number Diff line number Diff line change
@@ -1,77 +1,77 @@
// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
#include <filesystem>

#if _HAS_CXX17
namespace fs = std::experimental::filesystem::v1;
#else
namespace fs = std::tr2::sys;
#endif

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

HMODULE hDllHandle = NULL;
HMODULE hapi_dll = 0;
fn_api get_api = nullptr;
const arcobject::API* _api = nullptr;

bool load_arcobjectlib(HMODULE hModule)
{
if (_api != nullptr)
return true;

wchar_t dllName[MAX_PATH] = { 0 };
::GetModuleFileName(hModule, dllName, _countof(dllName));
HMODULE hm;
::GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_PIN, dllName, &hm);

//prepare search directories to load libobjecs.dll
auto tmp = fs::path(dllName);// .remove_filename();
//force load api dll
tmp.replace_filename(LIBRARY_API_DLL_NAME ".dll");
hapi_dll = ::LoadLibraryEx(tmp.wstring().c_str(), NULL, LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR);
get_api = (fn_api)::GetProcAddress(hapi_dll, "api");
ATLASSERT(get_api != nullptr);
if (get_api == nullptr)
return false;

try {
extern bool g_InProc;
ATLASSERT(g_InProc == false && get_api != nullptr);
auto api = get_api(g_InProc);
if (api == nullptr)
return false;
//validate
api->getLastComError();
_api = api;
return true;
}
catch (...) { }
return false;
}

BOOL APIENTRY DllMain(HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
{
::DisableThreadLibraryCalls(hModule);
hDllHandle = hModule;
_api = nullptr;
//load_arcobjectlib(hModule);
}
break;
case DLL_PROCESS_DETACH:
{
if (hapi_dll != 0)
FreeLibrary(hapi_dll);
hapi_dll = 0;
::OutputDebugStringA(DLL_NAME_STR " Terminated!\n");
}
break;
}
return TRUE;
}
// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
#include <filesystem>

#if _HAS_CXX17
namespace fs = std::experimental::filesystem::v1;
#else
namespace fs = std::tr2::sys;
#endif

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

HMODULE hDllHandle = NULL;
HMODULE hapi_dll = 0;
fn_api get_api = nullptr;
const arcobject::API* _api = nullptr;

bool load_arcobjectlib(HMODULE hModule)
{
if (_api != nullptr)
return true;

wchar_t dllName[MAX_PATH] = { 0 };
::GetModuleFileName(hModule, dllName, _countof(dllName));
HMODULE hm;
::GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_PIN, dllName, &hm);

//prepare search directories to load libobjecs.dll
auto tmp = fs::path(dllName);// .remove_filename();
//force load api dll
tmp.replace_filename(LIBRARY_API_DLL_NAME ".dll");
hapi_dll = ::LoadLibraryEx(tmp.wstring().c_str(), NULL, LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR);
get_api = (fn_api)::GetProcAddress(hapi_dll, "api");
ATLASSERT(get_api != nullptr);
if (get_api == nullptr)
return false;

try {
extern bool g_InProc;
ATLASSERT(g_InProc == false && get_api != nullptr);
auto api = get_api(g_InProc);
if (api == nullptr)
return false;
//validate
api->getLastComError();
_api = api;
return true;
}
catch (...) { }
return false;
}

BOOL APIENTRY DllMain(HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
{
::DisableThreadLibraryCalls(hModule);
hDllHandle = hModule;
_api = nullptr;
load_arcobjectlib(hModule);
}
break;
case DLL_PROCESS_DETACH:
{
if (hapi_dll != 0)
FreeLibrary(hapi_dll);
hapi_dll = 0;
::OutputDebugStringA(DLL_NAME_STR " Terminated!\n");
}
break;
}
return TRUE;
}
Loading

0 comments on commit bd1e670

Please sign in to comment.