Note that there are some explanatory texts on larger screens.

plurals
  1. POExplicit Loading of DLL
    text
    copied!<p>I'm trying to explicitly link with a DLL. No other resources is available except the DLL file itself and some documentation about the classes and its member functions.</p> <p>From the documentation, each class comes with its own </p> <ol> <li>member typedef<br> example: <code>typedef std::map&lt;std::string,std::string&gt; Server::KeyValueMap, typedef std::vector&lt;std::string&gt; Server::String Array</code></li> <li>member enumeration<br> example: <code>enum Server::Role {NONE,HIGH,LOW}</code></li> <li>member function<br> example: <code>void Server::connect(const StringArray,const KeyValueMap), void Server::disconnect()</code></li> </ol> <p>Implementing the codes from google search, i manage to load the dll can call the disconnect function..</p> <p>dir.h </p> <pre><code>LPCSTR disconnect = "_Java_mas_com_oa_rollings_as_apiJNI_Server_1disconnect@20"; LPCSTR connect = "_Java_mas_com_oa_rollings_as_apiJNI_Server_1connect@20"; </code></pre> <p>I got the function name above from depends.exe. Is this what is called decorated/mangled function names in C++?</p> <p>main.cpp </p> <pre><code>#include &lt;iostream&gt; #include &lt;windows.h&gt; #include &lt;tchar.h&gt; #include "dir.h" typedef void (*pdisconnect)(); int main() { HMODULE DLL = LoadLibrary(_T("server.dll")); pdisconnect _pdisconnect;` if(DLL) { std::cout&lt;&lt; "DLL loaded!" &lt;&lt; std::endl; _disconnect = (pdisconnect)GetProcAddress(DLL,disconnect); if(_disconnect) { std::cout &lt;&lt; "Successful link to function in DLL!" &lt;&lt; std::endl; } else { std::cout&lt;&lt; "Unable to link to function in DLL!" &lt;&lt; std::endl; } } else { std::cout&lt;&lt; "DLL failed to load!" &lt;&lt; std::endl; } FreeLibrary (DLL); return 0;} </code></pre> <p>How do i call (for example) the <strong><em>connect</em></strong> member function which has the parameter datatype declared in the dll itself? </p> <p><strong>Edit</strong></p> <p>more info:</p> <ul> <li>The DLL comes with an example implementation using Java. The Java example contains a Java wrapper generated using SWIG and a source code.</li> <li>The documentation lists all the class, their member functions and also their datatypes. According to the doc, the list was generated from the C++ source codes.(??)</li> <li>No other info was given (no info on what compiler was used to generate the DLL)</li> </ul> <p>My colleague is implementing the interface using Java based on the Java example given, while I was asked to implement using C++. The DLL is from a third party company. </p> <p>I'll ask them about the compiler. Any other info that i should get from them?</p> <p>I had a quick read through about JNI but i dont understand how it's implemented in this case.</p> <p><strong>Update</strong></p> <p>i'm a little confused... (ok, ok... very confused)</p> <ol> <li>Do i call(GetProcAddress) each public member function separately only when i want to use them? </li> <li>Do i create a dummy class that imitates the class in the dll. Then inside the class definition, i call the equivalent function from the DLL? (Am i making sense here?) fnieto, is this what you're showing me at the end of your post? </li> <li>Is it possible to instantiate the whole class from the DLL?</li> </ol> <p>I was trying to use the connect function described in my first post. From the Depends.exe DLL output,</p> <ul> <li>std::map // KeyValueMap has the following member functions: <strong><em>del, empty, get, has_1key,set</em></strong></li> <li>std::vector // StringArray has the following member functions: <strong><em>add, capacity, clear, get, isEMPTY, reserve, set, size</em></strong> </li> </ul> <p>which is different from the member functions of map and vector in my compiler (VS 2005)...</p> <p>Any idea? or am i getting the wrong picture here...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload