How to be fired a event from C# to C, C++ , VB

L

lightdoll

hello everyone

i want to know how to make a event by C# like ATL Sink.

The Event will be fired to C, C++, VB.

this below is my code, so i want to append a event function.

Could you help me make a Event function?

Thank you.

namespace TestServiceComponet
{
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
[Guid("4b3b9bfe-304b-4a5c-ad7f-a1472fdcd41f")]
public interface ISingleton
{
int Foo();
bool Variant(object VarData);

}


[JustInTimeActivation]
[ObjectPooling(Enabled=true, MinPoolSize=1, MaxPoolSize=1,
CreationTimeout=5000)]
[Guid("e57cd005-f67e-44a0-99e4-9c1032c4420a")]
[ProgId("SomeOnes.Singleton")]
[ComVisible(true)]
public sealed class Singleton : ServicedComponent, ISingleton
{

public Singleton () {}
public int Foo()
{
return SingleInstance.instance.GetFoo();
}

public bool Variant(object VarData)
{
return SingleInstance.instance.Variant(VarData);

}
}

public sealed class SingleInstance
{
int i;
public static readonly SingleInstance instance = new
SingleInstance();
public SingleInstance(){}
public int GetFoo()
{
return ++i;
}

public bool Variant(object VarData)
{
/* int nTest;

string[] strTest = new string[3];
nTest = (int)((object[])(VarData))[0];
strTest[0] = (string)((object[])(VarData))[1];
strTest[1] = (string)((object[])(VarData))[2];
strTest[2] = (string)((object[])(VarData))[3];
Console.WriteLine("{0}, {1}, {2}, {3}", nTest, strTest[0],
strTest[1], strTest[2], strTest[3]);*/

// Console.WriteLine("{0}", (string)((object[])(VarData))[0]);
// MessageBox.Show((string)((object[])(VarData))[0]);
System.Diagnostics.Debugger.Break();
return true;
}


}
 
N

Nicholas Paldino [.NET/C# MVP]

lightdoll,

I can't say that this is the best idea, because of changes in the
context in COM+ and whatnot, as well, as lifetime, process management and
threading issues.

For example, if this is being hosted out-of-process, then marshalling by
reference for the event isn't going to be easy at all.

If it is in-process, then you have to worry about apartment issues and
interface marshaling.

I would recommend using loosely coupled events. It's more
implementation, but you will get around many of the issues inherent to
eventing in COM+:

http://msdn2.microsoft.com/en-us/library/ms682247(VS.85).aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top