Receive a cluster from a dll function

Hi,
I have a function in a DLL which returns a C struct.  I want to know how can I receive a cluster from a CLFN?
struct info:
struct typedata{
int a;
int b;
const char * c;
int d;
int e;
}data;
function call:
const typedata * hostinfo(int param);
Solved!
Go to Solution.

LVCoder wrote:
Thanks a lot both of you for letting me know about my dumb assumption that 2 different processes can use the same memory space.
Anyways, I figured out the problem with my code that was reading the double value. 
the DLL function returns the address of the struct which has 5 elements.
struct test {
int a;
int b;
int c;
double d;
double e;
suppose the address I receive is 10
address of test->a = 10
address of test->b = 14
address of test->c = 18
address of test->d = 26 // I was refering it as address 22. but I forgot that I was on a 64 bit machine and that the OS will allocate the whole memory address for a double and won't utilize the 4 bytes left in the previous memory address. 
thanks!
That has nothing to do with the bitness of your CPU or the OS. It is only dependent on the compiler alignment setting when you compile your DLL. Microsoft Compilers use a default alignment of 8 bytes. That means every variable or element inside a cluster will be aligned to the smaller one of either its own size or the default alignment.
You can change the compiler alignment either with a compiler switch or an explicit #pragma iin your source code where you declare the variables or structure typedefs.
Rolf Kalbermatter
CIT Engineering Netherlands
a division of Test & Measurement Solutions

Similar Messages

  • Pass error cluster from labview dll to teststand

    Hello,
    I just want to pass an error cluster from a dll compiled in LV7.1 to TestStand 3.1. I never receive the contents of the LV error cluster in TS. I compiled my function with standard calling convention option, this should work. In my VI I generate only an error and pass to error output.
    LV Settings:
     TS settings:
    regards
    MB

    MB,
    please follow the info in this KB:
    http://digital.ni.com/public.nsf/allkb/22BF02003B4588808625717F003ECD67?OpenDocument
    Please note that using "By Value" will never return any values to TestStand!
    You cannot use the default error-container in TestStand to receive data from the LV error cluster if you compile the VI into a LV DLL.
    So either you choose to follow the KB or you split up the error cluster in your LV VIs to return error.occurred (boolean), error.code (numeric i32) and error.msg (LV String) .
    hope this helps,
    Norbert
    CEO: What exactly is stopping us from doing this?
    Expert: Geometry
    Marketing Manager: Just ignore it.

  • Calling a function from a DLL, exectution in background mode.

    Dear Experts,
    We have created an ABAP report the calls a function from a DLL file. If the report is executed in on-line mode the program calls and executes the function from the DLL, but if the ABAP programa is executed in background mode it doesnt calls the DLL function.
    Do you know a way to solve the problem when executing in background mode?
    Best regards.
    Antonio

    Hi Gabriel,
    Let me explain in details about my DLL function.
    We are importing the business partners from legacy system into the SAP CRM system, so at the moment we created the BP master data via BAPI, I get the name of the BP and this moment I call the function in the DLL file. I export the parameter name and I receive back a simplified string with the name reduced to a code. This code I get back from the dll it is insert in a Z table, so there is no interaction in the screen, all must be executed in background mode, because there are a lot of business partners to be converted in SAP system.
    I am sending my code for your considerations.
    Instancia a DLL
      CREATE OBJECT dll 'MTCODE.CPFONET'.
      IF sy-subrc NE 0.
        RAISE without_dll.
      ENDIF.
    Move para a tabela interna IT_NAME os valores recebidos na TI_NAME
      it_name[] = ti_name[].
    Para cada registro importado
      LOOP AT it_name.
        CLEAR v_string_ret.
        wa_matchcode-zregid     = it_name-zregid.
        wa_matchcode-name1_text = it_name-name1_text.
        v_string = it_name-name1_text.
        CONDENSE  v_string.
        TRANSLATE v_string TO UPPER CASE.
        CALL METHOD  OF dll 'SetNome' EXPORTING #1 = v_string.
        CALL METHOD  OF dll 'ExecMatch'.
        CALL METHOD  OF DLL 'GetMCData' = v_string_ret.
        FREE OBJECT dll.
      Preenche os campos do match-code de acordo com o retorno da DLL
        SPLIT v_string_ret
        AT '|'
        INTO wa_matchcode-zparmcln
             wa_matchcode-zparmcfn
             v_empty
             wa_matchcode-name_first
             wa_matchcode-name_last
             wa_matchcode-namemiddle.
      Adiciona o registro com o match-code correspondente na TE_MATCHCODE
        APPEND wa_matchcode TO te_matchcode.
      ENDLOOP.

