473,414 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

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

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!
Apr 15 '09 #1
7 10195
weaknessforcats
9,208 Expert Mod 8TB
You cannot create objects of classes that have pure virtual functions.

You are supposed to create a derived object (which has no pure vrtual functions) and assign the address of that object to a base class pointer (like I HardwareCheck). Then you use IHardwareCheck->etc... to call member functions on that derived object.
Apr 19 '09 #2
Can you please provide an example of the syntax of creating such a derived class or at least a link which illustrates this?

Thanks!
Apr 19 '09 #3
weaknessforcats
9,208 Expert Mod 8TB
Here you go:
Expand|Select|Wrap|Line Numbers
  1. class Shape
  2. {
  3.     public:
  4.        virtual void draw() = 0;
  5. };
  6. class Circle : public Shape
  7. {
  8.      public:
  9.         virtual void draw();
  10. };
  11. void Circle::draw()
  12. {
  13.     cout << I am a Circle" << endl;
  14. }
  15.  
  16. int main()
  17. {
  18.     //Shape* s = new Shape;  //ERROR. Cannot create Shape objects
  19.     Shape* s = new Circle;
  20.     s->draw();   //calls Circle::draw()
  21. }
This is fundamental C++ polymorphism. Any C++ textbook will discuss this.
Apr 19 '09 #4
thank you I understand from back in college...

what I don't understand is which side do I do this on? Do I do it on the C# .NET side where my dll is written, or do I do it on the Borland C++ Builder side where I actually will be using the dll.

Have you ever actually done this before (i.e. used a C# dll with Borland C++ Builder)??

Thanks for all inputs so far.
Apr 19 '09 #5
weaknessforcats
9,208 Expert Mod 8TB
It looks like IHardwareCheck is an interface of a C++ COM class.

I assume you know how to use COM. If not, you have a big learning curve here. Especially since this uses non-virtual multiple inheritance

You create your COM object by calling CoCreateInstance with the GUID for your COM class and then use a call to QueryInterface using the GUID for IHardwareCheck. That should return a pointer to the IHardwareCheck interface. Now you can use IHardwareCheck methods.

This is all done on the C++ side.
Apr 19 '09 #6
The problem is in using the tlb created. Try using . It works with me.

//------------------Implementation Method1----------------------------

IHardwareCheckPtr pIDotnetObj;
pIDotnetObj = CreateComObject(CLSID_HardwareCheck);
pIDotnetObj->ShowDialog();

//--------------------Implementation Method2---------------------------


CoInitialize(NULL);

IHardwareCheckPtr pDotNetCOMPtr;
HRESULT hRes = pDotNetCOMPtr.CreateInstance(CLSID_HardwareCheck );
if (hRes == S_OK)
{
pDotNetCOMPtr->ShowDialog2();
}

CoUninitialize ();
Apr 20 '09 #7
Great thanks a ton for all the help given here.

I really appreciate it.

I was told before that you couldn't use a .NET DLL in Borland C++ Builder 4, but now this proves that person was wrong.

I bet the same could be done in Delphi 3 using the same .NET dll.
Apr 20 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: TGF | last post by:
I am wondering if it is feasible to use .NET for applications that have to be very fast. We have a few applications that are blazingly fast, written in Borland C++ using Borland C++ Builder. We...
17
by: Ziggi | last post by:
Hi. I want to get a C++ IDE, but I dont know whether to go for Bill Gate's solution or Borland's. Could any kind folks detail the relative strength and weaknesses of both, and also tell me which...
15
by: Chris | last post by:
I am just beginning programming again and need a bit of advice. I have both Visual C++ 6.0 Standard Edition and Borland C++ Builder 6. Of these two which do you consider the best for programming...
9
by: Christo | last post by:
hey im a student about to start a course in c++ at uni, we have been told to obtain a copy of borland c++ 5.01 (not c++ builder) this is just a program with a compiler/linker and development...
6
by: Verne | last post by:
Can anyone tell me where to look for some sample code programs for simple window developement by Builder 6 C++. I know the C++ fairly well but tryint to understand and learn how to use the...
4
by: Ramon F Herrera | last post by:
As many of you know, the Borland C++ Builder X IDE allows you to select from a wide variety of compilers for Windows, Linux and Solaris. So far, I have only used it under Windows, where I have 4...
22
by: smartwolf agassi via DotNetMonster.com | last post by:
I'm a C# language learner. I want to know which IDE is better for C# programing, Borland C#Builder or VS.net 2003? -- Message posted via http://www.dotnetmonster.com
6
by: TGF | last post by:
I am wondering if it is feasible to use .NET for applications that have to be very fast. We have a few applications that are blazingly fast, written in Borland C++ using Borland C++ Builder. We...
0
by: =?Utf-8?B?QWxleEU=?= | last post by:
We are using .NET (C#) and we added several COM dlls as Resources to our projects. These COM dll's were created using Borland C++ Builder 6. When we add any COMs built with Borland into our .NET...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.