Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Can i trigger an event to a C# app in a C++ DLL?

Can i trigger an event to a C# app in a C++ DLL?

Scheduled Pinned Locked Moved C#
helpcsharpc++databasequestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fu0
    wrote on last edited by
    #1

    i m writting a C++ Win32 DLL which is called by a C# application. i want the DLL can trigger an event to the Calling C# app after some operations which might like the Win MSG mechanism: The DLL send a message to the C# app and the C# app handle the msg. the C# use the EventHandle/EventArgs on this issue. But can i trigger an event to C# app in a C++ Win32 DLL ? please help me.

    H 1 Reply Last reply
    0
    • F fu0

      i m writting a C++ Win32 DLL which is called by a C# application. i want the DLL can trigger an event to the Calling C# app after some operations which might like the Win MSG mechanism: The DLL send a message to the C# app and the C# app handle the msg. the C# use the EventHandle/EventArgs on this issue. But can i trigger an event to C# app in a C++ Win32 DLL ? please help me.

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      If you pass a handle (the Handle property for controls) to your unmanaged DLL (P/Invoke is easy enough, and I assume you know how to do it), you could always call SendMessage in your unmanaged code to send a message to a control. In your control class (assuming you've extended a class), override WndProc and handle the message. Don't forget to call base.WndProc to continue processing all messages that go through the window procedure for the Control. Another way is to expose your .NET component as a COM control (following correct guidelines, which aren't too obvious when reading the .NET Framework SDK but any COM developers should know). Your unmanaged code could instantiate a new or reference an existing instances and call a method that raises an event defined on your .NET component. While my article isn't exactly about this, per se, it does offer a lot of insight into this method. Read Embedding .NET Controls in Java[^], which discusses bridging .NET and Java with C++ (JNI and COM). You shoudl find a lot of helpful information in there about what you're trying to do.

      Microsoft MVP, Visual C# My Articles

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups