I have created .Net usercontrol in C#. it is graphical control with a text box and listbox.
Now I want to use this control in legacy VC++ application.(native binary).
means I want to call manage code from unmanage code.
suppose my usercontrol name is xyz.dll.
I generated tlb file using tlbexp.exe and then i registered this control using below command line.
regasm xyz.dll /tlb:”C:\xyz.tlb” /codebase
I have checked my control using ‘Activex control test container’ (open studio 2005 and go to ‘tools’ menu)
I tested my .Net usercontrol on this tool and it worked fine.
then I created a sample C# window application. Under Toolbox, I right click and selected ‘Choose Items’ and selected
“COM component” tab. and choose my xyz.dll control.
now this contol is added into toolbox.
But when I drag this control onto window then i got below error.
Failed to create component ‘AxHost’. The error message follows:
‘System.Runtime.InteropServices.COMException (0x80029C4A): Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY))
at System.Windows.Forms.Design.DocumentDesigner.AxToolboxItem.CreateComponentsCore(IDesignerHost host)
at System.Drawing.Design.ToolboxItem.CreateComponentsCore(IDesignerHost host, IDictionary defaultValues)
at System.Drawing.Design.ToolboxItem.CreateComponents(IDesignerHost host, IDictionary defaultValues)
at System.Windows.Forms.Design.OleDragDropHandler.CreateTool(ToolboxItem tool, Control parent, Int32 x, Int32 y, Int32 width, Int32 height, Boolean hasLocation, Boolean hasSize, ToolboxSnapDragDropEventArgs e)’
.
also give me some pointer “how to use .net usercontrol into legacy C# application”
There is not enough information but my guess so far:
The Control is developed in .NET 4 and the legacy C# application is in .NET 2.
.NET 4 can mix .NET-version in the same process, but .NET 2 can’t so I suspect to solve this you need to develop/build the control in .NET 2 so that it is usable in .NET 2 & 4.
EDIT (after the comment about .NET 3.5):
You need to register the control by running regsvr32.
EDIT 2:
regsvr32 xyz.dllORregsvr32 /i xyz.dll