Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Joeoshawa · Jul 24, 2012 at 09:41 PM · c#pluginc++

C++ plugin for Unity “EntryPointNotFoundExeption”

I need some serious help here... I'm trying to either get my member functions exported so I can call them in C#

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")  
 
 static class WMIWrapper 
 {  
 public:
  __declspec(dllexport) WMIWrapper();
  __declspec(dllexport) ~WMIWrapper();
 
  __declspec(dllexport) wstring CreateCOM();
  __declspec(dllexport) wstring CreateService();
 __declspec(dllexport) wstring GetMonitors();
 
 private:
  IWbemLocator* _locator;
  IWbemServices* _service;
  IEnumWbemClassObject* _monitors;
 };
 
 #endif



WMIWrapper.cpp

 #include "WMIWrapper.h"
 
 
 extern "C" {
 
  WMIWrapper::WMIWrapper()
  {
  _locator = NULL;
  _service = NULL;
  }
 
  WMIWrapper::~WMIWrapper()
  {
  if(_service != NULL)
  _service->Release();
  if(_locator != NULL)
  _locator->Release();
  }
 
  wstring WMIWrapper::CreateCOM()
  {
  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;
  return L"";  
  }  
 
  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;
  return L"";
  }
 
  if(FAILED(hRes = CoCreateInstance(CLSID_WbemLocator, NULL, CLSCTX_ALL, IID_PPV_ARGS(&_locator))))  
  {  
  ERRStream << "Unable to create a WbemLocator: " << std::hex << hRes << endl;  
  return L"";  
  }
 
  const std::wstring& myWString = ERRStream.str();
  const LPCWSTR p = myWString.c_str();
  return p;
 
  }
 
  wstring WMIWrapper::CreateService()
  {
  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;  
  return L"";  
  }  
 
  const std::wstring& myWString = ERRStream.str();
  const LPCWSTR p = myWString.c_str();
  return p;
  }
 
  wstring WMIWrapper::GetMonitors()
  {
  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)))
  {
  //ERRStream << "Unable to retrieve desktop monitors: " << std::hex << hRes << endl;
  return L"";
  }
 
  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)
  {
  //std::wcout <<  L"Description: " << vRet.bstrVal << endl;
  ssMonitorDescription << "Description: " << vRet.bstrVal << endl;
  VariantClear(&vRet);
  }
  }
 
  clsObj->Release();
 
  return ssMonitorDescription.str();
  }
 }


Interface.cpp

 #include "WMIWrapper.h"
 
 extern "C" 
 {
  __declspec( dllexport ) wstring GetMonitor()
  {
  WMIWrapper* wmiWrapper = new WMIWrapper();
  wmiWrapper->CreateCOM();
  wmiWrapper->CreateServiceW();
  return wmiWrapper->GetMonitors();
  }
 }


Unity Script

 using UnityEngine;
 using System.Runtime.InteropServices;
 using System;
 
 
 public class HardwareDiagnostics : MonoBehaviour {
  
  //[DllImport("WMIWrapper", EntryPoint="CreateCOM", CharSet = CharSet.Unicode)]
  //static extern String CreateCOM();
  //
  //[DllImport("WMIWrapper", EntryPoint="CreateService", CharSet = CharSet.Unicode)]
  //static extern String CreateService();
  //
  //[DllImport("WMIWrapper", EntryPoint="GetMonitors", CharSet = CharSet.Unicode)]
  //static extern String GetMonitors();
  [DllImport("WMIWrapper", EntryPoint = "GetMonitor", CharSet = CharSet.Unicode)]
  static extern string GetMonitor();
  
  // Use this for initialization
  void Start () {
  Debug.Log(GetMonitor());
  Debug.Log ("Cock");
  
  }
  
  // Update is called once per frame
  void Update () {
  
  }
  
   
 }

So I'm trying to call those member functions from the Unity script and I'm getting the EntryPointNotFoundExeption error. I thought maybe it was because you couldn't export member functions, so I tried writing that "Interface.cpp" to execute those functions and return the result but that returns the same error.

UPDATE

Per suggestion I have changed my C++ functions to this format

 void WMIWrapper::CreateCOM(wchar_t* err, int errLength)
  {
  .../Determine wstringstream ERRStream

 
  wcscpy_s(err, errLength, ERRStream.str().c_str());
 
  }

And my C# like so:

 public class HardwareDiagnostics : MonoBehaviour {
  
  [DllImport( "WMIWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
  private static extern void CreateCOM(StringBuilder str, int length);
  
  [DllImport( "WMIWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
  private static extern void CreateService(StringBuilder str, int length);
  
  [DllImport( "WMIWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
  private static extern void GetMonitors(StringBuilder str, int length);
  
  // Use this for initialization
  void Start () {
  StringBuilder buffer = new StringBuilder(255);
  
  CreateCOM(buffer, buffer.Capacity);
  Debug.Log(buffer.ToString());
  
  CreateService(buffer, buffer.Capacity);
  Debug.Log(buffer.ToString());
  
  GetMonitors(buffer, buffer.Capacity);
  Debug.Log(buffer.ToString());
  
  }
  
  // Update is called once per frame
  void Update () {
  
  }
  
   
 }

HOWEVER, I'm still getting "EntryPointNotFoundExeption" when calling the first function, CreateCOM();

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

C++ plugin for Unity “EntryPointNotFoundExeption” 0 Answers

iOS Plugin - Pass a struct from C++ to C# 1 Answer

Multiple Cars not working 1 Answer

C++ Plugin for mipmapping and JPG encoding: viability 0 Answers

Distribute terrain in zones 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges