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.

Similar Messages

  • How can I access JSP variables from a JavaScript function in a JSP page?

    Respected sir
    How can I access JSP variables from a JavaScript function in a JSP page?
    Thanx

    You may be get some help from the code below.
    <%
        String str="str";
    %>
    <script>
        function accessVar(){
           var varStr='<%=str%>';
           alert(varStr);// here will diplay 'str'
    </script>

  • HT5622 I have two iPhones synced with the same Apple ID and so the contacts are being shared in both of them. Is there any way to revert this?? The reason is that if I delete some contact from one device then it automatically erases from the second one as

    I have two iPhones synced with the same Apple ID and so the contacts are being shared in both of them. Is there any way to revert this?? The reason is that if I delete some contact from one device then it automatically erases from the second one as well

    Yes, you stop using the same Apple ID under Settings > iCloud.

  • How to get value for a global variable from an exel file?

    Hallo all,
    I am a beginner in LabVIEW and I have  a problem in reading datas from an exel file . I would like to import a group of data with timestamps from exel file to a global variable. for ex. speed, acceleration and position of 4 different sensors to each of its global variable.
    It will be very nice if anyone can give me some ideas.
    Thanking you in advance

    ...continued here

  • Access global variable in fpga from rt-target

    Hi All,
    I have a realtime PC with NI-FPGA 7852R.
    Generally I used programmatic front panel communication to access variables from FPGA to rt-system since I need the data for control and not for data logging.
    The thing is, I bumped into a tutorial and suggested me to use global variables to save resources of your FPGA. My question is, is it possible to access global variable that belongs to FPGA from rt-system? As far as I tried, this does not seem possible.
    Thanks,
    Auralius

    Could you point us towards this tutorial?
    Chris
    Certified LabVIEW Architect
    Certified TestStand Architect

  • Accessing public variables from other classes

    Probably a simple questions, but how can I access a variable from another class. My exact situation is as follows.
    A class called WorldCalender has a variable which is defined: public int hour; (the value is given to it elsewhere).
    I want to access this variable and increase it by one in a subroutine in the class Hour. In this class I have put: WorldCalender.hour++; but it doesn't seem to work. How should I do it?

    don't expose the hour variable at all.
    have a method eg addToHourBy( int hrs )
    Probably a simple questions, but how can I access a
    variable from another class. My exact situation is as
    follows.
    A class called WorldCalender has a variable which is
    defined: public int hour; (the value is given to it
    elsewhere).
    I want to access this variable and increase it by one
    in a subroutine in the class Hour. In this class I
    have put: WorldCalender.hour++; but it doesn't seem to
    work. How should I do it?

  • How to build labview global variable into dll?And how to use it in vc++ program?

    Hi!
       I want to build labview application into dll and use vc++ to call it.The labview program is a little complex,for it has many interface to vc++ and has while loop in it.When I use vc++ to call it,I must use vc++ to do other things.That is to say,vc++ creates a new thread to provide for the labview dll to run.the vc main thread goes on to other things.But the vc++ main thread must communicate with the labview dll by setting its inputs' parameters and get the results of running labview dll.Can you advise me how to realize it?
       I think global variable of labview could be useful when realizing the communication betweeb vc thread and labview dll.So I want to ask whether the labview global variable could also be built into dll and use it.Could you please tell me how to realize my idea?
       Thank you!

    [email protected] wrote:
    Hi!
    I want to build labview application into dll and use vc++ to call
    it.The labview program is a little complex,for it has many interface to
    vc++ and has while loop in it.When I use vc++ to call it,I must use
    vc++ to do other things.That is to say,vc++ creates a new thread to
    provide for the labview dll to run.the vc main thread goes on to other
    things.But the vc++ main thread must communicate with the labview dll
    by setting its inputs' parameters and get the results of running
    labview dll.Can you advise me how to realize it?
       I
    think global variable of labview could be useful when realizing the
    communication betweeb vc thread and labview dll.So I want to ask
    whether the labview global variable could also be built into dll and
    use it.Could you please tell me how to realize my idea?
       Thank you!
    You
    can't access LabVIEW globals directly from a caller to the LabVIEW DLL.
    However there is no problem in providing specific accessor VI functions
    to that global and export them as additional functions from the DLL.
    Rolf Kalbermatter
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Access payroll variables from custom payroll function

    Hi All,
    I have a requirement to create a custom payroll function that returns some data from IT0006 and IT0032.
    I have written the code in PCBURZDE0, as the payroll is for Germany, it does read the data needed.
    My question is, how I can access the variables specified for the function in the payroll schema.
    Schema definition in PE01
    Zeile     Fkt        Par1  Par2 Par3 Par4 D Text
    000010 BLOCK BEG                              Fahrradleasing
    000020 _DFRD &PRO GEN
    000030 BLOCK END
    If I double-click Par1 for function _DFRD (&PRO), then I see he two variables I should write the data to:
    Zeile  VarArg. FZ T Operation        Operation Operation Operation Operation Operation *
           -------------+---------+------------------+---------+---------+---------+---------+
    000010                  AMT= PKWWRPRINT     *
    000020           1     AMT= ENTKM  PRINT
    So, as I understand I should write the two variables PKWWR and ENTKM, I have the values in the function code, but I don't know how to access these variables.
    Thanks for your help!
    Gyöngyi

    1 - PIT is a Function that is used in the Payroll Schema to "Process the Internal Table".
    2 - You mentioned that you had created a Custom Function to read IT0006 and IT0032, and I only suggested to you that you could have that Custom Function generate Information WageTypes and save them in the Input Table where they could then be used in PCRs.
    3 - I did not mention that you can read only one value through operation AMT, but I mentioned that using AMT=xxxxxx followed by AMT=yyyyyy means that the first statement is useless.  On the other hand, using AMT=xxxxxx followed by AMT+yyyyyy and AMT+zzzzzz will result in the amount being the total of the 3 values.
    4 - Please read some documents on Schemas, Functions and PCRs, such as in the Wikis on this site, and study your current Payroll Schema, it's sub-schemas, it's functions and the operations in it's PCRs.  Note that t-code pe01, pe02 and pe04 can be used to find some documentation on functions and operations.

  • How can I handle global variables from different DLLs created based on VIs that access those variables

    My goal is to break apart an entirely LabView created application so I can still use parts of it (builded as Shared DLLs upon on some VIs) in my new .Net application. My problem is that some others VIs (that I am not intending using) are changing those global variables (in the natural data flow of the application).  I could , of course, send the values of those global variables as parameters, but I don't know how should I pass those data types (and their size)... There are some clusters there...
    Any help is well appreciated

    vulpe wrote:
    My goal is to break apart an
    entirely LabView created application so I can still use parts of it
    (builded as Shared DLLs upon on some VIs) in my new .Net application.
    My problem is that some others VIs (that I am not intending using) are
    changing those global variables (in the natural data flow of the
    application).  I could , of course, send the values of those
    global variables as parameters, but I don't know how should I pass
    those data types (and their size)... There are some clusters there...
    Any help is well appreciated
    Your
    problem is of course the use of globals. That is almost always a bad
    idea and asking for troubles once your application gets bigger.
    Avoiding race conditions and undesired influences between different
    parts of your application will take up more and more of your
    development time as your project grows.
    You should look into Functional Globals (LV2 style globals) and shift
    registers for data storage and queues for passing information between
    different parts of your applciation. Using these techniques
    consequently, will require you to spend some more time initially but
    will allow you to grow your application without increasing the
    complexity of managing such things exponentially.
    Rolf Kalbermatter
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • How to declare a global variable from a PL/SQL package

    Hi All,
    Using a global variable is a bad practise for all language. However, in my case, I have a PL/SQL package defines all constants, and I want to use them directly via SQL statement, for instance,
    PACKAGE my_const
    IS
         DEFAULT_ZIP_CODE CONSTANT VARCHAR2(5) := '00000';
    END;And I cannot referrence this variable from my select statement as
    SELECT my_const.DEFAULT_ZIP_CODE from dual;I have to create a function via my package, as,
    FUNCTION get_default_zip_code RETURN VARCHAR2
    IS
    BEGIN
         RETURN DEFAULT_ZIP_CODE;
    END;and
    SELECT my_const.get_default_zip_code from dual;I don't want to create functions to referrence the default varaibles. Does anyone have any clues?
    thanks
    Edited by: user4184769 on Jul 19, 2010 8:36 AM

    riedelme wrote:
    thanks for the info. Your scope explanation makes sense even though it is not intuitive to me. I think the usage of package variables should be supported by SQL (they're just values to be copied) Maybe look at it from another language's perspective. You want to use a global PL package variable in Java/C#/Delphi/VB/etc. How would you do it?
    None of these languages can crack open the data segment of a PL code unit, inspect the variables in it, and extract a value from it. Instead, it needs to be done as follows:
    Using sqlplus as the client illustrates how all these languages will need to do it:
    SQL> var value varchar2(20);
    SQL> begin
      2>     :value := SomePackage.someVar;
      3> end;
      4> /So why should SQL behave differently? It is not the same as the PL language. It is not a subset of the PL language. Yeah, PL/SQL blurs the line between these 2 languages making it very simple for us to mix their source code. But PL/SQL is SQL integrated with PL - not PL integrated with SQL. PL has tight hooks into SQL, creating cursors for you, defining bind variables, binding variables and doing the whole Oracle Call Interface bit for you.
    But SQL has no need for PL code, just as it has no need for Java code, or Delphi code or VB code. Yes, it is possible for it to call Java stored procs. As it is possible for it to call PL procs. But these are via the formal call interface of those languages - not via tight integration hooks that blur the languages and make SQL and Java, or SQL and PL, look like a single integrated source code unit.
    Thus SQL has the pretty much the same constraints in calling the PL language as other languages do. What SQL can do is use the PL engine's call interface and tell it "+execute this function and return the result of the function+".

  • Accessing another variable from another application

    I was wonder how I can access another variable form another application?
    For example: I want to access :P4_EMPLOYEE_NAME from app ID 104 when I am doing is from an activity in page 2 on app ID 142.
    I had a search before, but I am looking for an unambiguous response.

    Greg - About all you can do is call the function htmldb_util.fetch_app_item(p_item => 'F104_ITEM', p_app => '104'). The application you call this function in must be sharing a session with the application from which you are fetching the item, both applications must belong to the same workspace, and the item you name in the argument must be defined as an application-level item in the fetched-from application.
    Scott

  • Why does Labview create a .vi for each global variables?

    Hello,
    I wrote an Labview application which use several global variables (almost 30 variables). All the variables are of variable type "single process". For each of these variables, Labview creates a vi.
    For example, for the variable "_TS.Measures.channes", Labview creates a vi named "TS_'_TS.Measures.channels'.vi". Which means, I have almost 30 "name of variable".vi files: this is confusing!
    All my VI are inside library (.llb). When I try to put the VI of a global variable in a library, Labview can't find them anymore.
    May be can somebody explain me, why LabVIEW does create these VI and how is it possible to put them in a library.
    Cheers,
    Risotto

    Hi everybody,
    Thank you for your answers, I get a lot of informations.
    Yes, I use the new shared variables in LabVIEW8, which I am using like sort of global constants. Now I am understanding what guys are telling me all this about global variables in LabVIEW7.1. Sorry, I forgot to say I was using LabvVIEW8.
    I will have a look on the tutorial too.
    But yet one point about the library collecting all the shared variables in the windows explorer and in the project explorer: When I create a shared variable in my LabVIEW project - for example "test1" as double/single process - the variable doesn't appear in my file directory, but it appears in the project explorer in a library (.lvlib).
    When I drag/paste my shared variable on the block diagramm of my VI, then a file "Math_test1.vi" appears in my file directory. There is no extra .llb created to contain my shared variable vi.
    If I drag/paste the file "Math_test1.vi" in the Math.llb (see picture), then the file is moved in the llb and disapeared from the directory.
    If I created another shared variable "test2" as double/single process and put it on the VI, then LabVIEW creates2 files in the directory: "Math_test1.vi" and "Math_test2.vi". So that I get 2 vi for the "test1" variable now (one in the llb and one in the directory).
    I use several library in the project explorer. But the  library in the project explorer seems to create file with other extension (.lvlib) than the sdtandard LabVIEW library (.llb).
    Cheers,
    Risotto
    Attachments:
    picture.jpg ‏223 KB

  • Accessing a variable from another script

    Is it possible to create a global variable in VB in the Job VBA code and to access it from VB in the scripts contained in that job? I want to dynamically create a value (a random email address) for use in one script where it is used for registration and then use it again in a second script for login.

    I had a similar requirement and used a slightly different approach to solve it.
    I had to produce some random char strings that would be client IDs to create test client records in my web app. I needed to reference these random client IDs in both a create script and a modify script.
    I found that (and I guess this can come down to personal preference) it was easy to create a "utility function" that writes a file with however many random strings you want in csv format. If your target scripts don't have databanks, just play this sub in the VBA editor, and then throw the output file into the databank folder and databank the field of interest. For subsequent runs, just play the sub in the VBA editor for fresh data. Worst case, you have an existing databank, and you just need to paste this file into it in excel as a new column. Not a big deal. Here's an example of a function I have that I changed such that it would create a list of random email addresses to a csv file everytime you run the sub in VBA. Just drop this in your VBA workspace sharedmodule:
    Private Sub CreateMemberEmailFile()
    Dim intA As Integer
    Dim sngA As Single
    Dim strA As String
    'Dim x As Integer
    Dim str As String
    Dim answer As Boolean
    Dim fs As Scripting.FileSystemObject
    Dim myfile As Scripting.TextStream
    Set fs = New Scripting.FileSystemObject 'Create a new file system object
    ' put the file anywhere you want, doesnt matter
    Set myfile = fs.OpenTextFile("c:\memberemailid.csv", ForWriting)
    myfile.WriteLine "MemberEmailID"
    ' ok, this creates 50 random emails...feel free to change 50 to whatever you desire
    For y = 1 To 50
    str = ""
    For x = 0 To 9
    'sngA = Rnd
    'Select Case (CInt(sngA * 200) Mod 3)
    ' Case 0
    ' intA = CInt(sngA * 48) + CInt(sngA * 10)
    ' intA = 48 + (intA Mod 10)
    'Case 1
    ' intA = CInt(sngA * 65) + CInt(sngA * 26)
    ' intA = 65 + (intA Mod 26)
    'Case 2
    ' intA = CInt(sngA * 97) + CInt(sngA * 26)
    ' intA = 97 + (intA Mod 26)
    'End Select
    'make intA a random number from 0-9
    intA = RandNum(0, 9)
    strA = CStr(intA)
    str = str & strA
    Next x
    str = str & "@test.com"
    myfile.WriteLine str 'write the message to identify a different line
    Next y
    myfile.Close 'Close the file
    Set myfile = Nothing ' Release the variables
    Set fsoData = Nothing ' Release the variables
    End Sub

  • Reading a global variable from tomcat with JNDI. Example not working

    Hi you can help me to make this example work?
    Context initCtx = new InitialContext();
    Context envCtx = (Context)initCtx.lookup("java:comp/env");
    Object o = envCtx.lookup("testvariable");
    <GlobalNamingResources>
    <Environment name="testvariable" type="java.lang.Boolean" value="false"/>
    Nice greetings Christian

    I found out that in addition to having the JNDI lookup code, you have to
    - have the environment variable declared in the app server configuration
    - have a resource-env-ref entry in your webapp module
    - have the application container bind your named variable with the global variable
    I am using tomcat 5.5, and have done the following. with success.
    the following example uses the default sample environment variable in the tomcat server.xml
    in tomcat server.xml:
    <GlobalNamingResources>
    <Environment
    name="simpleValue"
    type="java.lang.Integer"
    value="30"/>
    </GlobalNamingResources>
    in my application's web.xml:
    <resource-env-ref>
    <description>Test read resource environment variable</description>
    <resource-env-ref-name>simpleValue</resource-env-ref-name>
    <resource-env-ref-type>java.lang.Integer</resource-env-ref-type>
    </resource-env-ref>
    in my META-INF/context.xml (or otherwise, in tomcat's context deployment configuration)
    <ResourceLink name="simpleValue" global="simpleValue"
    type="java.lang.Integer"/>
    Note: in theory, the named resource by your web app could be different from the global environment variable, but here they are the same 'simpleValue'
    This is the really important step, that with out it, nothing works.,
    the context.xml is known to work with tomcat when it exists in META-INF/context.xml inside the .war file (i use war files to deploy, but you should be able to create META-INF/context in an unpacked webapp directory too, and tomcat will find it.,
    I can not say what it is like for other app servers, but this mapping step is the critical point that i discovered after A LOT of hair pulling.
    then, make use of it, i created a jndiTest.jsp:
    <%@ page import="javax.naming.Context" %>
    <%@ page import="javax.naming.InitialContext" %>
    <%@ page import="javax.naming.NamingException" %>
    <%
    try {
    Context initCtx = new InitialContext();
    Context ctx = (Context) initCtx.lookup("java:/comp/env");
    Object o = ctx.lookup("simpleValue");
    %>
    <%=o%><br>
    <%
    catch (NamingException ex) {
    System.err.println(ex);
    %>
    since my server.xml defines the value for 'simpleValue' to be 30, this page displays 30

  • Problem accessing session variable from jsp

    Hi!
    I get an error retrieving a session variable from inside a JSP declaration scriptlet....
    Something like this code in a JSP page:
    <%!
    public void funtion1() {
    String parameter1 = session.getAttribute("parameter1");
    %>I have seen that I have available getContextServer() method and from there I could call getAttribute("parameter1") . But the thing is that the attribute I want to retrieve was stored in session by another Jsp page.
    Any solutions are welcome
    Cheers
    Victor

    Appropriately the above is one the reasons also You cannot use JSP implicit objects from the declaration tag. However we can think of a small workaround by passing the reference like the one discussed below
    <%!public void funtion1(HttpSession session) {
    String parameter1 = session.getAttribute("parameter1").toString();
    }%>
    <% funtion1(session);%>Hope that helps :)
    REGARDS,
    RaHuL

Maybe you are looking for

  • Problem with saving optimized PDF 900dpi, image is partially repeated... is this a bug in Acrobat Pro 10.1.10?

    I try to save a bigformat PDF file (1.4 Gb) with save optimize PDF. Hereby I send some screendumps to make this stuf clear. See screen after at the right; Is this problem a bug in Acrobat or due to Hardware problems? I use the newest Mac Pro with 32

  • No service on cellular on Ipad 1st gen

    Done a hard reset , reset network settings , tried  new Payg sim , as reported on various forums but still no cellular connection.. Worked perfectly up until a month ago .. Any clues from anybody

  • Brief Idea of Java Technology !

    Hi all, I m a Form/Report Developer in 11g and want to use JAVA in my 11g Forms/Reports application. But I have a little knowledge of Java, and Java has also so many technologies, and confuse to start the technology. So, want some brief idea of all J

  • Sharing a calendar to a group

    We just upgraded to Mavericks Server, and I was delighted that it accepted a group name as a sharing recipient for a Calendar; however, it doesn't actually send invitations to the people in the group. In fact, as far as I can tell, it doesn't do anyt

  • SAP SD CIN Query-3

    Hi I am facing a problem in CIN. I updated the RG1 register(J1I5) for only a few movement types and now when i try to extract it (J2I5). The system gives me error. No error details but only a Red cross mark against register name (i.e. RG1). Please su