C++ interface improvements

KarlBouchard
KarlBouchard Posts: 18 Calcite Rank Badge
edited February 2023 in GeoStudio
Hi all,

I decided to convert my applications that were using my own C++ wrapper around the C interface to the official GX C++ interface. I figured that it would be fairly simple since both implementation had the same concepts with smart pointers. It was a bit tedious to do but in the end it was worth it since the official interface wraps the entire C interface and my own wrapper only wrapped the methods I was using.
I had to do a couple of adjustments in the API to get things to work. Since there's a service pack coming out soon, perhaps this could be added in the official release?

In the GXContext class, I needed to set the "flags" parameter of pCreate_GEO

GXContextPtr create(const gx_string_type& application, const gx_string_type& version, HWND hParentWnd = nullptr, long flags = 0)
{
...if (auto cur_ctx = currentContext.lock())
......return cur_ctx;
...auto ctx = GXContextPtr(new GXContext(application, version, hParentWnd, flags));
...currentContext = ctx;
...return ctx;
}

GXContext(const gx_string_type& application, const gx_string_type& version, HWND hParentWnd, long flags)
: pGeo(nullptr)
, destroyGeo(true)
{
...gx_string_char_type geoError[4096];
...pGeo = pCreate_GEO(application.c_str(), version.c_str(), 0, hParentWnd, flags, geoError, _countof(geoError));
...if (pGeo == nullptr)
...{
......gx_string_type error = gx_string_literal("Unable to initialize Geosoft libraries: ");
......error += geoError;
......throw GXAPIError(error);
...}
}

I couldn't find a function that wrapped App_LoadControl_EMAP, so I created this one in GXEMAP
static GXEMAPPtr load_control(const gx_string_type& file, HWND hwnd)
{
...GXContextPtr gx_ = GXContext::current();
...int32_t ret = App_LoadControl_EMAP(gx_->pGeo, file.c_str(), hwnd);
...gx_->throw_on_error();
...return gx_->createPtr(ret);
}

I hope this can be useful for someone else!

Best regards,

Karl
This discussion has been closed.