10-06-2009 01:28 AM
Hi! I have a VB6 code.(Even you don't always write VB6, I am also appreciate if you could provide me with your experience on developing DLL for labview) and I have compiled it to become a Windows DLL. However, when I use it with a library node in labview, an error of memory corruption occured.
I have no experience on self-making a dll for the use in labview. So I tried something to figure where the problem comes from.
And I got two guesses after my trials:
1. My DLL cannot contain call function to call another DLL (like HID.dll in system32 folder)
2. My DLL cannot use self defined data type
But since I have no experience, could anyone advice me about my case? Are my guesses true or is it due to other problem? Or I missed something?
Attached are the code and the declarations. These stuffs are not written by me, but by a camera company, which should be working.
10-06-2009 01:47 AM
Your description is very unclear. A memory corruption error is not caused by the fact of calling other DLLs ever. Of course you could have made an error in the function prototypes you do call, since you have to setup all the functions in your VB code yourself. For instance using the wrong parameter type or missing a parameter or having one to much will certainly cause protection violation errors.
But there are about half a million other things that could go wrong in your example. It could be simply something you do in your VB code by trying to pass bad (uninitialized) pointers to some function. Or it could be in the configuration of the Call Library Node itself. Have you made sure that all pointer type parameters (string and arrays) are initialized properly BEFORE calling a function through the Call Library Node. While you do not have to worry about allocating memory in LabVIEW itself, since LabVIEW does that conviniently for you, this is not the case in the Call Library Node and also not as much in VB6.
If there is a function that takes a string parameter to fill in some information, you as the caller have to allocate a big enough memory chunk before calling that function. Otherwise the DLL will write into what it believes is a valid memory block anyhow and overwrite more or less vital information.
Personally I feel it to be a bad choice to use two different environments that both require to setup the APIs manually. Both in LabVIEW and VB you have to worry about the API prototypes of the functions you want to call, and that is a tedious and error prone thing. I would personally write the DLL in C because you can then at least rely on the SDK headers to have the correct function prototypes, so at least that error can not occur.
Rolf Kalbermatter
10-06-2009 02:11 AM
Hi! The attached "code" file is the source code to compile into a windows DLL, it should also include the "declaration" file so that all variables are defined and library to use is located.
I cannot have more error message since that the only error message I got from labview is like "it may be because memory is corrupted", then no more but asking me to save my work and restart the labview.
by the way, what should I do to initalize a pointer in labview? is it just done by creating a control/indicator in labview? I think once a variable is defined, it has its pointer.
I am not very experienced in programming but I am now facing this problem, I really wish you or someone could give some more keywords on what I should do ..
Thanks Rolf for your reply!!
Raymond Kwok
10-06-2009 04:11 AM
vgbraymond wrote:Hi! The attached "code" file is the source code to compile into a windows DLL, it should also include the "declaration" file so that all variables are defined and library to use is located.
I know, but I'm not going to check them against MSDN for you.
I cannot have more error message since that the only error message I got from labview is like "it may be because memory is corrupted", then no more but asking me to save my work and restart the labview.
by the way, what should I do to initalize a pointer in labview? is it just done by creating a control/indicator in labview? I think once a variable is defined, it has its pointer.
No! You allocate it by initializing an array with the apropriate size. A control will simply hold the data it does. By defailt this is an empty string or array so its data will be a memory block of 0 Bytes length. Passing that to a DLL will be not enough as the DLL needs some memory area to use.
I am not very experienced in programming but I am now facing this problem, I really wish you or someone could give some more keywords on what I should do ..
Thanks Rolf for your reply!!
Raymond Kwok
Rolf Kalbermatter