Thread: can i create a DLL with a class interface?

  1. #1
    Registered User
    Join Date
    Aug 2013
    Posts
    430

    can i create a DLL with a class interface?

    can i create a DLL for i use the 'class' keyword on other languages?
    for i create a class on VB6(for exemple) using the C++ class interface.

  2. #2
    Registered User
    Join Date
    Dec 2010
    Location
    Shamokin PA (middle of nowhere)
    Posts
    145
    One can export an object of a C++ class from a dll, but there is no binary compatibility between different compilers - not even between different versions of the same make of a compiler, e.g., Microsoft Version 15 (VStudio 2008) and Version 19 (Visual Studio 2015). It might work; but there is no guarantee. The C++ Standard doesn't enforce the binary layout of an instantiated object.

    On the other hand, functions can be easily exported and there is total cross language compatibility. Any language capable of being used in this manner will have the syntactical capabilities of declaring functions in such a way that they can be imporrted. I have regularly done this between PowerBASIC and C++. In fact, a Win32 program can be written in PowerBASIC that looks almost exactly like its C/C++ Win32 counterpart - CreateWindowEx() and all. In that usage, PowerBASIC is importing functions from user32.dll. And the converse is also true. I can write functions in a PowerBASIC dll and import them into C++.

    All is not lost however in terms of the Object Oriented Programming paradigm. Objects can indeed be created within Dlls and exported for use by other programming languages - just not C++ Class based objects. That statement might cause you to wonder what other types of objects there are? Well, an alternate 'Object Model' from the C++ one was created many years ago by Microsoft known by the acronym COM - 'Component Object Model'. It is the basis for the Microsoft technology known as OLE - 'Object Linking And Embedding'. It also forms the underlying plumbing of .NET.

    What makes this possible is that the COM Standard predicates a strict binary layout, and it is that binary layout which allows any COM aware programming language to use binary objects written in any other COM aware programming language. Speaking personally, I've written an ActiveX Grid Control which I use in all my applications. I originally wrote the grid object using PowerBASIC, and I have used it in C++ apps and Visual Basic .NET apps. That was in the 32 bit world. Several years later when I started experimenting with 64 bit I redid the code in C++, and if I build it in x86 I can use it in PowerBASIC. So there is a lot of flexiblity.

  3. #3
    Registered User
    Join Date
    Dec 2010
    Location
    Shamokin PA (middle of nowhere)
    Posts
    145
    My recommendations Joachim would be to attempt to create a strict procedural implementation of whatever C++ code you have that you wish to use in VB6. Functions in a C++ dll could be exported and used fairly easily in VB6. However, be very careful of variable types. Whatever you do, don't create functions with C++ String Class parameters. That is an example of a variable type or 'object', if you will, that would totally bewilder Visual Basic. I'd be willing to help with this.

    The other alternative is to learn COM and create a COM Object out of your C++ dll code. Another name for this is an ActiveX Dll. The reason I don't recommend this is because I'm not sure just how much of your life you want to devote to this. COM is pretty difficult to learn. Its actually one of my favorite topics, but I've devoted years and years of my life to studying it. I'm not sure you want to do that.

    Most (all, essentially) C++ coders use ATL to create COM objects. I don't, but that's very unusual. If you wanted to create an ActiveX Dll out of your C++ code, you would likely want to use ATL. By doing that, your C++ ActiveX Dll would be registered in the Windows Registry, and it would show up for use in the Visual Basic 'References' Dialog Box. By selecting it, the methods of the object would show up in intellisense.

    Thing is though, don't get the idea that this would be some way of actually using your C++ Classes in Visual Basic 6. It wouldn't for the reasons I previously stated. The binary layout of most C++ Classes is not the same as the binary layout of a standard COM object. So if you have a C++ Class that works it would have to be reworked to some extent to create a 'real' COM object for use in VB6.

  4. #4
    Registered User
    Join Date
    Dec 2010
    Location
    Shamokin PA (middle of nowhere)
    Posts
    145

    continued

    One other possible thought would be to just call Win Api functions from within VB6 itself to do whatever your C++ code does that you wish to use. That can be done. I've called Win Api functions a pretty lot from VB6. Its been awhile, but I've done it.

    I'm actually amazed to find folks still using VB6. I was a big user of it all through the 1990s. When MS came out with .NET around 2001 I moved to C and PowerBASIC. PowerBASIC in particular is awesome. Big problem there is that the genius creator of it passed away unexpectedly couple years back, when he was in the process of reworking it to 64 bit. I still use it, but moved most of my coding over to C++.

  5. #5
    Registered User
    Join Date
    Aug 2013
    Posts
    430
    i'm sorry freddie. but i was been busy.
    i see that i can't use C++ class's, interface, on VB6... my objective is using derived class's on VB6. but VB6 it's too limited on it

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Appropiate class interface design
    By cminusminus in forum C++ Programming
    Replies: 3
    Last Post: 05-18-2010, 05:26 PM
  2. How to create a real interface??
    By wakish in forum C++ Programming
    Replies: 4
    Last Post: 10-22-2005, 04:33 PM
  3. difference between pure virtual class and interface
    By kmirza in forum C++ Programming
    Replies: 4
    Last Post: 05-19-2003, 05:03 AM
  4. Replies: 1
    Last Post: 04-20-2003, 05:02 PM
  5. How to create matlab/scilab-like interface...
    By Captain Penguin in forum C++ Programming
    Replies: 0
    Last Post: 10-09-2002, 06:44 PM

Tags for this Thread