  • Call function in LabView from a DLL, then access global variable from DLL

    I have created a DLL in LabWindows with a function and a structure.  I want to call the function from within LabView and then access the global structure.  I am able to call the function from the DLL with a "Call Library Function Node" and can access the return value, but I cannot figure out how to access the global structure.  The structure is declared in the DLL header file with __declspec(dllimport) struct parameters.
    Is there any way of accessing this structure without using the Network Variable Library?
    Solved!
    Go to Solution.

    dblok wrote:
    When you say "access to" or "the address of" the global variable, do you mean to pass the variable as an argument to the function call in the DLL?  If so, then I was not really sure how to pass a cluster from LabView by using the "Call Library Function Node".
    Yes, that's exactly right.  I would include a pair of helper functions in the DLL to read and write the global variable.  Alternatively you might write separate helper functions for each field inside the global structure, depending on the number of fields and whether you want to do any validation on the values.
    You can pass a cluster by reference to a function that expects a struct by setting the parameter to Adapt to Type, so long as the cluster does not contain any variable-length elements (strings or arrays).  The cluster needs to match the struct exactly, and sometimes that involves adding extra padding bytes to make the alignment work.  Variable-length elements in LabVIEW need to be converted to clusters containing the same number of elements as the struct definition (for example, if your struct contains char name[12], you would create a cluster of 8 U8 values, and you could use String to Array of Bytes followed by Array to Cluster to convert a LabVIEW string into that format).  If the struct contains pointers it gets more complicated, and it may be easier to write functions in the DLL to access those specific elements individually.
    If you can't get this working or need help, post your code and an explanation of the error or problem you're seeing.
    EDIT: it is also possible to include a single function in the DLL that returns the address of the global variable, which LabVIEW can then use to access and modify the data, but that's more complicated and likely to lead to crashes if you don't get the memory addressing exactly right.

  • Using PostLVUserEvent function from Labview.dll

    I am trying to use the PostLVuserEvent function from the labview.dll and corresponding extcode.h file.  I have made my own dll using CVI that uses this function.  I then use Labview to call my dll.  My dll compiles fine.  No issues, no errors.  LabView can call my dll function containing the PostLVUserEvent function with no errors.  However, the event number LabView passes my dll is not the same event number I receive so no LabView event is triggered. 
    Has anyone had this issue? 
    We are trying to solve it from the LabView side and the CVI side but cannot seem to get it to work.  The examplesI have found here were compiled using C++ and those seem to work.  I do not know why when I compile my program in C, it creates the dll but does not work.   If I had to guess, i think it's an issue with pointers vs non-pointers.  When the LAbview program selects my function from the dll, it shows the argument PostLVUserEvent as a pointer when in my dll, it is not a pointer PostLVUserEvent....
    Any ideas?
    Thanks in advance. 

    Hello Blue
    Take a look to this one, it was created on C, I think the .c and the .h files will give a good idea, how the function should be implemented. It is important when calling the dll on LabVIEW, to use the std calling convention and run it on the UI thread.
    Regards
    Mart G
    Attachments:
    LabView EventTest.zip ‏1041 KB

  • LabVIEW call Win32 API DLL function from third party

