Note that there are some explanatory texts on larger screens.

plurals
  1. POName mangling in an exported c++ member function to C# (Unity)
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/11619986/c-plugin-for-unity-entrypointnotfoundexeption">C++ plugin for Unity &ldquo;EntryPointNotFoundExeption&rdquo;</a> </p> </blockquote> <p>I understand how to prevent name mangling with extern "C" on individual functions in c++, but is there any way to prevent it when exporting member functions?</p> <p><strong>WMIWrapper.cpp</strong></p> <pre><code>namespace WMIWrapper { extern "C" { WMIWrapper::WMIWrapper() { _locator = NULL; _service = NULL; _monitors = NULL; } WMIWrapper::~WMIWrapper() { if(_service != NULL) _service-&gt;Release(); if(_locator != NULL) _locator-&gt;Release(); } void WMIWrapper::CreateCOM(wchar_t* err, int errLength) { wstringstream ERRStream (wstringstream::in | wstringstream::out); HRESULT hRes = CoInitializeEx(NULL, COINIT_MULTITHREADED); if(FAILED(hRes)) { ERRStream &lt;&lt; "Unable to launch COM: 0x" &lt;&lt; std::hex &lt;&lt; hRes &lt;&lt; endl; } hRes = CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_CONNECT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, 0); if(FAILED(hRes)) { ERRStream &lt;&lt; "Unable to set security level for COM: " &lt;&lt; std::hex &lt;&lt; hRes &lt;&lt; endl; } if(FAILED(hRes = CoCreateInstance(CLSID_WbemLocator, NULL, CLSCTX_ALL, IID_PPV_ARGS(&amp;_locator)))) { ERRStream &lt;&lt; "Unable to create a WbemLocator: " &lt;&lt; std::hex &lt;&lt; hRes &lt;&lt; endl; } if(ERRStream != NULL) wcscpy_s(err, errLength, ERRStream.str().c_str()); } void WMIWrapper::CreateService(wchar_t* err, int errLength) { wstringstream ERRStream (wstringstream::in | wstringstream::out); HRESULT hRes; if(_locator == NULL || FAILED(hRes = _locator-&gt;ConnectServer(L"root\\CIMV2", NULL, NULL, NULL, WBEM_FLAG_CONNECT_USE_MAX_WAIT, NULL, NULL, &amp;_service))) { ERRStream &lt;&lt; "Unable to connect to \"CIMV2\": " &lt;&lt; std::hex &lt;&lt; hRes &lt;&lt; endl; } if(ERRStream != NULL) wcscpy_s(err, errLength, ERRStream.str().c_str()); } void WMIWrapper::GetMonitors(wchar_t* err, int errLength) { HRESULT hRes; wstringstream ssMonitorDescription; if(_locator == NULL || _service == NULL || FAILED(hRes = _service-&gt;ExecQuery(L"WQL", L"SELECT * FROM Win32_DesktopMonitor", WBEM_FLAG_FORWARD_ONLY, NULL, &amp;_monitors))) { ssMonitorDescription &lt;&lt; "Unable to retrieve desktop monitors: " &lt;&lt; std::hex &lt;&lt; hRes &lt;&lt; endl; wcscpy_s(err, errLength, ssMonitorDescription.str().c_str()); return; } IWbemClassObject* clsObj = NULL; int numElems; while((hRes = _monitors-&gt;Next(WBEM_INFINITE, 1, &amp;clsObj, (ULONG*)&amp;numElems)) != WBEM_S_FALSE) { if(FAILED(hRes)) break; VARIANT vRet; VariantInit(&amp;vRet); if(SUCCEEDED(clsObj-&gt;Get(L"Description", 0, &amp;vRet, NULL, NULL)) &amp;&amp; vRet.vt == VT_BSTR) { ssMonitorDescription &lt;&lt; "Description: " &lt;&lt; vRet.bstrVal &lt;&lt; endl; VariantClear(&amp;vRet); } } clsObj-&gt;Release(); wcscpy_s(err, errLength, ssMonitorDescription.str().c_str()); } void WMIWrapper::HelloWorld(wchar_t* testString, int length) { wstring hello = L"Hello World"; wcscpy_s(testString, length, hello.c_str()); } } } </code></pre> <p><strong>WMIWrapper.h</strong></p> <pre><code>#ifndef _WMIWRAPPER_H_ #define _WMIWRAPPER_H_ #include &lt;Windows.h&gt; #include &lt;sstream&gt; #include &lt;iostream&gt; #include &lt;WbemCli.h&gt; using std::endl; using std::wstring; using std::wstringstream; #pragma comment(lib, "wbemuuid.lib") namespace WMIWrapper { extern "C" { class WMIWrapper { public: WMIWrapper(); ~WMIWrapper(); __declspec(dllexport) void CreateCOM(wchar_t*, int); __declspec(dllexport) void CreateService(wchar_t*, int); __declspec(dllexport) void GetMonitors(wchar_t*, int); __declspec(dllexport) void HelloWorld(wchar_t*, int); private: IWbemLocator* _locator; IWbemServices* _service; IEnumWbemClassObject* _monitors; }; } } #endif </code></pre> <p>Now when I want to use those functions in Unity, I need to decompile the dll to find out what my EntryPoints are for the function names. I do not want to have to do this.</p> <p>I know I got a little overzealous with with the extern "C"...</p>
    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.
 

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