Thread: Exporting VC++ classes for use with VB

  1. #1
    Registered User
    Join Date
    Jul 2003

    Exporting VC++ classes for use with VB

    I just started off in this kind of stuff, so I'm practically nowhere yet. I have several questions in mind, e.g.:

    a)if I need to export an object with events, does it necessarily have to be a control? Can't "plain" classes have events in C++?

    b)does my DLL have to be an automation server in order for it to export my classes?

    c)I'm very confused by the "MFC" stuff. Do I need it? I mean, in Visual Basic it was very easy to make a DLL that exposed classes (regular classes, not control classes). That is, no "visual" part. In VC++ I can't seem to get rid of MFC "base classes", so I end up with a control.

    Sorry for/if mixing up things, I shall soon split my problem into more clear parts, but at the moment I need to start somewhere.

    Thank you.
    Last edited by Helix; 12-28-2003 at 04:10 PM.

  2. #2
    Registered User
    Join Date
    Nov 2003
    1. No it does not have to be a control you can make a dll. If its a dll then it makes your life much easier to call events. I planned to do a control in c++ but it was too dificult so I am making a activex dll. A good place to start is at my post at if you want the answers to the 1 and 2 questions in that topic(the 2 at the end) just ask And i'll answer because its nothing like return this; return this; will return the error code and there is more than that. There are a few links there that may help you.

    if you are going to do a dll then you should look at the CallWindowProc() api function. I didn't fully code that in my dll so I don't know much about it. what I do know is that pass the address of a function from vb to c++ and save it in a variable e.g.

    in vb
    myclass.myfunction(addressof myvbfunction)

    then you can use callwindowproc(procaddresso, param1, param2, param3, param4) param1 is usually the hWnd of who you are sending it too but you can do anything. Param2 is usually the message, (events are all messages so far as I know) and param3 and 4 are just extra data.

    2) I don't know about that one read the tutorial in

    3) I also don't like the MFC wizard it gets annoying with lots of things it adds that you are not going to use. No you do not have to use it. I don't use it its just there by M$. Use the ATL COM appWizard it gets you ready with everything to create an activeX dll and doesn't add much of extra stuff that you won't use.

    Hope this helps!

  3. #3
    Registered User
    Join Date
    Jul 2003

    1)My question wasn't a DLL vs OCX but a generic class vs control class question (of course, depending on the answer I would then build a DLL or an OCX).

    The question was: can a generic class in VC++ have events and can I expose it to a VB app together with those events?

    You are suggesting subclassing in VB as an alternative to my problem, but actually subclassing is what I'm running from. Depending on how thorough your knowledge of VB and subclassing is, you might know that there's a huge limitation in using "AddressOf" operator in VB. So, Windows Messages are not the way to go.

    2)The problem is the following: as I see it, the natural way to work with events in VC++ is ActiveX Control Project and ClassWizard. ClassWizard will only work in MFC projects and only on controls.

    So, if I want a generic class to have an event and furthermore to expose it using Automation, I'd have to manually edit the event map, ODL file etc ... Right? Would someone please confirm that's possible.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing an Array of Strings from VB to a C DLL
    By mr_nice! in forum Windows Programming
    Replies: 9
    Last Post: 03-08-2005, 06:16 AM
  2. VC++6: exporting classes containing templates
    By ttt in forum Windows Programming
    Replies: 2
    Last Post: 09-15-2003, 11:38 AM
  3. Hai Everybody !VC dll in VB ?
    By samudrala_99 in forum Windows Programming
    Replies: 2
    Last Post: 06-20-2003, 07:22 AM
  4. Passing parameters from VB to C++ through ActiveX DLL
    By torbjorn in forum Windows Programming
    Replies: 0
    Last Post: 12-10-2002, 03:13 AM
  5. Exporting Object Hierarchies from a DLL
    By andy668 in forum C++ Programming
    Replies: 0
    Last Post: 10-20-2001, 01:26 PM