c# - Calling .NET dll from native C++ -


i have problem calling .net dll (mclnet.dll) using com wrapper. third part dll not have source code of. want use mclnet.dll in pure native c++ application, developing c# wrapper. mclwrapper.dll, makes methods in mclnet.dll visible. here did:

  • in mclwrapper.dll, added mclnet.dll reference, define interface make mclnet.dll methods visible. here of code:

    using system;             using system.collections.generic;             using system.linq;             using system.text;            using mclnet;         namespace mclwrapper        {                  public interface mclcontrol                  {                           void mclconnect(string serialnumber);                           void mclset_switch(string switchname, int val);                           void mcldisconnect();               };       public class mclcontrolclass:mclcontrol      {          private usb_rf_switchbox _sb = new usb_rf_switchbox();           public void mclconnect(string serialnumber)          {                          _sb.connect(ref serialnumber);          }           public void mclset_switch(string switchname, int val)          {              _sb.set_switch(ref switchname, ref val);          }           public void mcldisconnect()          {              _sb.disconnect();          }      }  } 

and assemblyinfor.cs mclwrapper.dll:

using system.reflection; using system.runtime.compilerservices; using system.runtime.interopservices;  // general information assembly controlled through following  // set of attributes. change these attribute values modify information // associated assembly. [assembly: assemblytitle("mclwrapper")] [assembly: assemblydescription("")] [assembly: assemblyconfiguration("")] [assembly: assemblycompany("")] [assembly: assemblyproduct("mclwrapper")] [assembly: assemblycopyright("copyright ©  2013")] [assembly: assemblytrademark("")] [assembly: assemblyculture("")] //[assembly: assemblykeyfile("..\\mclwrapper.snk")]   // setting comvisible false makes types in assembly not visible  // com components.  if need access type in assembly  // com, set comvisible attribute true on type. [assembly: comvisible(true)]  // following guid id of typelib if project exposed com [assembly: guid("14fa8796-ee52-4e39-8481-f893ad92bb68")]  // version information assembly consists of following 4 values: // //      major version //      minor version  //      build number //      revision // // can specify values or can default build , revision numbers  // using '*' shown below: // [assembly: assemblyversion("1.0.*")] [assembly: assemblyversion("1.0.0.0")] [assembly: assemblyfileversion("1.0.0.0")] 
  • then after built wrapper.dll, registered using regasm command, generate .tlb file

  • then in native c++ application, imported tlb file, , tried use wrapper.dll referred net.dll. here code in native c++ application:

    #include "stdafx.h" #include "math.h" #include "detectorswitch.h" #include "detectorswitchsetupxml.h" #include "oleauto.h"  #import "c:/mypath/mclwrapper.tlb" raw_interfaces_only     wchar_t message[256]; using namespace mclwrapper;  long detectorswitch::finddevices(long &devicecount) {     long ret = true;      devicecount=0;         hresult hcoinitialize = coinitialize(null);      mclcontrolptr myswitch(__uuidof(mclcontrolclass));      hresult hconnet = myswitch->mclconnect(_sn);    // connect sc      short output  = 1;     myswitch->mclset_switch(&_a,&output);  } 

now problem is, not recognize myswitch->mclset_switch(&_a,&output) function, means, mclnet.dll not exposed native c++ code yet.

i wondering problem here? how can chance correct it? how can call .net dll in native c++ application? many front.

#import <mscorlib.tlb> raw_interfaces_only #import c:/mypath/mclwrapper.tlb" no_namespace named_guids 

try above mentioned import statements - works me , call .net code without namespaces native c++.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -