Visit our LabVIEW Wiki External Code Portal.
Tags |
(This content has not been tagged yet)
|
![]() |
Jul 14 2005, 07:05 AM
Post
#1
|
|||
|
I want a LabVIEW icon under my name! Member Posts: 3 Joined: 13-July 05 Member No.: 2576 LV:7.1
|
I got a new problem with a .DLL
The Pototype in the .h-file is like this: CODE ...cut... #ifdef CPP_CALL EXPORT int FKTNPREFIX _getUser( char* station, // in char*& userName, // out int& ErrorCode, char*& ErrorString); #else int 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?
|
||
|
|
|||
| Ad |
Jul 14 2005, 07:05 AM
Post
#
|
||
|
|
|
||
|
|
|||
Jul 14 2005, 08:20 PM
Post
#2
|
|||
![]() (n0ob)² Member Posts: 756 Joined: 22-October 04 From: Duesseldorf / Germany Member No.: 885 Using LabVIEW Since:2001 LV:8.20 ,7.1.1 ,.
|
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 --------------------
|
||
|
|
|||
Jul 15 2005, 06:19 AM
Post
#3
|
|||
|
I want a LabVIEW icon under my name! Member Posts: 3 Joined: 13-July 05 Member No.: 2576 LV:7.1
|
QUOTE (i2dx @ Jul 14 2005, 09:20 PM) 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 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?
|
||
|
|
|||
Jul 15 2005, 06:58 AM
Post
#4
|
|||
![]() (n0ob)² Member Posts: 756 Joined: 22-October 04 From: Duesseldorf / Germany Member No.: 885 Using LabVIEW Since:2001 LV:8.20 ,7.1.1 ,.
|
QUOTE (walter @ Jul 15 2005, 07:19 AM) 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? would be better, because you have NO chance to call a function in a dll in LabVIEW 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 --------------------
|
||
|
|
|||
Jul 15 2005, 07:03 AM
Post
#5
|
|||
![]() (n0ob)² Member Posts: 756 Joined: 22-October 04 From: Duesseldorf / Germany Member No.: 885 Using LabVIEW Since:2001 LV:8.20 ,7.1.1 ,.
|
jetzt mal auf deutsch:
das sieht ja irgendwie wie eine user-authentifizierung aus. wenn das über TCP/IP geht, dann kann man das auch prima mit LabVIEW erledigen. Zum Thema TCP/IP gipts auf jeden Fall ein paar schöne Beispiele in den "examples" ... Das Problem mit den DLLs hab ich leider öfter, gerade wenn man kein Visual Studio hat und mit fremd-DLLs arbeiten muss. Meistens hakts immer an einer Kleinigkeit, darum versuche ich "non NI DLLs" zu vermeiden ... Grüße CB --------------------
|
||
|
|
|||
Jul 15 2005, 04:03 PM
Post
#6
|
|||
|
I want a LabVIEW icon under my name! Member Posts: 3 Joined: 13-July 05 Member No.: 2576 LV:7.1
|
QUOTE (i2dx @ Jul 15 2005, 08:03 AM) jetzt mal auf deutsch: das sieht ja irgendwie wie eine user-authentifizierung aus. wenn das über TCP/IP geht, dann kann man das auch prima mit LabVIEW erledigen. Zum Thema TCP/IP gipts auf jeden Fall ein paar schöne Beispiele in den "examples" ... Das Problem mit den DLLs hab ich leider öfter, gerade wenn man kein Visual Studio hat und mit fremd-DLLs arbeiten muss. Meistens hakts immer an einer Kleinigkeit, darum versuche ich "non NI DLLs" zu vermeiden ... Grüße CB Sprache ok. Diese DLL kommuniziert mit einem Datenbankserver einer Fertigunglinie und die Anbindung wurde auch mitgekauft. "Nur" die Verbindung zu LabVIEW fehlt. Aber ich denke, die kriegen wir auch noch vom Lieferanten gegen €. Dabei denke ich an eine "Zwischen-DLL", die die fehlenden Tätigkeiten (alloc und free) durchführt. In der Test.CPP ist ja alles aufgeführt, es muss ja "nur" noch so exportiert werden, dass LabVIEW es versteht. Danke für die Unterstützung. walter
|
||
|
|
|||
Aug 12 2005, 09:53 AM
Post
#7
|
|||
|
<customize this text> Premium Member ![]() Posts: 1012 Joined: 9-April 04 From: Rotterdam Member No.: 349 Using LabVIEW Since:1992 LV:8.5.1 ,8.2.1 ,7.1.1
|
QUOTE (walter @ Jul 14 2005, 02:05 AM) 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? 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 This post has been edited by rolfk: Aug 12 2005, 09:54 AM
|
||
|
|
|||
Oct 4 2005, 02:34 PM
Post
#8
|
|||
|
5 more posts to go! Member Posts: 5 Joined: 23-September 05 Member No.: 3055 LV:7.1
|
Hi,
i had some trouble with a similar problem: I´ve had a dll for spline interpolation and was writing a VI for spline-on-spline interpolation with a filter modul between the two spline-interpolations. I use this VI in order to have a smooth second-derivation of the data. In the VI the data gets first derivated then filtered and finaly derviated. So to my problem: In the dll there i "alloc" memory for same arrays (that´s was no problem), as i doesn´t needed the arrays i "free" them. And heres the big problem: for the second dll call, the pointers of the arrays were not valid... So you can imaging what would happen the filtered data, nothing. The data which was "calculated" looks not that way it should be. So my advise: Don´t "free" the pointers. It seems that LabVIEW doesn´t create new once. And it doesn´t run even if you try to spoof LabVIEW with a renamed and copied dll
|
||
|
|
|||
![]() ![]() |
| Time is now: 1st December 2008 - 08:04 PM |