Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In C++/CLI you can use P/Invoke as in C#.</p> <p>If you don't want to use P/Invoke, the other way is to load the DLL with <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms684175%28v=vs.85%29.aspx" rel="nofollow">LoadLibrary</a> and get pointers to the functions with <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms683212%28v=vs.85%29.aspx" rel="nofollow">GetProcAddress</a>.</p> <hr> <p>Here's the equivalent of the C# code in C++/CLI:</p> <pre><code>using namespace System; using namespace System::Runtime::InteropServices; private ref class NativeMethods abstract sealed { internal: [DllImport("MimeTex.dll")] static int CreateGifFromEq(String^ expr, String^ fileName); [DllImport("kernel32.dll")] static IntPtr GetModuleHandle(String^ lpModuleName); [DllImport("kernel32.dll")] [returnvalue: MarshalAs(UnmanagedType::Bool)] static bool FreeLibrary(IntPtr hLibModule); }; </code></pre> <p>As you can see it's almost identical to the C# code except for some minor syntax changes.</p> <p>Here's how you would use LoadLibrary and GetProcAddress (which has the advantage of not requiring marshaling, which is unnecessary in C++ anyway):</p> <pre><code>HMODULE hModule = LoadLibrary(L"MimeTex.dll"); int (*fpCreateGifFromEq)(WCHAR*, WCHAR*) = GetProcAddress(hModule, "CreateGifFromEq"); (*fpCreateGifFromEq)(L"expression", L"filename"); </code></pre> <p>You don't need to do that for GetModuleHandle and FreeLibrary, because they're from kernel32.dll so you can just include Windows.h and call them normally.</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