PDA

View Full Version : use dll



MrShahi
23rd April 2008, 10:40
hello everyone,
I m trying to embed dotnet dll into my QWidget .but I have no idea how does it implement .........................
if anyone know please tell me ..........
I need your help ........
thanx in advance......:confused:

stevey
24th April 2008, 14:26
A .dot dll is not a standard dll, it's an "Assembly" which is a IL (intermediate language byte code), not something that can be loaded by the standard C++ load library calls.
Someone may have written a loader but it's not an out of the box option.

If you have the source code for the dll, then I'd reccomend adding "attributes to the class declarations and members you want "exported" making them COM ready, then use the Active Qt API to treat them like any other COM object. Find some tutorials on the COM on .NET stuff by searching for CCW (COM Callable Wrapper) and RCW (Runtime Callable Wrapper). I used this technique to create a Windows Explorer context menu shell extension in C#.

If you don't have the source code, then it'd be quite easy to create a .NET wrapper for the dll which does the above mentioned stuff. Create yourself a new "Class Library" project in Visual Studio, then add a "Reference" to the dll, include the namespaces from the external dll and you can wrap each public member into a COM callable class.


I m trying to embed dotnet dll into my QWidget
Are you trying to display ui controls on your QWidget? I'm not sure if it's that simple, maybe if the Control is defined as a COM object it will work, this will require some experimentation on your part.

stevey
24th April 2008, 14:35
Looks promising:

3. There is no problem embedding COM or ActiveX controls in Qt, even in the CE version. We have ActiveQt for that.
from http://blogs.msdn.com/mikehall/archive/2007/08/21/question-how-do-you-do-ui-development-on-windows-ce.aspx

As long as you expose your .NET classes (either by modifying the source or writing a wrapper) to COM you should be fine. I'd personally use the wrapper approach and subclass each class, but don't extend anything, just pass all parameters into the base class and add the member "Attributes" to expose to COM. The only issue here is you'll need to distribute 2 dlls with the project, if you want only one then merge the 2 into 1 using ILMerge from the Microsoft website.

I hope this helps.

stevey
25th April 2008, 02:10
Here's a good explanation on exposing the .NET interface to COM
Ignore the bit about Java, use QAxContainer

http://www.codeproject.com/KB/COM/javanet.aspx

stevey
26th April 2008, 11:58
I ran a test, I wrote a .net user control in C# and built it.

I then created a separate project with a "strong name" (Given that a .NET control to be exposed to COM needs to be registered in the Global Assembly Cache (GAC), it needs a strong name), but when you create a strongly named assembly in .NET, then every assembly referenced ALSO needs a strong name. You have 2 options, in the assembly you're trying to wrap, add a strong name ref to the project properties, but if you only have the dll and it isn't strongly named, you can't reference it from a strongly named project. So you need "Signer" from http://geekswithblogs.net/akraus1/archive/2007/01/23/104288.aspx which will disassemble the assembly to IL (Intermediate Language) sign it and re-assemble to a new DLL. You will then be able to add the reference.