02-08-2019 06:28 AM
Hello everyone,
as a follow up to this thread, I am trying to send a value to a running dll.
Here is a test example which I wrote, and I was expecting to be able to stop the running loop in the dll by setting the pStop pointer to "1" from Labview by pressing the pStop button.
__declspec(dllexport) int test_value_from_LV(unsigned int *pStop) { std::ofstream logFile; logFile.open("log.txt"); if (!logFile.is_open()) { return -1; } unsigned int value = 0; for (int i = 0; i < 100; i++) { if (*pStop == 1) i = 1000; value = *pStop; logFile << "pStop: " + std::to_string(value) + "\n"; Sleep(100); //wait 100ms } logFile.close(); return 0; }
This is the block diagram with the settings and the outputs of the MoveBlock.
The log.txt in the dll saves "pStop: 883828976" even after pressing the pStop button.
Any help or hint is appreciated.
The source code of the dll is available and is written in C++. Labview 2015, 64Bit, windows 7.
Thank you in advance.
Solved! Go to Solution.
02-10-2019 05:03 PM - edited 02-10-2019 05:11 PM
Think about what source and destination mean here. Do you really want to copy the contents of your pointer to the value read from the boolean control?
And think about what will happen with your pointer if you terminate the loop before your loop inside the DLL has finished!
And an int32 is only 4 byte, if you try to copy 8 bytes as you do now, you overwrite memory that you should never touch, and once you change source and destination you still read memory that you shouldn't.
02-11-2019 07:22 AM
Hi Rolf,
Thanks for the hints.
I switched the src and dst and its parameters accordingly at MoveBlock and it workes as expected.
I'm not really sure if I got your second point correctly, but in the real VI, the LV loop will be stoped after the dll finished his loop (or externally stopped). So I guess the DSDisposePtr will just kill the pointer as it is no more needed!?
Thanks again for the worthy guides..
Arash