Convert an in-process COM server to out-of-process - windows

I am currently using an in-process COM server (Outlook Redemption) in my application and I need to convert it to work out-of-process, I'm using C++ Builder.
From what I've read so far, I believe I need to create the new COM server as a .exe, but how do I do that? and how do I make all the the existing functions visible? Can that be done automatically via the existing TLB or do I have to create wrappers around all the functions that I will need?
Any guidance to put me on the right track would be really welcome.
Edit: If anyone is able to explain the process for Delphi instead, I'm sure I'd be able to adapt it.

Related

Windows: How to intercept Win32 disk I/O API

On Windows, all disk I/O ultimately happens via Win32 API calls like CreateFile, SetFilePointer, etc.
Now, is it possible to intercept these disk I/O Win32 calls and hook in your own code, at run time, for all dynamically-linked Windows applications? That is, applications that get their CreateFile functionality via a Windows DLL instead of a static, C library.
Some constraints that I have are:
No source code: I won't have the source code for the processes I'd like to intercept.
Thread safety: My hook code may dynamically allocate its own memory. Further, because this memory is going to be shared with multiple intercepted processes (and their threads), I'd like to be able to serialize access to it.
Conditional delegation and overriding : In my hook code, I would like to be able to decide whether to delegate to the original Win32 API functionality, or to use my own functionality, or both. (Much like the optional invocation of the super class method in the overriding method of the subclass in C++ or Java.)
Regular user-space code: I want to be able to accomplish the above without having to write any device-driver, mainly due to the complexity involved in writing one.
If this is possible, I'd appreciate some pointers. Source code is not necessary, but is always welcome!
You may want to look into mhook if Detours isn't what you want.
Here are a couple of problems you may run into while working with hooks:
ASLR can prevent injected code from intercepting the intended calls.
If your hooks are global (using AppInit_DLLs for example), only Kernel32.dll and User32.dll are available when your DLL is loaded. If you want to target functions outside of those modules, you'll need to manually make sure they're available.
I suggest you start with Microsoft Detours. It's free edition also exists and its rather powerful stable as well. For injections you will have to find which injection method will work for your applications in target. Not sure whether you need to code those on your own or not, but a simple tool like "Extreme Injector" would serve you well for testing your approaches. And you definitely do not need any kernel-land drivers to be developed for such a simple task, in my opinion at least. In order to get the full help of me and others, I'd like to see your approach first or list more constraints to the problem at hand or where have you started so far, but had problems. This narrows down a lot chit-chats and can save your time as well.
Now, if you are not familiar with Detours from Microsoft (MSFT) please go ahead and download it from the following link: http://research.microsoft.com/en-us/projects/detours/ once you download it. You are required to compile it yourself. It's very straightforward and it comes with a compiled HTML help file and samples. So far your profiles falls under IAT (Import Address Table) and EAT (Export Address Table).
I hope this non-snippet answer helps you a little bit in your approach to the solution, and if you get stuck come back again and ask. Best of luck!

Database password from VB6 application

I've inherited a Visual Basic 6 application that accesses a database directly, and I intend to rewrite it in Java.
However, something I NEED is the database user+password, which I believe is hard-coded into the application's source.
Unfortunately, I don't have access to it's source.
How could I retrieve the DB password? Is there a way to de-compile VB6 into some half-understandable form at least? or should I just log on and sniff it from my own PC?
I'd agree with MicSim that the DBA would be the person to ask.
However if you want to hack in to the source, you might have some luck just opening up the DLL (or EXE? OCX?) in a hex/text-editor and having a look through. If the credentials are really hard-coded into the application, presumably they're stored as strings... and I've noticed that strings tend to get stored in the assemblies created by VB6 in clear text.

Using MFC in Windows service?

