Why is my MTS object access violating when I install it in COM+?

By: mykle hoban

Abstract: This article describes how to fix access violations caused when installing transaction objects in COM+


Why won't my MTS Transaction object run in COM+? It's always getting access violations and things like that.


There is a little problem in the mtshlpr.cpp file that handles loading COM+ objects. I will show you how to make minor changes and compile that file back into your project to fix these errors.

The changes themselves are relatively simple, but there are a couple of other things you need to do to get it to compile. I recommend that you make copies of the mtshlpr.cpp, mtshlpr.h, and mtshlpr.res files that are local to your project (e.g. do not change the ones that are in source\vcl). The following changes are all within the HRESULT TMtsDll::Get_ObjectContext(IObjectContext** ppInstanceContext) function:

Change the line: TDllStdProc2 BGetObjectContext(*Library, _T("CoGetObjectContext")); /* do not localize */
to: TDllStdProc2<REFIID, LPVOID *> BGetObjectContext(*Library, _T("CoGetObjectContext")); /* do not localize */
and the line: hr = BGetObjectContext(IID_IObjectContext, ppInstanceContext);
to: hr = BGetObjectContext(IID_IObjectContext, (void **)ppInstanceContext);

At the very top of the mtshlpr.cpp file, you will need to remove the reference mtshlpr.rh (it doesn't exist) and after the #pragma resource... line add the following
#define sInitMTSServicesError 310
#define sLoadMTSServicesError 320
#define sLocateMTSServicesError 330
These are resource strings that are needed.
Finally, in your **Impl.h file (generated by the IDE), you'll have to change
#include <vcl/mtshlpr.h> to
#include "mtshlpr.h"
That's all, now add the files mtshlpr.cpp and mtshlpr.res to your project, and rebuild it and install the object in COM+, it should work fine.

Server Response from: ETNASC03