02-13-2013 08:51 AM
Hello!
When a call one my functions in my dll from LabView, i get an error 1097. My function takes a few arguments and then allocates some memory for measurement.
It's not returning any pointers to that memory area, it is just allocates that memory for itself. I don't know what could be the problem, probably i am missing something.
Could you help please?
Best regards,
Tamas
Solved! Go to Solution.
02-13-2013 04:24 PM
You need to provide more details: the header file for the function you are calling, or at least the function prototype, and the VI (not a screenshot - we need to see how the Call Library Function Node is configured). I would also suggest setting the error checking level to "Maximum" and see if you get a more helpful error message.
02-14-2013 01:44 AM
Hello,
Is that dll developed by you? In what language? or, do you know the internal structure of those functions??
Indeed, we need more information before we can make any suggestion.
Best regards,
I.R.
02-14-2013 03:15 AM
@nathand: setting error level to maximum unfortunately did not work, the same error message came up.
@ion.rosca: yes the dll was developed by myself but it is a wrapper dll because our sub contractor provided a lib for the camera that i work with.
Please find attached the vi and the header file. I would like to mention that dll works with for example Open, Close, Sampling, Timing functions, so i can communicate with the camera
and i can write registers. The error occurs when the Allocate function tries to allocate memory fro the measurement because it allocates two buffers according to the parameters
these buffers than stores the data which comes from the camera through network.
Best regards,
Tomzi
02-14-2013 01:24 PM
I don't see anything wrong with the setup of the Call Library Function Node, so I would suspect a problem inside the wrapper DLL. Is there some reason you need the wrapper instead of calling the functions directly from LabVIEW? Can you share the wrapper code? Have you tested the wrapper outside of calling it from LabVIEW, and can you attach a debugger to it so you can see if there's an error when your LabVIEW code calls it?
02-14-2013 01:37 PM
The reason i wrote a wrapper is that as far as i konw LabView can only use .dll and the subcontractor provided a .lib and the library has complex structures as well.
I think the wrapper should be fine because in that specific Allocate function a did not change anything, the function inside the Allocate function is the same.
The other functions that i used with LabView worked well and for example when i run my LabView application with Highlight Execution, the Allocate function return with 0, which means
no error accured and the the error 1097 came up, But for the second attemp it returns 2 which means the function can't allocate memory for unknown reason.
02-14-2013 01:45 PM
sorry i was wrong about this "But for the second attemp it returns 2 which means the function can't allocate memory for unknown reason." this means invalid handler error.
I'll try further investigate what could be wrong.
Thank you in advance for your answers!
02-14-2013 01:49 PM
What is the function prototype for the original Allocate function, and can you post the code for your wrapper?
Sometimes with DLL calls the LabVIEW error may not match exactly where the problem is. For example, let's say you passed a bad pointer to one function. Even if the function call succeeds, it could corrupt memory at that location, which could cause some later function call to generate an error. The problem is actually at the first function call even though it's the second one that shows the error. Sounds like you might have a similar issue here.
02-18-2013 02:51 AM
Sorry for the late answer, i wasn't in the office...
Here is how my wrapper function looks like.
unsigned int Allocate(long long sampleCount, int bits, int channelMask_1, int channelMask_2, int channelMask_3, int channelMask_4, int primary_buffer_size) { ADT_RESULT res = APDCAM_Allocate(handle, sampleCount, bits, channelMask_1, channelMask_2, channelMask_3, channelMask_4, primary_buffer_size); return res; }//Allocate
It doesn't use pointers so i don't know what could be wrong because i have used this library in another project as well. It is true that it was a C++ project but that works well.
02-18-2013 03:16 AM - edited 02-18-2013 03:20 AM
Are you sure that the allocate function is the problem?
Error 1097 simply means something inside the external code wrote into memory locations that it was not meant to write. That is usually because of output buffer parameters that are not allocated (large enough) in LabVIEW when passed to the external code fucntion, so the function assuming it received a buffer of a certain size happily writes into that buffer but overwriting other information it should not have.
But that is by far not the only possibility to cause this error. A simple bug in the external code can cause the same problem when a pointer goes astray or such. The fact that you used that library elsewhere already without seeing any problem is unfortunately no guarantee that the function is not buggy. The LabVIEW exeception handling around the Call Library Node has gotten rather picky and can detect violations that do not have to cause visible problems at all. But the violations it detects are real violations so just silencing them is not a good idea, as they could cause all kinds of problems including overwriting vital data structures in your program that either cause a crash later on or simply wrong results in other parts of your program. Especially the last one is a total bummer to debug.
Without seeing much more of your code it is basically impossible to point out where the problem could lie. The particular Allocate function doesn't look like there is much that could be done wrong, but I would assume that you call several other functions too somewhere, which could cause the problem. If you can absolutely positively say that you never ever call any library function with a to short (or unallocated) buffer parameter, then you will have to take it up with the manufacturer of your lib, as it would seem very likely that there is some problem in there.
Also you pass a handle to the library function but your Allocate function does not have this as a parameter! Where does this handle come from? Are you sure you have allocated and prepared it properly before calling this function? A handle is quite often a pointer, although usually a so called opaque pointer meaning the user of the library does not and should not know anything about the structure this pointer points to. It is only known internal to the library.