03-05-2020 08:50 AM
Hi
I want to get the title text of foreground Window(not only vi), the vi used user32.dll, and it can work, but when it run for a while labview will no response then crashed. does anybody can help me, Thanks.
03-05-2020 09:49 AM - edited 03-05-2020 10:00 AM
@seanwin wrote:
Hi
I want to get the title text of foreground Window(not only vi), the vi used user32.dll, and it can work, but when it run for a while labview will no response then crashed. does anybody can help me, Thanks.
Of course! DLL functions are not LabVIEW VIs. When you call a function that is supposed to write some data into a buffer, you must make sure to allocate that buffer before the call.
In your GetWindowsTextA() Call Library Node, change the configuration of the arg2 parameter to have a Minimum Size: arg3. This will tell LabVIEW to preallocate a string buffer with arg3 characters before passing it to the DLL function.
As it is now you pass in a string of 1 byte long (for the terminating NULL character) but tell the function to go on and copy up to 100 characters (including the NULL character) into that buffer. If this doesn't crash your software, which it potentially can, it for sure will corrupt memory that at some point will make LabVIEW stumble over some corrupted memory pointers.
Also some maintenance for long term support: Change the type of the window handle in both Call Library Nodes (the return value of the 1st and the first parameter in the second CLN) to be a pointer sized integer (signed or unsigned is not important as long as you make both the same). This will make the function compatible to run in 64-bit LabVIEW too.
03-05-2020 10:16 AM
Take a look this NI tool.
Windows API Function Utilities (32-bit) for LabVIEW
It has the function you need, and many more.
03-07-2020 07:22 PM
Hi Rolfk & Zhou
Thanks!