Passing a handle to a console application or managed / unmanaged help

Because of this, I have trouble sleeping! I have a VS2005 C # DLL that needs to communicate with a USB device under Labview. The C # DLL is mounted on top of the C ++ Wrapper, which is over a C ++ (unmanaged) project (not coded by me, but I have the code. Btw. C ++ and I, we are not best friends).

Using this shell, I can (under Windows / Visual Studio) do everything (connect, disconnect, send and receive data). The problem occurs in Labview. It connects, disconnects, sends files, but it does not receive (not very useful). I debugged the code, I know where the problem is, but I do not know how to fix it. (I could try to explain this)

Since I thought this was a longer way to fix an unmanaged library, I realized that by encoding a console application that handles the receiving procedure, I can jump over this problem. The Console application is called from a C # DLL as a process. In this process, it disconnects from the DLL, calls ConsoleApp, which connects again, requests the file, saves it to HD and disconnects. C # Dll restores and downloads a file.

As you might think, completion takes some long / impractical time. I thought of two options / questions:

Is there a way I could pass ConsoleApp an open link to Device (Handle, Ptr, or similiar as string arg) so that I would not need to connect again, but just request. How?

OR should it be easier for you to fix unmanaged code so that I don't have this problem and can work directly from the C # DLL?

Managed / Unmanaged looks something like this:

Packing: (wrapper.h)

public ref class Wrapper
{
public:
   Send(String^ mSendMessage);
   Parse(String^ mMessageString);
...
private:
   ComLayer* mComm;
   CInferface mInterface;
};

private class CInterface : public IIterface
{
public:
   virtual bool Deliver(CMessage mMessage);
...
private:
   gcroot<Wrapper^> mParent;
};

Packing (wrapper.cpp)

Wrapper::Send(String^ mSendMessage)
{
...
mComm->Send(mMessage);
}
Wrapper::Parse(String^ mMessageString)
{
...
}

CInterface::Deliver(CMessage* mMessage)
{
...
//Here, mParent value is empty under Labview, not while Debug/VS/WindowsForm
mParent->Parse(mMessageString)
}

unmanaged: (commLayer.h)

class CommLayer
{
public:
//Send:
   bool Send(CMessage* mMessage);
...
private:
//instead of CInterface, IInterface.
   IInterface mInterface;
};

unmanaged: (IInterface.h)

class IInterface
{
public:
//Response:
   virtual bool Deliver(CMessage mMessage);
};

The problem is that when unmanaged code calls mInferface-> Deliver (mMessage); There is no instance for mParent. Then in Wrapper mParent is empty (value = null?); This is similar to accessing methods from the unmanaged IInterface, not Wrapper ^ from the CInterface shell. Trying to evaluate mParent-> Parse will fail. Gcroot throws an exception from the GCHandle AppDomain application.

What should I do?

Thank!

+1
1

, , USB, LabVIEW TCP ( , ).

0

Source: https://habr.com/ru/post/1777033/


All Articles