.NET event, VC6 sink, problems with event parameters

dotnet framework

    Next

  • 1. Can not find Microsoft.office.introp VERSION=12
    I try to test the new version of VSTO (for office 2007), but I didn't have the PIA for the office 2007 version. Did anybody knows where I can find them? Thanks
  • 2. Cannot create ActiveX object (on Windows 2000)
    I have made a small interop function that uses Acrobat Distilr. It works smothly on all the XP machines, but when I try to run it on a Windows 2000,I get this error: System.Exception: Cannot create ActiveX component. at Microsoft.VisualBasic.Interaction.CreateObject(String ProgId, String ServerName) at MediaBuilder.Utils.PDFCreator.PDFCreator.Main(String[] args) in C: \Visual Studio Projects\Utilities\PDFCreator\Main.cs:line 31 And line 31 looks like this: objDist = (ACRODISTXLib.PdfDistiller) Microsoft.VisualBasic.Interaction.CreateObject ("PdfDistiller.PdfDistiller",""); What is the difference between running this under XP and 2000? The odd thing is, that I can compile it with out errors on the 2000, it is just when I run it, I get this error.
  • 3. unzip using the shell folder extension
    I want to unzip files without having to use a third party library, i.e. I want to use the XP/Win2k3 built in functionality for reading data from a zip file. I was hoping that SHFileOperation would let me get easy access to zip files but apparently not. Does anyone have a sample how to plug into Windows built in zip folder handling just to read from a zip file?
  • 4. value from C# to c++/MFC
    Hi, I have application in c#, which store data buffer of 256, I have other application running on same computer which is in c++/MFC. I wanted data buffer of C# in c++/MFC software, this buffer changes frequently, what is best approch ?? how ?? Thanks in advance

.NET event, VC6 sink, problems with event parameters

Postby Eric Brandt » Sat, 27 Sep 2003 00:35:49 GMT

Hi-

We have some .NET code that generates an event. The 2nd parameter of the
event is a C# class we derived from EventArgs.

A VC6 C++ client is subscribing to the event, we are using the
IDispEventImpl<> template in ATL, and have specified the
ComSourceInterfacesAttribute on our event generating class, as well as the
InterfaceTypeAttribute(InterfaceIsIDispatch) on our dummy interface for the
event in C#.

We are getting the callback made into C++ with no problem. The problem
occurs when we try to call a method of our EventArgs-derived parameter to
the event callback. When we make a call to say,
get_Name(&bstr); on our EventArgs-derived class in the C++ callback ('Name'
is a property in our EventArgs derived class) we get the following error
from the VC6 de{*filter*}:

"The value of ESP was not properly saved across a function call. This is
usually the result of calling a function declared with one calling
convention with a function pointer declared with a different calling
convention"

I have tried various settings in Project->Settings->C++->Code
Generation->Calling Convention, with no differences in behavior.

When our test app is in VB6 instead of VC6, we can access the parameters's
methods/properties with no problesm from within the event's callback
function.

Another note, when we implemented this event as a dual interface, and
received it in VC++ via a custom interface (rather than IDispatch), I am
pretty sure we were able to access the parameters methods and properties
with out the above crash. the problem, of course, is that with our COM
interface declared as Dual rather than IDispatch, we were unable to receive
the event in VB6.

Sorry for the long post, but there's no easy way to describe the problem.
Can anybody pinpoint what we are doing wrong so that we can access the event
parameters from C++?

Thanks in advance,
Eric.



Re: .NET event, VC6 sink, problems with event parameters

Postby Vadim Melnik » Sat, 27 Sep 2003 03:36:12 GMT

Hi,

the

What if you provide C# interface members with DispIdAttribute, will it help?

('Name'

Also some articles to check, it may be ATL's 3.0 IDispEventImpl problem...

BUG: IDispEventImpl Event Handlers May Give Strange Values for Parameters
 http://www.**--****.com/ 

FIX: Events Fail in ATL Containers when Enum Used as Event Parameter
 http://www.**--****.com/ 

BUG: ATL Events Don't Fire If Defined With Interface Alias
 http://www.**--****.com/ 

..
Thanks,
Vadim.




Re: .NET event, VC6 sink, problems with event parameters

Postby Eric Brandt » Sat, 27 Sep 2003 22:50:35 GMT

Vadim & group,
Thanks for your advice.
We figured out how to make it work but don't really understand the reason.
Perhaps someone could explain if they know....

We changed the 2 parameters in the C++ callback function (of IDispEventImp)
from the interface types that they really were to IDispatch*. Then inside
the function, we QI'ed the IDispatch pointers for the real interface pointer
we knew the parameter was. Then, accessing methods and properties of that
interface was successful.

Also, BTW, this was done over a local server (i.e., two separate exes). I
believe things worked fine when were were inproc.

Thanks,
E.

To get it to work, we changed both the parameters in the C++ implementation
of our event callback to




the
help?
to



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



Return to dotnet framework

 

Who is online

Users browsing this forum: No registered users and 65 guest