I writing some software to automate some 3rd party software and have found it necessary to look into calling that software's own dlls.
Note: Unfortunately, I don't have access to the source or the developer
Calling the dll's static methods has been easy using PInvoke, but from what I can tell, instantiating classes isn't possible without a C++/CLI wrapper.
The answer seems to be to create a C++/CLR wrapper around the dll, as demonstrated in this answer. While obviously an excellent answer, I've never created a C++ application before and don't know exactly what to do.
I've already used dependency walker to get the function name I'd like to use: sdk_string::sdk_string(const char *)
(as decorated: ??0sdk_string@@QAE@XZ
). Trying to PInvoke at that entry point just ends in sadness and self-pity.
From what I've gathered, I need to:
- Create a new Visual C++ CLR Class Library.
- In the main .h header file write something like:
sdk_string* CreateSdkString(const char * chars) { return new sdk_string(chars); }
- Somehow get that
new sdk_string(chars)
call to call into the 3rd party dll? - ?????? (do I need to build it any special way so I can easily PInvoke my
CreateSdkString
function?) - Upvote and accept your answer. :-)
I think step 3 above is my question: how do I get that new sdk_string(chars)
call to call into the 3rd party dll? But if I'm wrong about other things, then those other things I'm wrong about are my question.
Update:
Just for reference, here is the entire Dependency Walker function name output for this class:
const sdk_string::`vftable'
class sdk_string & sdk_string::append(class sdk_string const &)
class sdk_string & sdk_string::append(char)
class sdk_string & sdk_string::append(char *)
class sdk_string & sdk_string::append(char const *)
char const * sdk_string::c_str(void)
bool sdk_string::contains(char const *)
bool sdk_string::empty(void)
bool sdk_string::endsWith(char const *)
int sdk_string::equals(class sdk_string const &)
int sdk_string::equals(char const *)
int sdk_string::equalsIgnoreCase(class sdk_string const &)
int sdk_string::equalsIgnoreCase(char const *)
void sdk_string::erase(int,int)
bool sdk_string::hasAlphaChars(void)
int sdk_string::indexOf(class sdk_string const &)
int sdk_string::indexOf(char)
int sdk_string::indexOf(char,int)
int sdk_string::indexOf(char const *)
void sdk_string::insert(int,char const *)
bool sdk_string::isAllDigits(void)
bool sdk_string::isAllWhiteSpace(void)
int sdk_string::length(void)
class sdk_string & sdk_string::operator=(class sdk_string const &)
class sdk_string & sdk_string::operator=(char *)
void sdk_string::replace(int,int,class sdk_string const &)
void sdk_string::replace(char const *)
sdk_string::sdk_string(wchar_t * &)
sdk_string::sdk_string(class sdk_string const &)
sdk_string::sdk_string(char const *)
sdk_string::sdk_string(void)
void sdk_string::setData(char const *)
bool sdk_string::startsWith(char const *)
bool sdk_string::stretch(int)
void sdk_string::stripLeadingSpaces(void)
void sdk_string::stripSpaces(void)
void sdk_string::stripTrailingSpaces(void)
void sdk_string::substr(int,int,class sdk_string &)
void sdk_string::toUpper(class sdk_string &)
sdk_string::~sdk_string(void)
foo::foo()
was equivalent toclass foo{ public: foo(){} }
. I think I'm missing some really obvious piece of the puzzle ... how do I get the function/class from the 3rd party .dll into my new C++/CLR wrapper so I can call it? I've read about usingLoadLibrary
, which I have no problem doing in C#, but just don't know how to do in C++. – David Murdoch