Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>"Convert a library to another library type" <em>seems</em> easy, but it is not. There is no straight-forward step-by-step way to do this because C++ and DLLs do not play well together at all, and your code will need to be adapted to support a DLL interface.</p> <p>A concise way to describe the problem is this:</p> <ul> <li>A .lib's interface is C++</li> <li>A .dll's interface is C</li> </ul> <p>Thus, a DLL's interface simply doesn't support C++ and you need to be <em>clever</em> to make it work - this is why the ambiguous existing answers.</p> <p>One standard way is via COM, which means building an entire COM wrapper for the library, complete with class factory, interfaces, objects, and using <code>BSTR</code> instead of <code>std::string</code>. I would guess is not practical.</p> <p>Another solution is to create a C interface for your C++ library which is DLL-safe. That means basically creating a winapi-style interface, which again is probably not practical or defeats the purpose of using your library at all. This is what @David Heffernan suggests. But what he doesn't address is how you must change your code to be DLL-compatible.</p> <p>An important but subtle problem is you cannot pass ANY templated C++ objects across DLL boundaries. This means passing <code>std::string</code> in or out of a DLL function is considered unsafe. Each binary gets its own copy of the <code>std::string</code> code, and there's no guarantee that they will happen to play nicely with each other. Each binary (potentially) also gets its own copy of the CRT and you will mess up internal state of one module by manipulating objects from another.</p> <p><strong>Edit</strong>: You can export C++ objects in MSVC using <code>__declspec(dllexport)</code> and importing them using <code>__declspec(dllimport)</code>. But there are a lot of restrictions on this and subtleties that cause problems. Basically this is a shortcut for getting the compiler to create a cheap C-style interface for your exported class or function. The problem is it doesn't warn you about how much unsafe stuff is happening. To reiterate:</p> <ol> <li>If there are ANY templated symbols crossing DLL bounds, it is not safe (<code>std::*</code> for example).</li> <li>Any objects with CRT-managed state should not cross DLL bounds (<code>FILE*</code> for example).</li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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