Need help with managed C++ dll so unmanaged C++ program can use third party c# dll
-
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
-
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