Similar Threads:
1.Howto sink VB.NET event in VC6 class?
Hi,
I have defined a simple interface in VB.NET:
-----------
Public Interface iBrowser
Function SelectTemplate(ByVal ID As String, ByVal side As Boolean)
As String
Event MatchTemplate(ByVal ID As String)
End Interface
-----------
And a corresponding (dummy) class that implements the interface:
-----------
Public Class Browser
Implements iBrowser
Public Event MatchTemplate(ByVal ID As String) Implements
iBrowser.MatchTemplate
Public Function SelectTemplate(ByVal ID As String, ByVal side As
Boolean) As String Implements iBrowser.SelectTemplate
RaiseEvent MatchTemplate(ID.ToLower)
MsgBox(ID)
End Function
End Class
-----------
I'm using VS.NET 2003 to compile and make the class available for COM
interop. This works fine in the sense that I can create an instance of
the Browser class in VC6 and I can also call the SelectTemplate method
with success.
My problem is that I cannot figure out how to catch the MatchTemplate
event in VC6?
Any hints will be greatly appreciated!
Thanks in advance
Ulrik
2.Problem with Event sink (ATL C++) when the event source is a C# object
Hello everybody,
I need to send from a C# object events, that have to be caught
in my C++ code. I have followed the instructions from the MSDN article
"Raising Events Handled by a COM Sink", but I have a problem
when I call AtlAdvise in the C++ client: the method FindConnectionPoint
will fail with error CONNECT_E_NOCONNECTION (0x80040200).
So I suppose there is a problem with the connetion point map. I found
in another posting that the event instance name has to be the same as the
interface method, which I did, but with no result.
How can I solve my problem? Stupid ideea: is there any way to define
(correct)
manually the message map for the C# object, like it was possible in C++?
Many thanks for your help,
Cristian
3.Problem with Event sink (ATL C++) when the event source is a C# ob
Sorry, I forgot to mention that I am an MSDN subscriber, so I would
be pleased to see some "Microsoft" answers.
Regards,
Cristian Marinescu
"Cristian Marinescu" wrote:
>
> Hello everybody,
>
> I need to send from a C# object events, that have to be caught
> in my C++ code. I have followed the instructions from the MSDN article
> "Raising Events Handled by a COM Sink", but I have a problem
> when I call AtlAdvise in the C++ client: the method FindConnectionPoint
> will fail with error CONNECT_E_NOCONNECTION (0x80040200).
>
> So I suppose there is a problem with the connetion point map. I found
> in another posting that the event instance name has to be the same as the
> interface method, which I did, but with no result.
>
> How can I solve my problem? Stupid ideea: is there any way to define
> (correct)
> manually the message map for the C# object, like it was possible in C++?
>
> Many thanks for your help,
> Cristian
>
>
>
>
>
>
4.I implemanted Custom Event Schema, Custom Event Sink and I have a problem
## Event Schema
namespace MiMiC.EnterpriseInstrumentation.Schema
{
/// <summary>
/// Summary description for MiMiCEvent.
/// </summary>
public class MiMiCEvent : BaseEvent
{
public MiMiCEvent() {}
public DateTime m_timeLOG;
public string m_strEventSourceName;
public string m_strScheduleType;
public long m_lScheduleID;
public long m_lScenarioID;
public long m_lTargetID;
public string m_strLOG;
public override bool PrepareForSerialization(EventSource eventSource,
RequestContext requestContext)
{
if (!base.PrepareForSerialization(eventSource, requestContext)) return
false;
m_strEventSourceName = eventSource.Name;
m_timeLOG = DateTime.Now;
return true;
}
public static void Raise(EventSource eventSource, string strLOG)
{
if (eventSource == null) throw new ArgumentNullException("eventSource");
MiMiCEvent e = new MiMiCEvent();
e.m_strScheduleType = "NONE";
e.m_lScheduleID = -1;
e.m_lScenarioID = -1;
e.m_lTargetID = -1;
e.m_strLOG = strLOG;
eventSource.Raise(e);
}
public static void Raise(EventSource eventSource, string strScheduleType,
long lScheduleID, long lScenarioID, long lTargetID, string strLOG)
{
if (eventSource == null) throw new ArgumentNullException("eventSource");
MiMiCEvent e = new MiMiCEvent();
strScheduleType = strScheduleType.ToUpper();
if(strScheduleType.IndexOf("EMULATOR") != -1) strScheduleType = "QT";
if(strScheduleType.IndexOf("AGENT") != -1) strScheduleType = "LT";
e.m_strScheduleType = strScheduleType;
e.m_lScheduleID = lScheduleID;
e.m_lScenarioID = lScenarioID;
e.m_lTargetID = lTargetID;
e.m_strLOG = strLOG;
eventSource.Raise(e);
}
}
}
## Event Sink
namespace MiMiC.EnterpriseInstrumentation.EventSinks
{
public class MiMiCEventSink : EventSink, IEventContainerSink
{
[StructLayoutAttribute(LayoutKind.Sequential)]
public struct SECURITY_ATTRIBUTES
{
public uint dwSize;
public int lpSecurityDescriptor;
public bool bInheritHandle;
}
[StructLayoutAttribute(LayoutKind.Sequential)]
public struct SECURITY_DESCRIPTOR
{
public byte revision;
public byte size;
public short control;
public IntPtr owner;
public IntPtr Group;
public IntPtr Sacl;
public IntPtr Dacl;
}
[DllImport("kernel32.dll", SetLastError=true)]
private static extern UInt32 CreateMutex(ref SECURITY_ATTRIBUTES
SecurityAttributes, bool InitialOwner, string MutexName);
[DllImport("kernel32.dll", SetLastError=true)]
private static extern UInt32 OpenMutex(UInt32 dwDesiredAccess, bool
bInheritHandle, string MutexName);
[DllImport("kernel32.dll", SetLastError=true)]
private static extern bool ReleaseMutex(UInt32 hMutex);
[DllImport("Advapi32.dll", SetLastError=true)]
private static extern bool
ConvertStringSecurityDescriptorToSecurityDescriptor(string
StringSecurityDescriptor, UInt32 StringSDRevision, ref int
SecurityDescriptor, ref int SecurityDescriptorSize);
[DllImport("kernel32.dll", SetLastError=true)]
private static extern UInt32 LocalFree(UInt32 hMem);
[DllImport("kernel32.dll", SetLastError=true)]
private static extern UInt32 WaitForSingleObject(UInt32 hHandle, UInt32
dwMilliseconds);
[DllImport("kernel32.dll", SetLastError=true)]
private static extern bool CloseHandle(UInt32 hHandle);
private UInt32 CreateMutex_Wrap(bool initiallyOwned, string name)
{
UInt32 hResult = 0;
UInt32 SYNCHRONIZE = 0x00100000;
UInt32 SDDL_REVISION_1 = 1;
// UInt32 ERROR_ALREADY_EXISTS = 183;
// It's faster to first try OpenMutex
hResult = OpenMutex(SYNCHRONIZE, true, name);
if(hResult == 0)
{
SECURITY_ATTRIBUTES sa = new SECURITY_ATTRIBUTES();
sa.dwSize = (UInt32)System.Runtime.InteropServices.Marshal.SizeOf(sa);
sa.bInheritHandle = true;
sa.lpSecurityDescriptor = 0;
int securityDescriptorSize = 0; // dummy
bool result = ConvertStringSecurityDescriptorToSecurityDescriptor(
"D:(A;NP;0x001f0001;;;WD)", // Grant MUTEX_ALL_ACCESS
SDDL_REVISION_1,
ref sa.lpSecurityDescriptor,
ref securityDescriptorSize);
if (result == false) throw new Exception("Failure while creating
security descriptor for new mutex");
hResult = CreateMutex(ref sa, initiallyOwned, name);
// createdNew = (Marshal.GetLastWin32Error() != ERROR_ALREADY_EXISTS);
LocalFree((UInt32)sa.lpSecurityDescriptor);
}
return hResult;
}
private string m_strLogFilePath;
private UInt32 m_hMutex;
public MiMiCEventSink(IDictionary parameters, EventSource eventSource) :
base(parameters, eventSource)
{
if (parameters == null)
throw new ArgumentNullException("parameters");
m_strLogFilePath = parameters["LogFilePath"] as string;
m_hMutex = CreateMutex_Wrap(false, "MiMiCEventSink");
}
public override void Write(object eventToRaise)
{
throw new NotSupportedException();
}
[MethodImpl(MethodImplOptions.Synchronized)]
public unsafe void Write(EventContainer eventContainer)
{
if (eventContainer == null)
throw new ArgumentNullException("eventcontainer");
EventEntrySerializer serializer = new EventEntrySerializer();
eventContainer.Evaluate(serializer);
EventEntry evententry = serializer.GetEventEntry();
StreamWriter streamWriter;
string strTemp;
string strFilePath;
DateTime timeNow = DateTime.Now;
strFilePath = m_strLogFilePath + "_" +
String.Format("{0:0000}_{1:00}_{2:00}", timeNow.Year, timeNow.Month,
timeNow.Day);
strFilePath += ".log";
WaitForSingleObject(m_hMutex, UInt32.MaxValue); // UInt32.MaxValue ==
INFINITE
try
{
streamWriter = File.AppendText(strFilePath);
streamWriter.AutoFlush = true;
if(evententry.Type.ToString() ==
"MiMiC.EnterpriseInstrumentation.Schema.MiMiCEvent")
{
foreach(DictionaryEntry deOne in evententry)
{
if(deOne.Value.GetType().Name == "DateTime")
{
DateTime dtOne = (DateTime)deOne.Value;
strTemp = String.Format("{0:0000}-{1:00}-{2:00}
{3:00}:{4:00}:{5:00}",
dtOne.Year, dtOne.Month, dtOne.Day,
dtOne.Hour, dtOne.Minute, dtOne.Second);
}
else
{
strTemp = deOne.Value.ToString();
}
streamWriter.Write( "{0}\t", strTemp );
}
streamWriter.Write(streamWriter.NewLine);
}
streamWriter.Flush();
streamWriter.Close();
}
catch(Exception err)
{
throw err;
}
finally
{
ReleaseMutex(m_hMutex);
}
}
// Dispose of resources.
protected override void Dispose(bool disposing)
{
if (disposing)
{
// Free state-managed objects.
CloseHandle(m_hMutex);
}
base.Dispose(disposing);
}
}
}
######################################################
this work is fine,
but sometime lose custom event,
somebody help me
5.Handling events from .NET Components in unmanaged Event Sinks
Hello,
Can anyone tell me how handle events from .NET Components in unmanaged Event
Sinks or COM apps
Pooja Renukdas
6. Sinking events in IE script - Problem with .net 1.1 sp1
7. C# Remoted Event Source, COM Event Sink
8. Managed event source, unmanaged event sink