Create an MFC OCX using C++ DLL
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Create an MFC OCX using C++ DLL

  1. #1
    Join Date
    Oct 2010
    Posts
    43

    Question Create an MFC OCX using C++ DLL

    Hello Guru's

    Im am a newbie here trying to create a OCX from a C++ dll., Here's the scenario
    I have a C++ dll and this dll needs to be called in VB.net program my boss want's me to create an OCX out of this
    C++ dll and use it in a VB.net class library, apparently I have created an OCX but it requires a form but the VB.net program is a class library.

    Any one there can help me here.,


    Regards,
    Newbie here

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,070

    Re: Create an MFC OCX using C++ DLL

    OCX you mention here is just an alias to ActiveX term, which in its turn is an alias to COM in-proc server. So let's talk a bit about COM in-proc servers.

    COM is Windows way to bring OOP to languages including ones not supporting OOP natively, and provide cross-language use of components doing that some standard way. In COM world server exposes a number of coclasses, each of ones exposes a number of interfaces where each one exposes a number of methods and properties. Internally those may be implemented in any language that is able to build native Windows DLLs.

    From C++ perspective COM DLL is a regular C/C++ DLL that follows COM programming guidelines. Internally it makes use of C++ classes and exposes their member functions and data via COM methods and properties respectively, but transposing internally used C++ data types to COM data types. Additionally it takes care of internal C++ object life cycles to comply with COM object life cycles.

    There is one more point here you are to take into consideration. COM DLL may implement dual DLL interface, including both COM specific and usual C++ exports, or may implement only COM and link to external C++ DLL making use of the latter. Remember that COM DLL is just a regular DLL with some standard exports, so it is allowed do all the things that any regular DLL does.

    In case you have no idea about COM programming, I have bad news for you: it's not something trivial, and you have to gain some experience first. Exposing COM to .NET is another knowledge you are to gain.
    Last edited by Igor Vartanov; August 29th, 2014 at 01:45 AM.
    Best regards,
    Igor

  3. #3
    Join Date
    Oct 2010
    Posts
    43

    Re: Create an MFC OCX using C++ DLL

    Hello Igor:

    Thanks for the clear distinction of the COM interface, YES you are right I don't have enough knowledge about the COM,.. Any link for the tutorial would help me gain knowledge.
    As I mentioned my goal is to create an ActiveX(.OCX) or a COM interface coming from the C++ dll.

    If you someone can give me some trick how to do it and I would gladly appreciate it.

    Regards,
    Newbie here

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,480

    Re: Create an MFC OCX using C++ DLL

    If you want to do this in 32-bit, I suggest you create a ActiveX control rather than the older OCX control.

    As Igor mentioned, programming in COM isn't trivial, but in my opinion a good way to get up to speed with a usable control is to use ATL.

    A good book (albeit a bit dated) is: Beginning ATL 3COM Programming

  5. #5
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,848

    Re: Create an MFC OCX using C++ DLL

    Quote Originally Posted by Arjay View Post
    If you want to do this in 32-bit, I suggest you create a ActiveX control rather than the older OCX control.

    As Igor mentioned, programming in COM isn't trivial, but in my opinion a good way to get up to speed with a usable control is to use ATL.

    A good book (albeit a bit dated) is: Beginning ATL 3COM Programming
    You might also want to have a look at MS Inside ATL
    http://www.amazon.co.uk/Inside-ATL-P...tl+programming

    There are several books that cover ATL/COM/ActiveX etc. I would suggest that you do a search on Amazon and consider the content and the reviews to choose one suitable for your requirements. Some are quite dated (from 1998/1999/2000) but their content is still relevant.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  6. #6
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,070

    Re: Create an MFC OCX using C++ DLL

    Quote Originally Posted by kpax1684 View Post
    YES you are right I don't have enough knowledge about the COM,.. Any link for the tutorial would help me gain knowledge.
    I don't think I could recommend anything better than what plain google search would do. I believe, MSDN, and CodeGuru, and CodeProject sites are good to start with.
    Best regards,
    Igor

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center