Trouble using .NET DLL in Borland C++ Builder 4

和自甴很熟 提交于 2019-12-11 08:35:25

问题


I have created a COM callable DLL in C# .NET 2.0 and created a TLB from the assembly using the .NET regasm tool.

In Borland C++ Builder 4.0 I go to Project->Import Type Library-> and find my DLL's type library there and click "Ok" to import it.

BCB creates an HardwareCheck_TLB.cpp & HardwareCheck_TLB.h file.

In a cpp file of the project I want to use the DLL I put: #include "HardwareCheck_TLB.h" at the top.

Then in code if I try to declare an object of that type in code: IHardwareCheck hc = new IHardwareCheck();

I get the following compiler error: [C++ Error] Unit1.cpp(22): E2352 Cannot create instance of abstract class 'IHardwareCheck'. [C++ Error] Unit1.cpp(22): E2353 Class 'IHardwareCheck' is abstract because of '__stdcall IHardwareCheck::IsExpress(wchar_t * *,TOLEBOOL *) = 0'.

Anybody have any ideas how to get rid of this error?

Thanks!


回答1:


COM clasess cannot be created using new. You need to use the CoCreateInstance system call (see MSDN) or some wrapper provided by Borland (such as the one mentioned by zer0_ring).




回答2:


It should generate some TCoClassCreatorT<> types that you can do a

CoHardwareCheck::Create(&hc)

You may have to look at the tlibimp.exe that Borland distributes with its products. I've gone through this before with that program but never was able to get the Co classes generated, maybe you'll have better luck.



来源:https://stackoverflow.com/questions/752828/trouble-using-net-dll-in-borland-c-builder-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!