walter Posted July 14, 2005 Report Share Posted July 14, 2005 I got a new problem with a .DLL The Pototype in the .h-file is like this: ...cut...#ifdef CPP_CALLEXPORT int FKTNPREFIX _getUser( char* station, // in char*& userName, // out int& ErrorCode, char*& ErrorString);#elseint FKTNPREFIX _getUser_c( char* station, /* in */ char** userName, /* out */ int* ErrorCode, char** ErrorString);#endif...cut...In the running .CPP the function call is like this:...cut.... printf("calling _getUser()\n"); char station[80]; char* userName; ErrorString = (char *)calloc(280, sizeof( char )); userName = (char *)calloc(180, sizeof( char )); printf("station: "); scanf("%s", station); ret = _getUser( stationNr, /* in */ userName, /* out */ ErrorCode, ErrorString); printf("return Value <%d>\n", ret); if(ret >= 0) { printf("userName <%s>\n", userName); } printf("ErrorCode <%d>\n", ErrorCode); printf("ErrorString <%s>\n", ErrorString); free(userName); free(ErrorString);...cut... How do I handle this calloc and free statement when calling the .DLL from LabView? Quote Link to comment
i2dx Posted July 14, 2005 Report Share Posted July 14, 2005 take a look at: http://zone.ni.com/devzone/conceptd.nsf/we...567CC004D5CCA#3 you have to export your "free" function in your dll, then you call the free function via the call library-node Quote Link to comment
walter Posted July 15, 2005 Author Report Share Posted July 15, 2005 take a look at:http://zone.ni.com/devzone/conceptd.nsf/we...567CC004D5CCA#3 you have to export your "free" function in your dll, then you call the free function via the call library-node 5347[/snapback] That's exactly what I cannot do, because the .DLL is made from a supplier and I do not have an access to the source code. Should I change the supplier? Quote Link to comment
i2dx Posted July 15, 2005 Report Share Posted July 15, 2005 That's exactly what I cannot do, because the .DLL is made from a supplier and I do not have an access to the source code.Should I change the supplier? 5349[/snapback] would be better, because you have NO chance to call a function in a dll in LV via the call library node, if the function is not exported ... i can imagine there could be a way with the code interface node, but my skils in C/C++ are very basic, so you better ask an expert if there is a way ... cheers CB Quote Link to comment
i2dx Posted July 15, 2005 Report Share Posted July 15, 2005 jetzt mal auf deutsch: das sieht ja irgendwie wie eine user-authentifizierung aus. wenn das Quote Link to comment
walter Posted July 15, 2005 Author Report Share Posted July 15, 2005 jetzt mal auf deutsch:das sieht ja irgendwie wie eine user-authentifizierung aus. wenn das Quote Link to comment
Rolf Kalbermatter Posted August 12, 2005 Report Share Posted August 12, 2005 I got a new problem with a .DLL ErrorString = (char *)calloc(280, sizeof( char )); userName = (char *)calloc(180, sizeof( char )); printf("station: "); scanf("%s", station); ret = _getUser( stationNr, /* in */ userName, /* out */ ErrorCode, ErrorString); printf("return Value <%d>\n", ret); if(ret >= 0) { printf("userName <%s>\n", userName); } printf("ErrorCode <%d>\n", ErrorCode); printf("ErrorString <%s>\n", ErrorString); free(userName); free(ErrorString); ...cut... How do I handle this calloc and free statement when calling the .DLL from LabView? 5337[/snapback] Very simple. Create two LabVIEW strings with the correct size. You can use the Initialize Array function to create two arrays of the necessary size of U8 numbers with the value 0. Then use the Byte Array To String function to convert these arrays in a string, place a Call Library Node on the diagram to call your _getUser function and pass the two strings at the appropriate location to that Call Library Node configuring them to be a C String pointer. LabVIEW will take care about passing the correct pointer to the DLL and on return will truncate the string to the actual filled in information up to the terminating 0 byte character. Basically the calloc is done through the Initialize Array function and the free is done implicitedly by LabVIEW as soon as the string is not anymore used in the diagram. Since the allocation and freeing of the memory is done by the caller (here LabVIEW) there is no need to use a particular memory manager instance. The function will just take whatever memory is provided to it and fill it in with whatever information it has. Rolf Kalbermatter Quote Link to comment
H_1_syncro Posted October 4, 2005 Report Share Posted October 4, 2005 Hi, i had some trouble with a similar problem: I Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.