DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2004

    Custom Events and Event Handlers

    I'm new to C++ programming (but coming from a c-sharp) and have been working on translating some of the dlls that I've written in the past to C++.

    Anyway, one of the dlls that I'm writing uses event notifications to let the user know when database calls (amongst other things) are complete. I've been looking through some of the online tutorials and find very little on how to port my c-sharp events to C++.

    Any suggestions, thoughts or hints would be great!

  2. #2
    Join Date
    Dec 2003
    not knowing anything at all about what you did, all I can do is give generic answers. Basically, the raw language is unaware of events -- of course -- the language is also unaware of the concept of a database too, and only vaguely aware of the CPU and OS with some fairly generic and crude interfaces to those.

    However the extended language, using standard libraries, makes such things possible.
    My suggestion here is to use threading, such as the standard p-threads library or if you are in windows, the built in threading library of visual studio is pretty good.

    basically, by wrapping a database call in a thread you can detect if that call is done (the thread returns a value, or can flip a boolean, invoke a function, or whatever you like), effectively trapping the 'done' event. If something needs to happen immediately after the DB call is done, you can do it too, just put it after the DB call inside the thread function body, depending on what you need to do.

    Other event handling is done through the OS and related OS libraries, such as keyboard events, system shutdown (broadcast internally by the OS, you listen for it if you care), or the like. Still other events are hardware related and quite complex to handle.

  3. #3
    Join Date
    Feb 2004
    Thanks for the reply.

    I had thought about using threading to make my database call asynchronous (sp?). My thought being that users could continue to work within the program without locking up the program each time they execute a long running queries etc.

    I've been looking at using callbacks to handle this sort of notification.

  4. #4
    Join Date
    Dec 2003
    If the database tools you use support callbacks that will work just fine. Threading will also work just fine, as you said it prevents lockup for long periods. Again, every thread library I have ever seen has a way that can be polled to determine if a thread is done yet, or you can have the thread function itself do something when the database call returns, lots of ways to handle it.

Similar Threads

  1. Replies: 2
    Last Post: 03-27-2008, 05:32 PM
  2. DataAdapter RowUpdated Event Problem (C# 2.0)
    By me_code2004 in forum .NET
    Replies: 1
    Last Post: 06-07-2006, 08:52 PM
  3. Replies: 0
    Last Post: 02-20-2005, 01:06 PM
  4. event handlers in c# and vb.net
    By Florian Fankhauser in forum .NET
    Replies: 0
    Last Post: 07-03-2002, 03:31 AM
  5. REPOST-from VB.dotnet.technical
    By Sachin in forum VB Classic
    Replies: 8
    Last Post: 09-09-2001, 11:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.