Implementing a custom interface in a COleControl using MFC - c++

I'm trying to implement a plugin for a customer who has an interface defined in a TLB file, which they use to get video from my system.
I've got an ActiveX control based on COleControl, which needs to implement this interface, but am having trouble figuring out how to do it correctly. I'm using DISP_FUNCTION_ID and DISP_PROPERTY_ID to hook up methods/properties to the dispinterface in the TLB, but can't figure out how to register that my class is implementing the interface so that QueryInterface will pick it up.
I'm kinda new to the whole COM thing, so please be gentle, but any help would be greatly appreciated :)
Cheers,
Callum

TLB file is giving you the definition for Development. To register the component you actually need the COM dll. To register the DLL you need "REGSVR32" command (http://ss64.com/nt/regsvr32.html). If you are not able to create your class as part of COM Library you can refer the example http://www.codeproject.com/KB/atl/SimpleATLCom.aspx, This will give you simple COM object.

Related

function call(methods) between native and managed C++

I am new to .Net and hitting the brick wall trying to resolve this....
Having done enough googling for the past few days I've come across nothing but some vague (at lease for me) C# related info
Basically, I am trying to set up a few global hooks to carry out certain automation process. Since the development environment is VS2008 C++ windows forms, I started by compiling a native Dll to be injected by the calling prog. The strategy being for the callback proc in native dll calling a function in .Net program (or maybe a wrapper managed dll), passing the filtered raw data (keyboard/mouse/WM_create/etc) messages for further processing.
Question: How do I pass on the handle of such function(s) to my injected dll?
Is the managed wrapper dll path an easier choice or simply have the managed & native functions residing side by side in the main application?
I'll have to do a lot of Marshalling which is yet another dark side of the matter. Is there a link to precise documentation/examples of marshalling functions?
I thank you for your help in advance.
Mark
Have a look at 'Marshal.GetFunctionPointerForDelegate'

What is the easiest way to create a simple COM object in VS2010 using native/C++ code?

This is a followon to a prior question I posted (see here). I'm trying to call my native/C++ code from Javascript running in an HTML page. The answer in the referenced question was to create a COM object. The Javascript can then create an instance of the COM object and invoke methods on it getting to the native/C++ code.
So now I'm left with trying to create a simple COM object to accept the call from the Javascript. It looks like the way to go is to create a DLL and put the COM object in that DLL. Years ago I did tons of reading on COM and have tried to forget it since then :) Now I'm getting a headache wondering how to go about this easily without becoming an expert in COM.
Is there a simple/easy way to setup a DLL with a COM object that you would recommend?
EDIT: My application is written using native C++/Win32/MFC. I have an MFC dialog which uses the IE ActiveX browser control to render locally generated HTML. Currently the button handler code is all in Javascript, but as you can see from the referenced question, my goal is to handle it on the C++ side.
As I know the easy and fast way to create COM objects is to create an ATL project.
here's a nice tutorial that explains the steps to follow.

Is there any method of accessing a remote filter graph without registering proppage.dll on Windows Vista+?

I'm currently attempting to developing a small application / dll that will read a remote directshow filter graph and glean information from it for display in a "now playing" style plugin or script. After a few days of reading and subsequent testing, I realized that after getting the filter graph address from the ROT I was failing to convert it from the IUnknown interface pointer to IFilterGraph until I had registered "proppage.dll" which came with Windows SDK.
So what I am asking is, is there no other way to glean any information from a remote filter graph without having to register proppage.dll?
You can't call a COM interface from another address space unless you marshall the interface pointers and parameters/return values to and from the other process. For COM, you need to register a marshalling object for each interface that you want to be able to use cross-process. The standard implementation for that is in proppage.dll.
I don't think there is a simple way to access the interface without providing marshalling. If you don't want to use proppage.dll, you can build marshalling code from the IDL files supplied with the SDK and compile that into your own app.
G

How can I keep track of ActiveX controls created by a process?

I'd like to keep track of the ActiveX controls created by some process. To simplify the problem, I'd first like to monitor the current process only. I want to do this so that I can check whether any ActiveX control supports IOleWindow and if so, whether a given HWND belongs to that ActiveX control (so that I can map HWNDs to ActiveX controls).
Does anybody have experience with this? My first idea was to use API hooking to monitor CoCreateInstance invocations, but I read that this doesn't work in all cases. Some Google research revealed http://www.pocketsoap.com/sf/activation.html which talks about installing a custom class factory - how would this work?
You may find you can find out what you need to know using the UI Automation and Active Accessibility APIs:
http://msdn.microsoft.com/en-us/library/dd317978(VS.85).aspx
If you are sure you need to do this, be aware of the following. CoCreateInstance is essentially a convenience function, which wraps CoGetClassObject and IClassObject::CreateInstance.
If you are going to use that technique you will therefore have to hook CoGetClassObject too, as the process may use it directly.
And of course there is no law saying any library or DLL cannot provide it's own convenience functions which bypass the COM registry altogether. The registry itself is a convenience - if you know where the DLL is you can use LoadLibrary, GetProcAddress to find DllGetClassObject and retrieve the class object without involving the COM libraries, and indeed without the DLL being registered at all.
I ended up hooking CoCreateInstance and CoGetClassObject to track all COM objects being created.

Automating VB6 application with ActiveX controls

I have a VB6 application that I don't have source code. This application uses third-party ActiveX controls. I want to automate these ActiveX controls. Is it possible to get the IUnknowns or Object references? For some of these, I can get the underlying HWNDs, but from what I can tell there isn't a generic way to convert these HWNDs to the ActiveX control.
Some testing software allows you to script VB6 applications with ActiveX controls. How do they do it?
Are these ActiveX controls in a separate DLL? If so, you can use OLE View (an VS 6.0 tool) to open the dll and view all the interfaces, coclasse and etc.
You might be able to using DLL injection via Microsoft Research Detours library. Basically you'd want to hook the cocreate for those specific controls. You will need to be ultra careful especially if you do anything cross-thread/cross-process (COM threading rules are vitally important).
On whole Detours is easy to use... but I've never tried it with COM routines. You might want to look at a different solution.
Also note that Detours has some licensing restrictions on it that may affect your ability to distribute it.
Testing software may well just send the appropriate WM_XXX messages to the particular windows in question (eg. WM_MOUSEMOVE).
Sorry to say but the VB6 EXE don't contain the manifests needed to pull out the COM objects it uses. You best bet is trying some of rbobby's suggestions especially about sending WM_XXX messages.