Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8294351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:10:57+00:00 2026-06-08T14:10:57+00:00

Possible Duplicate: C++ plugin for Unity “EntryPointNotFoundExeption” I understand how to prevent name mangling

  • 0

Possible Duplicate:
C++ plugin for Unity “EntryPointNotFoundExeption”

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?

WMIWrapper.cpp

namespace WMIWrapper
{

    extern "C" {

        WMIWrapper::WMIWrapper()
        {
            _locator = NULL;
            _service = NULL;
            _monitors = NULL;
        }

        WMIWrapper::~WMIWrapper()
        {
            if(_service != NULL)
                _service->Release();
            if(_locator != NULL)
                _locator->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 << "Unable to launch COM: 0x" << std::hex << hRes << 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 << "Unable to set security level for COM: " << std::hex << hRes << endl;
            } 

            if(FAILED(hRes = CoCreateInstance(CLSID_WbemLocator, NULL, CLSCTX_ALL, IID_PPV_ARGS(&_locator))))  
            {  
                ERRStream << "Unable to create a WbemLocator: " << std::hex << hRes << 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->ConnectServer(L"root\\CIMV2", NULL, NULL, NULL, WBEM_FLAG_CONNECT_USE_MAX_WAIT, NULL, NULL, &_service)))  
            {  
                ERRStream << "Unable to connect to \"CIMV2\": " << std::hex << hRes << 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->ExecQuery(L"WQL", L"SELECT * FROM Win32_DesktopMonitor", WBEM_FLAG_FORWARD_ONLY, NULL, &_monitors)))
            {
                ssMonitorDescription << "Unable to retrieve desktop monitors: " << std::hex << hRes << endl;
                wcscpy_s(err, errLength, ssMonitorDescription.str().c_str());
                return;
            }

            IWbemClassObject* clsObj = NULL;
            int numElems;
            while((hRes = _monitors->Next(WBEM_INFINITE, 1, &clsObj, (ULONG*)&numElems)) != WBEM_S_FALSE)
            {
                if(FAILED(hRes))
                    break;

                VARIANT vRet;
                VariantInit(&vRet);
                if(SUCCEEDED(clsObj->Get(L"Description", 0, &vRet, NULL, NULL)) && vRet.vt == VT_BSTR)
                {
                    ssMonitorDescription << "Description: " << vRet.bstrVal << endl;
                    VariantClear(&vRet);
                }
            }

            clsObj->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());
        }
    }
}

WMIWrapper.h

#ifndef _WMIWRAPPER_H_
#define _WMIWRAPPER_H_

#include <Windows.h>  
#include <sstream>  
#include <iostream>
#include <WbemCli.h>  

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

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.

I know I got a little overzealous with with the extern “C”…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T14:10:59+00:00Added an answer on June 8, 2026 at 2:10 pm

    UPDATE: As @peechykeen pointed out in the comments, if you are going to use .def then you can directly rename your mangled names. I’m leaving the original answer although it’s much more useful for hiding the exported names rather then renaming them.

    Original answer:

    One way to do it is to “hide” the exported names behind ordinals. For that you will need to define a .def file and then in its EXPORTS section put all the exported names you want to hide. For example, to assign ordinal 1 to a function exported by a Boost serialization you would do this:

    EXPORTS
    ??0?$oserializer@Vportable_binary_oarchive@@U?$pair@$$CBHH@std@@@detail@archive@boost@@QEAA@XZ  @1  NONAME
    

    And so on for all the functions. Now, doing this manually is both tedious and error prone. And you will get link errors every time you change any part of the exported interface. To semi-automate it, I use Dependency Walker and a Perl script. It works like this:

    1. In .def file place markers in EXPORTS section:

      EXPORTS
      ;BEGIN_RENAMING_TAG
      ;END_RENAMING_TAG
      
    2. Load the binary into Dependency Walker, go to exported functions window, select all the exported functions and copy them to clipboard.

    3. Past the copied text between BEGIN/END tags in the .def file.
    4. Run the following Perl script on the .def file:

      #perl -w
      print $ARGC;
      die "ERROR: Provide name of one DEF file to process\n" if @ARGV != 1;
      
      my $renaming = 0;
      my $counter = 1;
      my $fileName = $ARGV[0];
      my @lines;
      open(FILE, $fileName) or die $!;
      while(<FILE>)
      {
          if(/;END_RENAMING_TAG/)
          {
              $renaming = 0;
          }
      
          if($renaming == 1)
          {
              chomp;
              my $line = $_."\t@".$counter."\tNONAME";
              push(@lines, $line);
              ++$counter;
          }
          else
          {
              chomp;
              push(@lines, $_);
          }
      
          if(/;BEGIN_RENAMING_TAG/)
          {
              $renaming = 1;
          }
      }
      
      close FILE;
      open(FILE, ">$fileName") or die $!;
      print FILE join("\n", @lines);
      close FILE;
      
    5. Entries in your .def file are now all in <entry> @<ordinal> NONAME format.

    Now, I don’t use these ordinals to access the functions, I just rename them as it bugs me to expose hundreds of exported functions that I don’t need (Boost serialization that I use in turn uses dllexport to force linking of its functions). So you would need to do more in Perl script and say export an enum with function names and ordinals. If you want to do this right you would have to implement a demangling algorithm in the Perl script that would give you accurate names, take care of overloading (same name, different args) and keep the enum name constants.

    In order to access the functions behind ordinals, you use GetProcAddress but cast the ordinal to LPCSTR. See the documentation for the function for more details.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: “Uncaught ReferenceError: JQueryValidatorUI is not defined”? Any familiar with jquery-validation-ui plugin for
Possible Duplicate: Detecting an “invalid date” Date instance in JavaScript I was using the
Possible Duplicate: Weird “406 not acceptable” error I've been stuck on this ALL DAY!
Possible Duplicate: Why does the JavaScript need to start with “;” ? I've been
Possible Duplicate: What does appending “?v=1” to CSS and Javascript URLs in link and
Possible Duplicate: How can I understand nested ?: operators in PHP? Why does this:
Possible Duplicate: How to do this pull-to-refresh in webapp? Is there a plugin available
Possible Duplicate: Reading dll.config (not app.config!) from a plugin module. I have two different
Possible Duplicate: jquery validate & ajax.beginform I'm trying to use the jQuery validate plugin
Possible Duplicate: Android Eclipse Plugin Too Slow I'm an Android programmer and when programming

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.