04-15-2010 06:41 AM
I cannot get the LStrPrintf version to work at all it just crashes LabView.
I do have a BlockMove version (see attachment), but it only seems to get the first 10 characters of the string if there are spaces in it. If I change my test DLL string "ABCDEFGHIJKLMNOPQRSTUVWXYZ" I get the lot out????
04-15-2010 08:01 AM
Fixed it. I managed to get LStrPrintf to work...
Thanks all.
04-15-2010 09:08 AM
ChristopherPovey wrote:And parameter 3 is:
Type: Numeric
Data Type: Signed 8-bit Integer
Pass: Pointer to Value
???
Also the "problem" DLL function. Should that be set up as per "this little trick"?
Thanks.
Well LabVIEW 8.5 does not have pointer sized integers. So you will want to use a 32 Bit integer and set Pass: Value.
For your own DLL you will want to set it to Pass: Pointer to Value
03-16-2011 04:46 AM - edited 03-16-2011 04:47 AM
Rolf,
Thank you for your answer to the original question. It just helped me too -- I came here with the same question, searching for a solution.
Just one note. You wrote: "As such the function will allocate a pointer and return it (a highly non-standard C practice at least for strings). This automatically begs the question when and how will this pointer be deallocated?".
This is not completely true. The same prototype is often used in a different, quite standard C practice. Often for things like retrieving an error string by code, or some such. The strings are constant strings, and they are returned either via a "char *" return value or via a "char **" parameter, where nothing is allocated, and nothing needs to be deallocated. The user's pointer is simply pointed to the constant string.
eg:
void GetErrorString(int errorCode, char **ppErrorString) {
switch (errorCode) {
case error1:
*ppErrorString = "Error 1 occured");
return;
case error2:
*ppErrorString = "Error 2 occured");
return;
default:
"Unknown error";
}
}
or, more common:
char * GetErrorString(int errorCode) {
switch (errorCode) {
case error1:
return "error 1 occured";
case error2:
return "error 2 occured";
default:
return "Unknown error";
}
}
Batya
03-16-2011 08:56 AM
You are of course right with this. However the fact that the returned pointer is really a static memory location should be just as much documented as if it would be dynamic. C simply isn't verbose enough in itself to allow this indication, and assuming that no documentation means static memory is really a dangerous one.
03-17-2011 06:14 AM
No, you are right, you can't assume it.
It is much more standard/common usage in C, but you can't assume it.