05-10-2017 06:24 AM
Hi.
I am working with a dll-function generated from LV which needs an path type.
I would like to convert a std::string to LV-path and tried the following code.
std::string v_PathAsString_o = "C:\\_work\\PowerSupply.ini"; const char * v_path_pc = v_PathAsString_o.c_str(); const char ** v_path_ppc = &v_path_pc; Path * v_Path_po = NULL; char **filename = 0; MgErr v_status_o = FStringToPath((ConstLStrH)v_path_ppc, v_Path_po); // v_status_o will be set to 2 (mFullErr) // v_Path_po remains 0x00000000
After sucessful compile and run I got status from FStringToPath() back and was set to mFullErr.
I cannot imagine that my Windows 7 PC is having trouble with memory space.
What is the right way to get a LV path variable?
05-17-2017 03:43 AM - edited 05-17-2017 03:48 AM
@egon456 wrote:
Hi.
I am working with a dll-function generated from LV which needs an path type.
I would like to convert a std::string to LV-path and tried the following code.
std::string v_PathAsString_o = "C:\\_work\\PowerSupply.ini"; const char * v_path_pc = v_PathAsString_o.c_str(); const char ** v_path_ppc = &v_path_pc; Path * v_Path_po = NULL; char **filename = 0; MgErr v_status_o = FStringToPath((ConstLStrH)v_path_ppc, v_Path_po); // v_status_o will be set to 2 (mFullErr) // v_Path_po remains 0x00000000
After sucessful compile and run I got status from FStringToPath() back and was set to mFullErr.
I cannot imagine that my Windows 7 PC is having trouble with memory space.
What is the right way to get a LV path variable?
A LStrHandle is a pointer to a pointer, but not to a C string buffer but instead to a memory buffer that first contains an int32 that indicates the number of bytes, followed by the 8bit MCBS data string (without appended 0 char but having one in the buffer as long as it is not counted in the length is not a problem).
So you really first need to convert your C String into a LStrHandle.
And once you do that you would run into the next error (mgArgErr) since you don't allocate a space for the returned path but only for a pointer to one and initialize it to NULL, then pass it to FStringToPath() like that. And FStringToPath() receives a null pointer to return the path in! That can't work!
Something like this would work:
char *cstr = "something"; LStrHandle lstr = NULL; Path path = NULL; err = NumericArrayResize(uB, 1, (UHandle*)&lstr, strlen(cstr)); if (!err) { MoveBlock(cstr, LStrBuf(*lstr), strlen(cstr));
LStrLen(*lstr) = strlen(cstr); err = FStringToPath(lstr, &path);
DSDisposeHandle((UHandle)lstr); }