Jump to content

greatwall

Members
  • Posts

    2
  • Joined

  • Last visited

Posts posted by greatwall

  1. QUOTE (bsvingen @ Apr 6 2009, 02:59 PM)

    Working with pointers in LV through DLLs can be a bit very confusing IMO. LV does not know how memory is allocated in the DLL, so it has no idea what to return when memory is allocated/deallocated. There are special memory functions in external.h, but I have never used them myself. The way I do it is to have certain rules that I know will work, for me at least.

    Never return a dynamic value (array and similar with unknown size) in the return argument. Only return basic types like integers (could be pointer) or floats or nothing at all.

    Allways allocate memory in LV when returning arrays and similar within the function body.

    When you have lots of complex data types (arrays, clusters, objects) in the DLL, leave them there and return a pointer to LV. Preferably a pointer to a class. Use LV to call the methods via the pointer and return/send data only when needed through well defined get/set methods where all array sizes are defined in LV.

    In your special case, I think what is wrong is that LV does not know the size of the return string, it doesn't know the size of anything really. You have to refactor so that both the return string and b have memory allocated in LV before the call, and this includes a wrapper that returns void or int or something.

    thanks very much!

    It is not a good idea to use dlls returning pointer argument ,I think so too. because the dll is not mine, I only have the head file and dll, it seems that I must re-disposal it in C++. thanks again!

  2. hi,

    I am in trouble now!

    I have a dll , i want get same altered values from the parameters by passing pointers as arguments to a function.my function definition is as following.

    ========mydll.h========

    ##ifdef __cplusplus

    extern "C" {

    #endif

    __declspec(dllexport) char *str (int *num,char **ch);

    #ifdef __cplusplus

    }

    #endif

    =========mydll.cpp======

    #include "mydll.h"

    char *str(int *num,char **ch)

    {

    char *pstr = "this is string!";

    *num = 10;

    *ch =pstr;

    return *ch;

    }

    and then I create another project to test this dll ,it works correctly. but if I use labview to call the dll,it is incorrect.

    in c++,call the function as follows:

    int a = 0;

    char *b ="";

    char *rtnStr = str ( &a,&b);

    after executing the "str" function,the return value and all arguments are:

    a = 10;

    b = this is string!

    rtnStr = this is string!

    but in labview, I wrap this dll by setting return value as string(c string pointer),setting parameters as numeric (pointer to value) and string(c string pointer).

    I think my setting is correct!

    but the result is incorrect!

    a = 10

    b =(unknowing char)

    rtnStr = this is string!

    Why "b" can not get the string as calling in C++? if I want to get the value by passing pointer. How should I do ?

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.