简体   繁体   中英

Using .NET dll via QT

I am hardly trying to use Laser Control dll file based on .NET on QT. I registered dll file on server, made tlb file, and imported it with using command

  #import "Litron.Control.CWLasers.tlb" no_namespace named_guids

after that, I used this command

struct cwDiodeLaserPIV;
cwDiodeLaserPIV Laser=NULL;
CoInitialize(NULL);
HRESULT hr = CoCreateInstance(CLSID_cwDiodeLaserPIV, NULL, CLSCTX_INPROC_SERVER, IID__cwDiodeLaserPIV, reinterpret_cast<void*>(&Laser));

*I added ActiveQT header file also to use CoCreateInstance

when i Check whether this code works with this,

if(SUCCEEDED(hr))
{ qDebug()<<"Calling dll is succeded"; }
else
{ qDebug()<<"Calling dll is failed"; }

"Calling dll is failed" is come out. But, When i use same code in Visual Studio C++, "Calling dll is succeded" is come out. furthermore, even calling dll is succeeded, I couldn't call the function of dll at VS.

Here are some Questions.

I used struct cwDiodeLaserPIV. because in tlh file, cwDiodeLaserPIV is declared with struct command. but actually, when i see the inner part of dll, cwDiodeLaserPIV was declared with class command. Why this happen? Can I use it with struct declaration?

When I write down the code at QT, CLSID_ and IID_ part, There were no directory that automatically connected. On the Other hand, at VS, CLSID_cwDiodeLaserPIV and IID__cwDiodeLaserPIV are automatically found by VS Say again, at QT, CLSID_cwDiodeLaserPIV and IID__cwDiodeLaserPIV are not found in list of directory that automatically connected when i write down CLSID_ or IID_. Why this happen? Can 't I use this way at QT?

++ I refered https://forum.qt.io/topic/108642/how-to-include-a-com-tlb-library-in-my-c-project/2 and made cpp and header file using dumpcpp. but it seems there aren't enough function in it.

I am such a vanilla on QT and Programming. So, example code would be very helpful Thanks very much...

CoCreateInstance is a sign that you're using COM. This is a technology that allows you to call C++ code from other languages and vice versa. The struct cwDiodeLaserPIV; you see in the .tlh is a C++ representation of the interface of a COM object. In other languages, other representations may be used. The DLL may be written in C# for instance, which could use the keyword class . COM is a glue layer that hides the implementation, but you probably want a second abstraction layer. Pure COM is tricky

The link you found describes a dumpcpp tool that's an alternative to the #import statement. Both are ways to ease the use of COM, but they indeed work differently. dumpcpp knows that it can use Qt library functionality in its implementation.

You can't freely mix the Qt dumpcpp approach and the Visual Studio #import approach. If you use dumpcpp , you must use the interface type that it generates.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM