03-31-2020 01:57 AM
I'm calling a callback function in dll, that looks like this:
FaceCallback (byte [] buf, int size, string res);
callback returns three parameters:
1. Buf represents the real-time video frame image binary buffer;
2, and size represents the video frame size;
3. Res returns the detected face information, which is the same as the json returned in the track method.
How do I configure the dialog box for dll?
I look forward to your reply.
Solved! Go to Solution.
03-31-2020 02:51 AM
It's not clear what you want.
@ferry123 wrote:
I'm calling a callback function in dll, that looks like this:
You are calling the function? Or you try to?
@ferry123 wrote:
How do I configure the dialog box for dll?
If you are calling the function from a dll, there won't be a dialog box.
Are trying to make a callback function, so an existing dll can call it? That's not trivial:
+ Make a VI with the specified parameters.
+ Make a dll, and add the VI as a function (with the correct parameters and calling convention).
+ Use LoadLibrary and GetProcAddress to get a pointer to the function.
+ Tell the dll to use the pointer as a callback.
That will call the dll as a callback. But that won't give you access to the data the callback gets. To get access to that data:
+ Add a VI to the dll that buffers a UserEvent reference.
+ In the callback use LVPostEvent to trigger the user event.
04-01-2020 09:01 PM
04-02-2020 01:15 AM
04-02-2020 03:55 AM - edited 04-02-2020 04:01 AM
Calling a callback function is exactly the same as calling a function. It's only it's purpose that's different.
If you want us to help with calling a function, we need to see your attempt and the function's prototype. Optionally, upload the dll and the VI.
FaceCallback (byte [] buf, int size, string res);
callback returns three parameters:
1. Buf represents the real-time video frame image binary buffer;
2, and size represents the video frame size;
3. Res returns the detected face information, which is the same as the json returned in the track method.
The function doesn't return 3 parameters. Functions can only return one integer. All other parameters are inputs, but they can be pointers\references. The dll can change the data at those pointers, and this is almost like an output.
The first parameter is an array of bytes.
The 2nd parameter is the size of that array.
The string is tricky. It's not clear what is expected. If the dll returns a pointer to data, it's data allocated by the dll. This is possible, but then there should be a way to deallocate that data.
Is there an example? Any language will help...
04-07-2020 05:05 AM - edited 04-07-2020 05:11 AM
A callback function is only a callback function if it is called back by the code you call. That means you call a function that takes a callback function pointer that that function or someone else in the library will eventually call back into.
This requires a function pointer and that is something LabVIEW can not provide as LabVIEW VIs are not function pointers. Basically if you really have an API that requires a callback function as parameter you have only one feasable way of dealing with that for use in LabVIEW: You need to write a wrapper DLL in C(++) that implements this callback function and then contains another function that you can call from LabVIEW and then calls that other API passing it the pointer to its implemented callback function.
The callback function will somehow have to interprete the parameters it receives and probably have a way to communicate that back to LabVIEW. Possible ways to do so:
1) store them in a queue (a queue in the C(++) code so if you know C++ and can use template classes that would be mighty helpful, as implementing your own queues in C is a major effort to get fully right). Then provide another function to call from LabVIEW to poll this queue periodically.
2) Using the LabVIEW exported C function PostLVUserEvent() you can post an event to a user event refnum from within the callback function that a LabVIEW event structure can receive.
Both solutions require some good understanding about C(++) programming though! Function pointers are considered advanced C programming knowledge and callback functions are basically just that. An interface to configure a callback function in the Call Library Node would be so complex that only someone who can write the wrapper DLL anyhow left handed would be able to understand it properly, so it's basically a useless feature to implement for the LabVIEW developers, and would be pretty costly too to implement. That means the cost-usefullness analysis for this feature is approaching negative infinity.
04-16-2020 04:02 AM
07-13-2021 08:28 AM - edited 07-13-2021 08:29 AM
wiebe@CARYA wrote:
The string is tricky. It's not clear what is expected. If the dll returns a pointer to data, it's data allocated by the dll. This is possible, but then there should be a way to deallocate that data.
Actually the 3rd parameter is more than just tricky. There is no string datatype in standard C. There is one in the C++ standard template class library but that is a C++ object and as such not only not implementable (nor even accessible) by LabVIEW directly but in fact C++ compiler specific.
You can not mix and match object pointers between different compilers, so C++ object parameters in DLL interfaces is a pretty bad idea. Despite that the DLL interface would promise that the DLL can be called by anyone that can access DLL functions, only the C++ compiler (and version) that was used to create the DLL is guaranteed to be able to access such an API without causing all kinds of weird problems, including memory corruptions.