-
August 28th, 2014, 06:32 AM
#1
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
-
August 29th, 2014, 12:34 AM
#2
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 12:45 AM.
Best regards,
Igor
-
August 29th, 2014, 03:38 AM
#3
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
-
August 30th, 2014, 03:58 AM
#4
Re: Create an MFC OCX using C++ DLL
Originally Posted by kpax1684
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
-
August 29th, 2014, 07:35 PM
#5
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
-
August 30th, 2014, 03:56 AM
#6
Re: Create an MFC OCX using C++ DLL
Originally Posted by Arjay
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. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|