    Hi everyone,
    I'm trying to build a LabVIEW 2010 interface on 32-bit Window XP system to configurate and communicate to an Anglient laser head through its USB expansion box. I contacted the vendor and they shared a win32 API with some dll files. I started with a function called "A55292Find", but the CLF node always pop up error 1097.I checked the MSDN to get the corresponding LabVIEW data type for CLF.
    My question is: Do I need to initialize those arguments? (How can I know the values of them if initialization is needed?)
    Could anyone help me figure out what's the problem?
    Here is what I have from API documents about this function:
    The A55292Find function returns lists of handles and board types for all the 55292 USB
    Expansion Modules connected to the system.
    A55292RC __cdecl A55292Find(
    HANDLE hBoxes[], // List of handles for the boxes found. (as Unsigned 32-bit integer numeric)
    BOARDTYPE PortABrdType[], // List of board types for slot A boards (as Unsigned 16-bit integer numeric)
    BOARDTYPE PortBBrdType[], // List of board types for slot B boards (as Unsigned 16-bit integer numeric)
    WORD *spMaxBoxes); // dimension for all of the passed arrays. (as Unsigned 16-bit integer array data pointer)
    // (function return type as Unsigned 32-bit integer numeric)
    Parameters
    HBoxes[] Array that will receive the list of HANDLES for all the 55292 boxes connected.
    PortABrdType[] An array that will receive Slot ‘A’ board type information for each 55292 box.
    PortBBrdType[] An array that will receive Slot ‘B’ board type information for each 55292 box.
    spMxBoxes Passes the maximum number of values that can be held in hBoxes, PortABrdType, and PortBBoardType arrays to the A55292Find routine and returns the actual number of boxes found
    The return value will be one of the following A55292RC return codes:
    Value Meaning
    A55292_NO_ERROR No error
    A55292_TIMEOUT Timeout accessing a shared memory
    Remarks
    This routine must be called to obtain handles and board type information used in calling all the other routines. If there are significantly more array elements than boxes, the routine will take longer to complete.
    These are the definitions: 
    typedef DWORD A55292RC; enum{A55292_NO_ERROR, A55292_HANDLE_ERROR,...}
    typeder WORD BOARDTYPE; enum{A55292_PCAL_BOARD, A55292_NO_BOARD, ...}
    Thanks a lot,
    Kang
    Solved!
    Go to Solution.
    Attachments:
    call A55292Find.vi ‏10 KB

    nkang11 wrote:
    Hi Mr. Kalbermatter,
    As you told me, I should try to use the defined enumeration words as control and indicator.
    For the previous CLF node, it successfully returned the hardware configuration (I have only connected a board at slot A):
    But I really want to see a string return as "A55292_PCAL_BOARD" which is defined by "typedef WORD BOARDTYPE; enumeration {...}; Does that mean I need to change the data type or do something like "converter"? Or initialize the array first, then convert it to string type?
    Right now, I'm trying to open the laser card by using "A55292PcalOpen(HANDLE hDev, SLOTSELECT SlotSelector);" function which requires to use the enumeration constants from " typedef WORD SLOTSELECT; enum {A55292_PORT_A, A55292_PORT_B};" but I'm confused to shot an constant control to a new CLF node.
    Since almost all of the arguments in dll function are typedefined as WORD, short and struct et al, I hope you could give me some hints on it.
    Thank you very much sincerely!
    Kang
    Depending on the actual C implementation you can simply create a LabVIEW enum with the according item names or use a ring control instead. Teh enum requires the numeric values of the items to be in consecutive order without any gaps in between. This is a given if the C definition never assigns a specific number to the item. If the C enum is not consecutive you need to go with a ring control instead.
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Calling CVI DLL Function from Visual Studio

    HI all ,
    Iv'e created a DLL using CVI and i'm tring to call one of it's function from visual studio 6.0
    I'm getting a general error , is there a specific prototype that i need to set my functions in ordrer to call them ?!  
    Kobi Kalif
    Software Engineer

