I need to interface an old C application with C#.NET, I created a IJW C++
bridge, here is a sample code ......
#include "stdafx.h"
#include "MyCPPClass.Interop.h"
#pragma managed
#using <mscorlib.dll>
#using "MyCSharpAssembly.dll"
using namespace System;
using namespace System::Runtime::InteropServices;
using namespace MyCSharpAssembly;
void ExecuteManageCode(char *msg, char **errMsg)
{
try{
MyCSharpAssembly::CSharpClass *cSharpClass = new
MyCSharpAssembly::CSharpClass();
cSharpClass->set_Msg(msg);
cSharpClass->Execute();
}
catch(Exception *e){
*errMsg =
(char*)Marshal::StringToHGlobalAnsi(e->get_Message()).ToPointer();
}
}
#pragma unmanaged
extern "C" {
__declspec(dllexport) void __stdcall ExecuteUnManageCode(char *msg, char
**errMsg)
{
ExecuteManageCode(msg, errMsg);
}
}
The code works fine and my C application is able to execute the C#.NET.
However, I found some issues if my C#.NET uses STATIC methods. The first
execution works fine but the following executions "hangs". I know that the
memory created in the MANAGED section of my code is being release by the GC,
but what about STATICS? How the Application Domain boundaries are being
handle during this type of IJW technology? When is the memory used by those
STATICS being released? If I replace the code that uses the STATIC methods
my application will never experience the issue that ocurrs when the STATIC
methods are being used.
Thanks in advance
Willy Denoyette [MVP] - 20 Oct 2004 22:04 GMT
Please post a short and complete program that illustrates the issue.
Statics are released when the application exits.
Willy.
>I need to interface an old C application with C#.NET, I created a IJW C++
> bridge, here is a sample code ......
[quoted text clipped - 47 lines]
>
> Thanks in advance
Luis Fajardo - 21 Oct 2004 03:19 GMT
Thanks for the information about the Statics. Actually my problem was a
little deeper and nothing to do really with the Static itself. I ran onto
some threading problems that I got it to work.
Thanks
> Please post a short and complete program that illustrates the issue.
> Statics are released when the application exits.
[quoted text clipped - 51 lines]
> >
> > Thanks in advance