Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Need help with managed C++ dll so unmanaged C++ program can use third party c# dll

Need help with managed C++ dll so unmanaged C++ program can use third party c# dll

Scheduled Pinned Locked Moved Managed C++/CLI
helpquestioncsharpc++visual-studio
2 Posts 1 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    garyflet
    wrote on last edited by
    #1

    Using Windows 7 and VS 2010 (soon 2015). I’m writing a C++ managed code dll (managed.dll)which will be an intermediary between our unmanaged C++ code (program.exe) and a third party C# driver dll (tcbDriver.dll). I don’t have access to the code for tcbDriver.dll. However, in the following example of managed.dll code, I use a TcbDriver class which accesses the tcbDriver.dll. So program.exe calls "__declspec(dllexport) int ConnectTCB()" in managed.dll, which in turns calls Connect() in tcbDriver.dll. It works. The problem is, I don’t know how get the managed.dll code to preserve the same instance of "work" or "tcb" for other methods that program.exe will call. For example, in this case tcbDriver.dll will eventually make tcb.Initialized equal to "true", indicating it is done initializing the hardware. However, managed.dll needs to use the same instance of "work" or "tcb" in another exposed function that it used to call Connect(). The exposed function "__declspec(dllexport) bool IsInitialized()" makes a new instance, so tcbDriver.dll doesn't ever make tcb.Initialized equal to "true", even after TcbDriver is done initializing.

    namespace ManagedTCB
    {
    public ref class DoWork
    {
    TcbDriver::TCB tcb;
    public:int ConnectTCB()
    {
    try
    {
    tcb.Connect();
    }
    catch(...)
    {
    return 0;
    }
    return 1;
    }
    public:bool IsInitialized()
    {
    return tcb.Initialized;
    }
    };
    }

    __declspec(dllexport) int ConnectTCB()
    {
    ManagedTCB::DoWork work;
    return work.ConnectTCB();
    }
    __declspec(dllexport) bool IsInitialized()
    {
    ManagedTCB::DoWork work;
    return work.IsInitialized();
    }

    How do I use the same instance of the tcb class in different exported functions? Thanks for any help, Gary

    G 1 Reply Last reply
    0
    • G garyflet

      Using Windows 7 and VS 2010 (soon 2015). I’m writing a C++ managed code dll (managed.dll)which will be an intermediary between our unmanaged C++ code (program.exe) and a third party C# driver dll (tcbDriver.dll). I don’t have access to the code for tcbDriver.dll. However, in the following example of managed.dll code, I use a TcbDriver class which accesses the tcbDriver.dll. So program.exe calls "__declspec(dllexport) int ConnectTCB()" in managed.dll, which in turns calls Connect() in tcbDriver.dll. It works. The problem is, I don’t know how get the managed.dll code to preserve the same instance of "work" or "tcb" for other methods that program.exe will call. For example, in this case tcbDriver.dll will eventually make tcb.Initialized equal to "true", indicating it is done initializing the hardware. However, managed.dll needs to use the same instance of "work" or "tcb" in another exposed function that it used to call Connect(). The exposed function "__declspec(dllexport) bool IsInitialized()" makes a new instance, so tcbDriver.dll doesn't ever make tcb.Initialized equal to "true", even after TcbDriver is done initializing.

      namespace ManagedTCB
      {
      public ref class DoWork
      {
      TcbDriver::TCB tcb;
      public:int ConnectTCB()
      {
      try
      {
      tcb.Connect();
      }
      catch(...)
      {
      return 0;
      }
      return 1;
      }
      public:bool IsInitialized()
      {
      return tcb.Initialized;
      }
      };
      }

      __declspec(dllexport) int ConnectTCB()
      {
      ManagedTCB::DoWork work;
      return work.ConnectTCB();
      }
      __declspec(dllexport) bool IsInitialized()
      {
      ManagedTCB::DoWork work;
      return work.IsInitialized();
      }

      How do I use the same instance of the tcb class in different exported functions? Thanks for any help, Gary

      G Offline
      G Offline
      garyflet
      wrote on last edited by
      #2

      Actually, all I need to do is make the tcb variable static, as in static TcbDriver::TCB tcb; Gary

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups