Yes, this is probably too long. Apologies in advance:
This is another iteration of my previous question which was specific to remote desktop.
We have an existing product consisting of many programs, which are built in (unmanaged) C. In the recent past we have started adding .NET (managed) applications to our product. A major part of our product is a proprietary interpreter, which can make calls into interface libraries to make interprocess calls into particular programs or to execute shared code. The linking to these interface libraries is by static linking rather than dynamic.
Recently we have added several interface libraries written in managed C. For example:
... managed C++ classes and code ...
extern "C"
{
using namespace BauerControls::BCXML;
__declspec(dllexport)
long BCXMLValidate // returns TRUE if the XML file is valid
(
char const * xml_file_name, // (in) XML file name
char const * xsd_file_name // (in) schema file name
)
{
long rc = TRUE;
… calls into the managed code to do the work…
return rc;
}
… other C callable functions go here…
} // end of extern “C”
In our unmanaged C code there is a header file that contains:
long BCXMLValidate // returns TRUE if the XML file is valid
(
char const * xml_file_name, // (in) XML file name
char const * xsd_file_name // (in) schema file name
);
And in at various places in our C code there will be calls to the the function
Return_Code = BCXMLValidate(xml_file_name, xsd_file_name);
Initially, for the developer of the code everything went just fine, everything compiled, linked and ran. Then after deployment things went to __. For some of the optional programs in our system, the load would fail. On certain machines none of the programs that linked to the managed DLL would load. The really interesting experiment involved using the remote desktop.
1) Install our product on a windows XP machine verify that it would run successfull on the local desktop. 2) connect to the XP machine via remote desktop. 3) start up our product through the remote desktop connection: you always get a total failure of our product. The error message is:
"The application failed to iniialize properly (0xc0000005). Click OK to terminate the application"
The one big clue is that if you do the same experiment, installing our system on a windows 7 machine, connect to it via remote desktop and start up our product, everything works properly. The only solution to the failure has been to change all of our programs so that they are started up as managed code which in turn calls the entry point of the unmanaged C. While this works and appears to fix all the failure cases, it just seems WRONG:
// new startup code written in managed C++
using namespace baimain;
extern "C" {
extern int BaiMain (void); // the entry of unmanaged code
} // extern "C"
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // pointer to command line
int nCmdShow // show state of window
)
{
winmain ^rm = gcnew winmain ();
rm->enter (hInstance, hPrevInstance, lpCmdLine, nCmdShow);
return 0;
}
namespace baimain {
// the constructor
winmain::winmain(void)
{}
// the enter method that calls the entry point of the unmanaged code
int winmain::enter(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // pointer to command line
int nCmdShow // show state of window
)
{
long rc;
hInstance = hInstance;
hPrevInstance = hPrevInstance;
lpCmdLine = lpCmdLine;
nCmdShow = nCmdShow;
rc = BaiMain();
return((int) rc);
}
}