    You will need to distribute the CVI RTE along with your DLL, since anything you write in CVI is going to use the RTE.
    As far as calling the DLL functions, you can use the CVI defined macros
    <return type> DLLEXPORT DLLSTDCALL <function name> (<param1 type> <param1> ...) {
    to declare your functions in the DLL for access by a VS application.
    for example
    int DLLEXPORT DLLSTDCALL myfunction (int funparam1, double func param2) {
    There are options for identifying which functions to export from your DLL, I use "functions marked for export" but there are other choices available.  I also include a type library so when you type the name of a DLL funciton in VS6 you see a balloon popup with the function signature.  This is a check box in the target settings.  You have to create a ".fp" file (function panel file) to collect the function info for the library.
    From VB6 you can access the DLL a couple of ways, but I usually add the DLL as a reference.

  • How to auto-recognize the function parameters called from a DLL built by VC6.0

    Hi,
    I use Teststand 3.5 with C/C++ Adapter, and the DLL is built by VC6.0.
    While I specify module for an action, the parameters of a function called from the DLL are not recognized.
    Since I have the DLL source, I know I can select the source file and verify prototype in the "Source Code" Tab.
    Under the way, almost parameters can be recognized, but some parameters, e.g. HANDLE or I definded, can not ( shows error message "The function definition cannot be found in the source file...").
    How to recognise these parameters?
    Thanks.

    The problem isn't that TestStand doesn't have enough native types. A handle can be represented in a TestStand numeric variable just fine. Instead, the issue is that when you select Verify Prototype, TestStand doesn't fully pre process your headers and compile your code to determine the types. To do so would require TestStand not only to be a full C/C++ compiler but it would also have to be able to read your compiler's projects and settings to resolve include paths, macros, etc.
    Since TestStand is not a C/C++ compiler, it just looks for the standard basic data types plus a few more that are common in test code.  Other data types will not be automatically recognized even if they can be mapped to TestStand types.
    Another option it to create a type library for your dll so that TestStand can automatically read the data type information from it. However, I don't know if that works for struct parameters and I looked for the document on devzone that explains how to do that in VC++ and it has been moved or deleted
    Maybe an AE would know of a link to a current document that describes how to do this?

  • Can I call a function from a dll in LabVIEW that returns:double*string and int.?

    I have a function from a dll that return a double* string and an integer. How can I call this function from LabVIEW? There is a possibility to work in LabVIEW with a double* string?

    pcbv wrote:
    > Hello all,<br><br>The header of the function is:
    >
    > "HRESULT WRAPIEnumerateDevices(WRAPI_NDIS_DEVICE **ppDeviceList, long *plItems);"
    >
    > where WRAPI_NDIS_DEVICE have this form:
    >
    > typedef struct WRAPI_NDIS_DEVICE<br>{<br>
    > WCHAR *pDeviceName;<br>
    > WCHAR *pDeviceDescription;<br><br>}
    > WRAPI_NDIS_DEVICE;<br><br>
    >
    > The function is from WRAPI.dll, used for communication with wireless card.
    > For my application I need to call in LabVIEW this function.
    Two difficulties I can see with this.
    First the application seems to allocate the array of references
    internally and return a pointer to that array. In that case there must
    be another function which then deallocates that array again.
    Then you would need to setup the function call to have a pointer to an
    int32 number for the deviceList parameter and another pointer to int32
    one for the plItems parameter.
    Then create another function in your DLL similar to this:
    HRESULT WRAPIEnumExtractDevice(WRAPI_NDIS_DEVICE *lpDeviceList, long i,
    CHAR lpszDeviceName, LONG lenDeviceName,
    CHAR lpszDeviceDesc, LONG lenDeviceDesc)
    if (!lpDeviceList)
    return ERROR_INV_PARAMETER;
    if (lpDeviceList[i].pDeviceName)
    WideCharToMultiByte(CP_ACP, 0,
    pDeviceList[i].pDeviceName, -1,
    lpszDeviceName, lenDeviceName,
    NULL, NULL);
    if (lpDeviceList[i].pDeviceName)
    WideCharToMultiByte(CP_ACP, 0,
    pDeviceList[i].pDeviceDescription, -1,
    lpszDeviceDesc, lenDeviceDesc,
    NULL, NULL);
    return NO_ERROR;
    Pass the int32 you got from the first parameter of the previous call as
    a simple int32 passed by value to this function (and make sure you don't
    call this function with a higher index than (plItems - 1) returned from
    the first function.
    Rolf Kalbermatter
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Call multiple functions from same dll with call library function

    hi,
    i am working on a project in wich we need to make a UI to read out a sensor network.
    the UI should be usable in any project, but every node needs a different piece of code depending on the type of sensor with wich it is equipt.
    so i need to be able to call different pieces of code when i need them, and still be able to use the UI in future projects with possibly new types of node we now don't have.
    so someone told me to use DLL's, cause then i would be able to call the code i need the moment i need it.
    but i have never worked with DLL's (just learned about this option 3 day's ago) so i have a question.
    i know i can dynamicly change the DLL i call with the call library function, but can i dynamicly change the function i call from that DLL ?
    or do i have to put a new call library function for each function i want to call, even if its from the same DLL ?
    kind regards,
    stijn

    nazarim wrote:
    ok so there is no (easy and ubderstandable) way for me to dynamicly change wich function i want to call from a certain DLL.
    but now i started wondering, the path on the call library function is not ment to dynamicly change a DLL
    but it does work so, if i am carefull, can i use it for that purpose or will labview give me a series of problems once i start using it in larger programs ?
    Thepath on the Call Library Node can be used to load a different DLL. Obviously since you can't change the function name your other DLL would have to export exactly the same function name and of course with the same parameters. This is seldom the case so it is not the main use of the path input to the Call Library Node. It's main use is as indicated to load DLLs at runtime rather than at load time of a VI. So that an application can run even when the DLL is missing, until the moment the functionality from that DLL is needed.
    If you can make sure that all your DLLs export the same function name with the same parameter you can use the Call Library Node to call into different DLLs through the path input. If however you would need to call different function names you would have to resolve to some DLL which does do the dispatching and invocation using LoadLibrary() and GetProcAddress(). But unless you need to go with DLLs for some reason using the Call By Reference Node can give you an even more flexible approach. 
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Calling a function from a dll written by using visual studio c++

    Hi, how can i call a function from a dll which is written by visual studio c++ in test stand?  Although the functions in dll are exported and i've chosen c/c++ adapter, i saw no function in test stand. Is there a different step while i'm calling a function from a dll written by c++ than calling a function from a dll written by cvi?

    Hey Sadik,
    Selecting the C/C++ DLL Adapter Module should be sufficient for this. When you drag an action step for this onto the Main Step and navigate to the location of the DLL, the function list should populate and you should be able to select the function you want to use. If this is not the case, would you be able to post this DLL so that we can test this on our end?
    Regards,
    Jackie
    DAQ Product Marketing Engineer
    National Instruments

  • Calling a native function from a dll

    Hi all,
    I want to call an api function exported from a dll using java. For example l like to call a function from kernel.dll (Windows). How can i do this. Do i have to create another dll for this?

    hi,
    you need to use JNI
    you have to create de DLL , and call kernel32.dll in.
    like that:
    java_class.class ==> first_dll.dll ==> kernel32.dll

  • Call function from C++ (dll file) in Flex

    Hi,
    i using Adobe Flash Builder with Flex 4 , i write a C++ Code in dll File , i need to access to my Function in dll file in Flex ?? what should i do ??

    Lets make sure you are performing the correct actions:
    1.  Place a Call Library Function node on your block diagram.
    2.  Double click the node to open up the Call Library Function dialog box.
    3.  Click the Browse button and navigate to the DLL function.  Select the proper DLL and click Open, or just double click on DLL.
    4.  On the Function Name box, click on down arrow.  A list of functions found in the DLL should be displayed.  Choose the function.
    5.  On the Calling Conventions box, click on down arrow and select C or WINAPI.  In your case, it should probably be C.
    6.  The Parameter box should show return type.  In the Type box, select the data type of the return value.  Since you won't see HRESULT here, you need to find out what data type HRESULT is in the C code.  I would guess it is a numeric so select numeric from the drop down list.
    7.  Click the Add a Parameter After button.
    8.  In the Parameter box, change the name arg1 to the actual name of your first parameter, which is byPortNumber.
    9.  In the Type box, choose Numeric, since a BYTE is a numeric in Labview.
    10. In the Data Type box, choose Unsigned 8-bit Integer, since a BYTE is a U8 in Labview.
    11. In the Pass box, choose Value.  If the C parameter was a pointer (*BYTE), you would choose Pointer to Value.
    12. Verify that the contents of the Function Prototype box contains the correct syntax according to the C declaration.
             C:  HRESULT RSPInitComm (BYTE byPortNumber)   should be in Labview: long RSPInitComm(Unsigned char byPortNumber)
    13. Click OK button.
    Try it out.
    If you get a crash, change the Calling Convention to WINAPI.
    - tbob
    Inventor of the WORM Global

  • FRM-40734 when calling external DLL Function from Forms 6

    Even though some answers were given to my previous help request ("Again: Forms 6 and user-defined data types") I wasn't able to solve the problem of passing a parameter of an user-defined type to an external DLL function residing in the SECURSIGN.DLL library (the closest solution was to declare that "composite" parameter using the ROWTYPE clause referencing a custom-made table created just for the sake of defining that perticular datatype).
    So I concentrated on SECURSIGN.DLL functions using more trivial data types, like a function requiring just four character strings as parameters.
    I generated the necessary PL/SQL support using the FFI.
    I discovered that also the simplest calls to external functions fail at runtime with the generic error FRM-40734.
    I located the error: it happens just at the moment of calling the function from within the FFI-generated package body. Before that, the DLL is loaded with no problem, the function is correctly registered, and a function handle is regularly returned.
    As long as I can regularly issue the very same call with the very same parameters from Visual Basic, I can't understand what's going wrong (ALL the needed DLL are in the same directory as the FMB/FMX forms).
    I will greatly appreciate any help that You may be able to provide.

    I have noticed just now that a dump file having a name like ifrun60_dump_299, is generated by FORMS every time I issue the aborted call to the foreign function.
    Inside the form dump file, apart from useless info like Registers and so on, the message:
    "Could not find Module32First"
    By a FILE/FIND/CONTAINING TEXT I searched all the DLLs, and I noticed that Module32First is a routine that can be found within each of the following DLLs:
    Cl32
    d2kwut32
    d2kwut60
    I tried to load those DLLs along with SECURSIGN.DLL by modifying the PROCEDURE LoadLibrary into the FFI-generated PLL code, and I have apparently no problem in loading all the DLLs that I wish, but the error persists, and that dump file is constantly generated, always looking for the "Module32First" routine.
    How can I avoid all that mess and the FRM-40734 error??

  • Application with a vi calling a function from kernel32.dll

    I have a Labview application which runs very well.
    I had add a vi using the functio GetSystemTime from the dll kernel32.dll. The vi calling the API function runs well. Then I tried to buil the application and it does'nt run anymore . A dialog box is opened : "access to a forbidden space memory. I don't understand.
    Does anyone have an idea?
    Thank you for your response.

    I have made at test with this function but it runs on my system.
    I have used LV 6.0.2 to LV 7.0 on a Win XP Prof. You can compare your solution with mine.
    The VI will run once when the application is called. You will see current time.
    Waldemar
    Waldemar
    Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
    Don't forget to give Kudos to good answers and/or questions
    Attachments:
    GetSystemTime.zip ‏23 KB

Maybe you are looking for

  • CAn You Sync Two iPhones to the same iTunes Account?

    Has anyone been successful in syncing two iPhones to the same iTunes account. I am the main user of our Mac and my wife just uses it for email and internet browsing. Basically she uses my user account and therefore we share one contacts list, one cal

  • Count number of rows in a table

    Hi, I have a requirement. I want to frame a SQL, which takes schema name as input and returns tables owned by that schema and number of rows inside a particular table. A Sample output: =========== Table            No. of Rows ~~~~          ~~~~~~~~ A

  • Oracle forms/reports on java

    HI ALL, We are in the midst of migrating java from 1.3 to 1.42 or 1.5. So what I would like to know is that, is there any compatibility issue with oracle forms 6i running on jre 1.5 or 1.42 and Oracle Report 9i running on JRE 1.42 or Java 1.5. Is the

  • Number range of manual check

    Hello Experts, I have ordered new manual checks. The new manual check range should be 10000 to 11000. I want to know whether I can change check number range in FCHI if there is setting before, or is there another transaction to set the number range o

  • I am having trouble launching elements 6.  i click on it but nothing happens

    i am having trouble launcing elements 6.  I click on it but nothing happens?am i doing something worng?