I'm starting to develop a Windows service. I want to use some classes from my own, that has little dependencies to some MFC classes like CString, CSocket, CArchive, CMemFile and CObject. MSDN says you need to be very careful about which pieces of MFC you use in the Windows service, but don't specifies it and don't describes the problems that can occur.
My questions are:
what pieces of MFC can be used?
what problems can I expect, by using MFC?
which parts of Windows service are critical for MFC use?
is it advisable to use ATL instead of MFC for Windows service?
I'm not sure what they mean in teh MSDN article. As long as you don't use any of the GUI functionality you'll be fine - but that's a general design issue when developing services.
That being said, ATL has functionality specifically designed for building services IIRC so you may be better off using that.
To answer your questions (to the best of my knowledge):
1) the ones you specify are no problem.
2) I guess they mean synchronization issues with UI components. As long as you don't use any CWnd-derived classes you'll be fine.
3) don't understand the question.
4) See before, plus ATL is more lightweight so you'll have to distribute less, and provides build-in functionality that'll make it less of a pain to develop the service. See e.g. CAtlServiceModuleT. You'll still be able to mostly use your own classes, as CString is shared between MFC and ATL nowadays and ATL has classes for socket programming and memory file mapping itself. It doesn't have an equivalent for CArchive, and I'm not sure what functionality you use in CObject so I can't say whether there's an equivalent in ATL. So to conclude, I'd say 'yes' to this question.
(I know this answer is a bit late and this question was already answered but MFC in services is a sore spot for me...)
CSockets, far as I recall, require a Window. It makes an invisible one in the background. I found out this the hard way when I tried include some pre-exisiting MFC code into a windows service. Maybe this was only required if you accepted socket connection - I can't recall? But it did not work! (How exactly I wasted so much time doing this w/o realizing this limitation is a long story)
CObject? If you need the runtime class id stuff use RTTI (dynamic_cast, etc...)
CString, I like CString, I know it's shared with ATL now, not sure if you pull it in w/o MFC or ATL included... You could use std::string. Also, I recall someone created a derived std::string that provided the same methods as CString.
(EDIT: found the code - man!! that's a blast from the past...)
CArchive, CMemFile: do you really need these?
Anyway, as Roel said, ATL may be more helpful. I wouldn't use MFC in a server-side application (ever!) ATL? Maybe. If I needed COM, defiantly. No COM but for CAtlServiceModuleT, etc... maybe....
And another bad thing about MFC in services that I have just experienced while trying to turn a regular MFC-ATL app into a service: The use of AfxConnectionAdvise() is actually useless without a Window procedure. The threads in my service are just regular non message-pumping threads. I believe this is why I never get events fired from another COM server I have developed. That other COM server hangs on Fire_xxxEvent(), causing a big mess in the whole system.

Excel SheetSelectionChange event example needed

I have a problem I'm trying to solve involving interfaceing a C++ program with Excel (an import interface, specifically). The SheetSelectionChange sounds like it will get me most of the way to where I need to be, but I can't find any good documentation or examples on registering the event, using its Range parameter when it's fired, and unregistering when done. My code currently doesn't use the COM wrapper classes; it issues QueryInterface calls to pick up pointers to the interfaces in Excel.
You need to implement the Excel events interface, and then advise on the Excel connection point. Look at Office Automation Using VC++, more specifically point 7. You can also look at Handle Events for Excel using Visual C++.Net

Calling COM objects from a Firefox addon

I'm about to take on a project that requires a Firefox addon to issue call to COM dll's installed on the client Windows machine and I'm having a hard time estimating the complexity of this undertaking.
I have quite a bit of experience with COM, so I'm not frightened by it. I have less experience with Firefox addons, but I don't think that's where my problems are going to be.
Has anybody done anything like that?
Does Firefox allow its addons to communicate freely with the outside world?
Is there a plugin or sample code somewhere that does something like this (Google turned up little useful results)?
Update: Naturally, I would prefer a solution that doesn't require building an extension in C++, if that's at all possible.
Create an XPCOM in C++ to talk to your COM objects as usual. The XPCOM extensions can then be made available to Javascript to do the rest of the extension (GUI mainly, I guess). However, that's about all I understand about it :-)
You might be interested by IE Tab extension, which is open source. I haven't looked but I guess it does Com access to use IE's display.
If you do this you'll almost certainly need to use XPCOM. Take a look at Shanti Rao's JSDB, which supports COM/ActiveX within Javascript. The ActiveX stuff is in a file called wrap_com.cpp. It supports most IDispatch interfaces; the Invoke method of IDispatch is the magic that makes this work.
How complex this is depends on how "easy" you want this to be from Javascript. If you implemented an XPCOM thing called IDispatchObject where you had to pass in the names of methods & an array of arguments, then it's probably not too hard. If you want to create a general method for doing dynamic bindings to COM objects & referring to them directly, then that's tougher... not sure if the techniques used in JSDB will carry over to XPCOM.

Resources