Note that there are some explanatory texts on larger screens.

plurals
  1. POEvent Handling in C++/CLI
    primarykey
    data
    text
    <p>I have a function, singleFrameEventHandler, that I wish to be called when a certain event, OnNewFrame, occurs. After doing some research, it seemed to me that functions which handle events have a void return type and take a parameter of the type that contains the event. From what I could find online, that is done like this:</p> <p>Function declaration:</p> <pre><code>void singleFrameEventHandler(IAFrame ^ frame); </code></pre> <p>When the function is assigned to handle the event:</p> <pre><code>iaframe-&gt;OnNewFrame += &amp;singleFrameEventHandler; </code></pre> <p>When I try to compile the code containing the above segments, I get the following error:</p> <pre><code>error C2664: 'Spiricon::BeamGage::Automation::Interfaces::IAFrame::OnNewFrame::add' : cannot convert parameter 1 from 'void (__clrcall *)(Spiricon::BeamGage::Automation::Interfaces::IAFrame ^)' to 'Spiricon::BeamGage::Automation::Interfaces::newFrame ^' No user-defined-conversion operator available, or There is no context in which this conversion is possible </code></pre> <p>The OnNewFrame is of type Spiricon::BeamGage::Automation::Interfaces::newFrame, which unfortunately has no documentation beyond being described as "The event that is called when a new frame is available."</p> <p>In the object browser, I can find some information about it:</p> <pre><code>public delegate newFrame: public System.IAsyncResult BeginInvoke(System.AsyncCallback callback, System.Object object) public System.Void EndInvoke(System.IAsyncResult result) public System.Void Invoke() public newFrame(System.Object object, System.IntPtr method) </code></pre> <p>The newFrame constructor (?) seems to be the best bet, as it appears to take a method pointer, but when I try to use it like this:</p> <pre><code>iaframe-&gt;OnNewFrame += gcnew newFrame(iaframe, &amp;singleFrameEventHandler); </code></pre> <p>I get the following error:</p> <pre><code>error C3352: 'singleFrameEventHandler' : the specified function does not match the delegate type 'void (void)' </code></pre> <p>Does this mean that my function has to take no parameters? If so, how would I get information about the event?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload