Announcement

Collapse
No announcement yet.

Read data from DLL

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Read data from DLL

    Hi, I am new with ESignal.

    sorry if this is a repeat, this is my second time trying to post this message out.


    I have an EFS file that send data to a DLL for computation and get the result back. I am able to get the code running but the EFS is not able to get the data back from the DLL. Here is snippet of my EFS and C++ code. Can someone tell me what is wrong? I've tried many different cases unsuccessfully.

    Thanks,
    Anthony.

    EFS code:
    var one1 = null;
    var two2 = null;
    var dll = new DLL("myDLL.dll");

    in preMain function:
    dll.addFunction("getframe", DLL.INT, DLL.CDECL, "Testing123", DLL.INT, DLL.INT);

    in main function:
    var retVal = dll.call( "getframe", one1, two2);
    // one1 and two2 are return null

    in C++ code:
    extern "C" int __declspec(dllexport) __cdecl Testing123(int one1, int two2)
    {
    one1 = 15000;
    two2 = 0;
    return 0;
    }

    the DLL is put in c:\program files\esignal folder.

  • #2
    Hello topagent006,

    I'm not a c++ expert, but it looks like your c++ function is returning a 0. Is this what you are seeing in your EFS? What happens if you change the return statement in the c++ function to return 1?
    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation

    Comment


    • #3
      same thing. still not able to get the data.

      Comment


      • #4
        It is very shameful if eSignal cannot help this request since they claim they support function call to DLL. At least, they can provide, like Doji mentioned, a template so that developers can start their code development out of it.

        Doji, thanks for your "help". I give a chance to eSignal to respond. If I get nothing, then I have to look at alternatives.

        Anthony.

        Comment


        • #5
          Hello Anthony,

          We definitely will help you resolve this issue. I don't have an immediate solution for you. Please post the test dll you've created along with your testing formula. I will enlist some help from our internal developers here that can assist us with the c++ side.

          We will also work on putting some additional examples into the knowledgebase.
          Jason K.
          Project Manager
          eSignal - an Interactive Data company

          EFS KnowledgeBase
          JavaScript for EFS Video Series
          EFS Beginner Tutorial Series
          EFS Glossary
          Custom EFS Development Policy

          New User Orientation

          Comment


          • #6
            Thanks in advance, Jason.

            See attached for the efs file.

            To create the DLL, follow the next steps:
            1. Open Visual Studio 6.0
            2. Create New Projects with Win32 Dynamic-Link Library, use "myDLL" as the Project name.
            3. Select a simple DLL project and click Finish.
            4. In the myDLL.cpp file, copy the code below
            extern "C" int __declspec(dllexport) __cdecl Testing123(int one1, int two2)
            {
            one1 = 15000;
            two2 = 0;
            return 0;
            }
            5. Build in Release mode and copy the 28KB DLL into C:\program files\esignal folder

            Once you load the efs file, there is nothing plotted on the screen.

            Hope I give you enough information to get internal developers to debug on it. Please let me know if you need further information.

            Anthony.
            Attached Files

            Comment


            • #7
              Hello Anthony,

              Thank you for posting the EFS and detailed instructions. I believe I have an understanding of the problem. First note that the .dll file that I copied to the \esignal\folder came from the \debug\ folder under the project folder. The file size was 196KB. Not sure if that has anything to do with the issue, but thought I'd mention it.

              The problem I see is that your EFS variables, one1, and two2 were set to null. As a result they were being passed as null values to the dll.call() statement. The parameters for that call are expecting integer values. All I did was change the declarations for the variables on lines 2 and 3 to set the initial values to 0 and the rest of the formula code worked.

              Note that retVal will be set to 0 based on your c++ function. If you add retVal to your return statement in main() you should see a 0 plotted for that series in the cursor window and on the chart.

              PHP Code:
              // initialize global variables
              var one1 0;  // changed to non-null value
              var two2 0;  // changed to non-null value
              var dll = new DLL("myDLL.dll"); 

              function 
              preMain() 
              {
                
              setPriceStudy(true);
                
              setStudyTitle("Testing");
                
                
              dll.addFunction("getframe"DLL.INTDLL.CDECL "Testing123"DLL.INTDLL.INT);  

              }

              function 
              main(framedayback
              {

                var 
              retVal dll.call"getframe"one1two2);

                return new Array(
              one1two2high(0), retVal);

              Please let us know if this resolves the problem for you.
              Jason K.
              Project Manager
              eSignal - an Interactive Data company

              EFS KnowledgeBase
              JavaScript for EFS Video Series
              EFS Beginner Tutorial Series
              EFS Glossary
              Custom EFS Development Policy

              New User Orientation

              Comment


              • #8
                Jason,

                It did not resolve it. In the C++ function, I set the variable one1 to 15000. I expect to get this value back in the script as 15000, not 0.

                The DLL in release mode is only 28KB. You have to build in Release mode (click on Build menu, set active configuration, select release).

                And then, thinking I am dealing with C++, I try to pass by reference
                extern "C" int __declspec(dllexport) __cdecl Testing123(int& one1, int& two2)
                and by pointer
                extern "C" int __declspec(dllexport) __cdecl Testing123(int* one1, int* two2) ,
                in either case, I crash eSignal SW.

                I am running out of idea at this point.

                Anthony.

                Comment


                • #9
                  Hello Anthony,

                  The EFS and dll works the same on my end also with the release mode.

                  The EFS variable, retVal, will be assigned with the return value from the dll. Currently the dll function returns a hard coded 0.

                  The variables that are being used in the dll do not have an effect on the global variables in the EFS as you are expecting.

                  The intended purpose of the EFS DLL object is to pass data from the EFS environment to a dll function for custom calculations that are returned to the EFS via the .call() method. Any processes outside of this are not supported.
                  Jason K.
                  Project Manager
                  eSignal - an Interactive Data company

                  EFS KnowledgeBase
                  JavaScript for EFS Video Series
                  EFS Beginner Tutorial Series
                  EFS Glossary
                  Custom EFS Development Policy

                  New User Orientation

                  Comment


                  • #10
                    Jason,

                    I think there is a misunderstanding in here. In my C++ code, I never use local variable. I assign value to the parameters that were passed by EFS. Like you stated below, "The EFS variable, retVal, will be assigned with the return value from the dll." I expect my values 15000 and 0 are assigned back to EFS variables through the parameter passing. At this point in time, the code is not doing it. Why? What is the right format/signature to use?

                    Anthony.

                    Comment


                    • #11
                      Anthony,

                      From your code it's clear that you are expecting the DLL C code to change the value of a variable in the JavaScript code. This is not how the DLL interface to JavaScript works. It is going to pass the value of a variable, not a refrence to it. Changing the variable in your C code won't change it in the JavaScript code since you were given a copy of the value.

                      You need to modifiy your DLL code to return the 15000 value and then assign that returned value to one1 in your JavaScript code. Same thing for two2. This will likely involve writing two functions in your DLL. One to compute the value for one1 and another to compute the value for two2.

                      Maybe something like this....
                      extern "C" int __declspec(dllexport) __cdecl TestingOne1(int one1, int two2)
                      {
                      // some actual code here to compute stuff
                      return 15000 ; // return results of the computation
                      }

                      extern "C" int __declspec(dllexport) __cdecl TestingTwo2(int one1, int two2)
                      {
                      // some actual code here to compute stuff
                      return 0;
                      }

                      Then in your efs you would have 2 dll.AddFunction calls to define getframe1 and getframe 2 and then add the following code...
                      var one1 = dll.call( "getframe1", one1, two2);

                      var two2 = dll.call( "getframe2", one1, two2);

                      Basically you will need one function for each variable you want to get a value for in your efs.

                      Hope this helps.

                      Steve

                      Comment


                      • #12
                        Steve,

                        Thank you very much for the pointer. I got it to work now. Here is the final code.

                        Anthony.

                        EFS Code:
                        var one1 = null;
                        var two2 = null;
                        var dll = new DLL("myDLL.dll");

                        function preMain()
                        {
                        setPriceStudy(true);
                        setStudyTitle("Example DLL Call");
                        setCursorLabelName("one1", 0);
                        setCursorLabelName("two2", 1);
                        dll.addFunction("setframe", DLL.INT, DLL.CDECL, "Testing123", DLL.INT, DLL.INT);
                        dll.addFunction("getlow", DLL.INT, DLL.CDECL, "Testinglow");
                        dll.addFunction("gethigh", DLL.INT, DLL.CDECL, "Testinghigh");
                        }

                        function main(frame, dayback)
                        {
                        one1 = 13000;
                        two2 = 13500;
                        var retVal = dll.call("setframe", one1, two2);
                        one1 = dll.call("getlow");
                        two2 = dll.call("gethigh");
                        return new Array(one1, two2);
                        }


                        C++ Code:
                        static int low = 0;
                        static int high = 0;

                        extern "C" int __declspec(dllexport) __cdecl Testing123(int one1, int two2)
                        {
                        low = one1 + 100;
                        high = two2 + 100;
                        return 0;
                        }

                        extern "C" int __declspec(dllexport) __cdecl Testinglow()
                        {
                        return low;
                        }

                        extern "C" int __declspec(dllexport) __cdecl Testinghigh()
                        {
                        return high;
                        }

                        Comment


                        • #13
                          Anthony,

                          Glad you got it to work.

                          I'm just curious, the code you've shown could be done in javascript using functions and you wouldn't have to go thru all the problems. Is there a reason you're using a DLL?

                          Steve

                          Comment


                          • #14
                            Steve,

                            I am building up a bigger project where I put all the decision making in the DLL and let EFS handle display mechanism. Down the road, when I plan to support other platforms than eSignal, I then don't have to rewrite my DLL.

                            Anthony.

                            Comment

                            Working...
                            X