<div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><div>I share a method for reading result from DOE2/eQUEST by calling function in D2Result.dll.</div><div><span style="line-height: 1.7;">Before run the program,you must the D2Result.dll to your project folder.Below is the source code for c#.</span></div><div><span style="line-height: 1.7;">-------------------------------------------------------------------------------------------------------------------------------------</span></div><div><div>using System;</div><div>using System.Collections.Generic;</div><div>using System.Linq;</div><div>using System.Text;</div><div>using System.Runtime.InteropServices;</div><div><br></div><div>namespace ConsoleApplication1</div><div>{</div><div><br></div><div>    [StructLayout(LayoutKind.Sequential,Pack=4)]</div><div>    public struct MultResultsType</div><div>    {</div><div>        public int  iEntryID;      // from NHRList.txt</div><div>        public int  iReturnValue;  // success/failure</div><div>        [MarshalAs(UnmanagedType.ByValTStr,SizeConst =40)]</div><div>        public string pszReportKey;</div><div>        [MarshalAs(UnmanagedType.ByValTStr,SizeConst = 40)]</div><div>        public string pszRowKey;</div><div>    }</div><div>    class Program</div><div>    {</div><div>        [DllImport("kernel32.dll")]</div><div>        public extern static IntPtr LoadLibrary(string dllToLoad);</div><div>        [DllImport("kernel32.dll", EntryPoint = "GetProcAddress")]</div><div>        public extern static IntPtr GetProcAddress(IntPtr hModule, string procedureName);</div><div>        [DllImport("kernel32.dll", EntryPoint = "FreeLibrary")]</div><div>        public extern static bool FreeLibrary(IntPtr hModule);</div><div>        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]</div><div>        private delegate long D2R_GetSingleResult([MarshalAs(UnmanagedType.LPStr)]string pszDOE2Dir,</div><div>            [MarshalAs(UnmanagedType.LPStr)]string pszFileName,</div><div>            int iEntryID,</div><div>            float[] pfData,</div><div>            int iMaxValues,</div><div>            [MarshalAs(UnmanagedType.LPStr)]string pszReportKey,</div><div>            [MarshalAs(UnmanagedType.LPStr)]string pszRowKey);</div><div><br></div><div>        private delegate long D2R_GetMultipleResult([MarshalAs(UnmanagedType.LPStr)]string pszDOE2Dir,</div><div>            [MarshalAs(UnmanagedType.LPStr)]string pszFileName,</div><div>            int iFileType,</div><div>            //[MarshalAs(UnmanagedType.LPArray)]</div><div>            float[] pfData,</div><div>            int iMaxValues,</div><div>            int iNumMRTs,</div><div>            [In,Out]IntPtr pMRTs);</div><div><br></div><div>        unsafe public static  IntPtr MarshalArray(ref MultResultsType[] bodies)</div><div>        {</div><div>            int iSizeOfOneBodyPos = Marshal.SizeOf(typeof(MultResultsType));</div><div>            int iTotalSize = iSizeOfOneBodyPos * bodies.Length;</div><div>            IntPtr pUnmanagedBodies = Marshal.AllocHGlobal(iTotalSize);</div><div>            byte* pbyUnmanagedBodies = (byte*)(pUnmanagedBodies.ToPointer());</div><div><br></div><div>            for (int i = 0; i < bodies.Length; i++, pbyUnmanagedBodies += (iSizeOfOneBodyPos))</div><div>            {</div><div>                IntPtr pOneBodyPos = new IntPtr(pbyUnmanagedBodies);</div><div>                Marshal.StructureToPtr(bodies[i], pOneBodyPos, false);</div><div>            }</div><div><br></div><div>            return pUnmanagedBodies;</div><div>        }</div><div>       </div><div>        static void Main(string[] args)</div><div>        {</div><div>            // Dynamically Load Library</div><div>            var pDll = LoadLibrary("D2Result.dll"); // Path to D2Result.dll</div><div>            // Get Address of Function</div><div>            var pFunctionAddress = GetProcAddress(pDll, "D2R_GetMultipleResult");</div><div>            // Instantiate Delegate</div><div>            D2R_GetMultipleResult D2R_GetMultipleResult = (D2R_GetMultipleResult)Marshal.GetDelegateForFunctionPointer(pFunctionAddress, typeof(D2R_GetMultipleResult));</div><div><br></div><div>            string pszDOE2Dir = "doe22\\exent.ref\\"; // Insert path to DOE-2 Dir i.e "C:\\DOE-2\\</div><div>            string pszFileName = "Project 10\\Project 10 - Baseline Design"; // Insert file path of where the input and run files are kept</div><div>           </div><div>            float[] pfData = new float[1] ;</div><div>            //string pszReportKey = null;</div><div>            //string pszRowKey = null;</div><div>            MultResultsType[] MRTs=new MultResultsType[4];</div><div>            MRTs[0].iEntryID = 2309007;    // EM1 array from PS-F</div><div>            MRTs[0].pszReportKey = "EM1";</div><div>            MRTs[0].pszRowKey = "";</div><div><br></div><div>            MRTs[1].iEntryID = 2309007;    // EM2 array from PS-F</div><div>            MRTs[1].pszReportKey = "EM1";</div><div>            MRTs[1].pszRowKey = "";</div><div><br></div><div>            MRTs[2].iEntryID = 2305005;    // Elec Mtr Totals from PS-E</div><div>            MRTs[2].pszReportKey = "";</div><div>            MRTs[2].pszRowKey = "";<span style="line-height: 1.7;">     </span></div><div>            IntPtr pt = MarshalArray(ref MRTs);</div><div>            float[] fResults=new float[39];</div><div>            long lRetVal = D2R_GetMultipleResult(</div><div>                                 pszDOE2Dir,</div><div>                                 pszFileName,</div><div>                                 1, fResults, 39, 3, pt);</div><div><br></div><div><br></div><div>           // long result = getSingleResult(pszDOE2Dir, pszFileName, iEntryID, pfData, iMaxValues, pszReportKey, pszRowKey);</div><div>            for (int i = 0; i < 39;i++ )</div><div>                Console.WriteLine("pfData is {0}", fResults[i]);</div><div><br></div><div>            bool freedom = FreeLibrary(pDll);</div><div>           </div><div>            Console.ReadKey();</div><div>        }</div><div>    }</div><div>}</div></div><div><p style="margin: 0px 0px 14px; padding: 0px 5px 5px 0px; border: none; line-height: 1.4; color: rgb(75, 75, 75);"><br></p></div></div><br><br><span title="neteasefooter"><p> </p></span>