This solution requires users to install a client (actually a COM server component) on local machine. Browser communicates to this COM server by using ActiveX objects to get all application details from Terminal Server. When I said ActiveX, it meant this can only happen in Internet Explorer browser! Yes, that’s what the problem was…it only supported IE. The reason was some JavaScript code that creates ActiveX objects for communication with locally installed COM server component. For years, this cool product was only supported on IE – sad.
Someone from us then thought of a different approach –Remove ActiveX objects!
The solution was to use applets, JNI(Java Native Interface) and convert the ActiveX part of processing to a DLL (that will be consumed by applet through JNI). This DLL will act as client to the COM server component installed locally.
(I did not had the source code of this COM server component).
There are more than one way to invoke methods in COM server, like (that I know)
a) by importing .tlb file of the COM server (if you have)
b) using IUnknown interface (you need .idl file of COM server)
I did not had .tlb file, neither I had .idl file.
Then I came to know about OLE-COM Object Viewer tool that ships with Windows SDK.
(click to enlarge)
If your COM server is registered(it should be registered if someone wants to use it), you can see your COM server listed in OLE-COM Object Viewer’s ‘Type Library’ section and can create .tlb or .idl files from there. I was not lucky enough to get that done, there was some error popping-up due to some section missing in the COM server.
(click to enlarge)
I manually created .idl file by copying the entries in different sub-sections of OLE-COM Object Viewer into that file. A sample .idl file looks like –
[
uuid(CE3AA854-5337-4EA6-ABC7-EF843DA87620),
version(1.0)
]
library IQCLNTMGRLib
{
importlib("stdole32.tlb");
[
odl,
uuid(C55E6C38-1BC9-4489-9824-F42B868DFAB9),
helpstring("ILaunchpadMgr Interface"),
dual,
oleautomation
]
interface ILaunchpadMgr : IDispatch {
HRESULT GetDefaultLaunchpadPrefs(
[in] unsigned long dwLaunchpadId,
[out, retval] BSTR* pbstrPrefsAsXML);
[id(0x0000000a), helpstring("method GetDefaultLaunchpadPref")]
HRESULT GetDefaultLaunchpadPref(
[in] unsigned long dwLaunchpadId,
[in] BSTR bstrPrefName,
[out, retval] BSTR* pbstrPrefValue);
[id(0x0000000b), helpstring("method SetLaunchpadPrefs")]
HRESULT SetLaunchpadPrefs(
[in] unsigned long dwLaunchpadId,
[in] BSTR pbstrPrefsAsXML);
[id(0x0000000c), helpstring("method SetLaunchpadPref")]
HRESULT SetLaunchpadPref(
[in] unsigned long dwLaunchpadId,
[in] BSTR bstrPrefName,
[in] BSTR bstrPrefValue);
[id(0x0000000d), helpstring("method ReconnectSession")]
HRESULT ReconnectSession(
[in] BSTR bstrInParams,
[out, retval] BSTR* pbstrOutParams);
[id(0x0000000e), helpstring("method GetVersion")]
HRESULT GetVersion([out, retval] BSTR* pbstrVersion);
[id(0x0000000f), helpstring("method UpgradeRequest")]
HRESULT UpgradeRequest([out, retval] long* pbIsSafeToUpgrade);
};
[
uuid(7A950C02-9DE8-4718-A53C-30B8F82DBBE7),
helpstring("LaunchpadMgr Class")
]
coclass LaunchpadMgr {
[default] interface ILaunchpadMgr;
};
};
You need to include this .idl file in your project, build it. It will auto generate a .h and .c/.cpp file, that you need to include in your project.
Next, you need to call “CoInitializeEx”, create instance, and use IUnknown interface to query the pointer to COM interface. There you are! Now you can see all available methods in the intellisense and can invoke each method
CoInitializeEx(NULL, COINIT_MULTITHREADED);
IUnknown* pUnknown = 0;
ILaunchpadMgr* pLaunchpadMgr = 0;
MULTI_QI rgmqi[1];
ZeroMemory(rgmqi, sizeof(rgmqi));
rgmqi[0].pIID = &IID_IUnknown;
HRESULT hr = CoCreateInstanceEx(
CLSID_LaunchpadMgr, NULL, CLSCTX_LOCAL_SERVER, NULL, 1, rgmqi);
if (hr == S_OK)
pUnknown = (IUnknown*)rgmqi[0].pItf;
else
{
return 0;
}
hr = pUnknown->QueryInterface(IID_ILaunchpadMgr, (void**)&pLaunchpadMgr);
if(FAILED(hr))
{
return 0;
}
hr = pUnknown->Release();
Note: Use BSTR only instead of any char* string or CString.
You need to compile this .idl file to generate class files (.cpp and .h files)
Next, you can call any function inside the COM.
Feel free to suggest enhancements, clarify confusions. Anyone can ask for sample code.