当我在项目中使用DLL时,不会采用文件路径 [英] When I use the DLL in my project the file path is not taken

查看:50
本文介绍了当我在项目中使用DLL时,不会采用文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个dll名称是PointinPolygon1,这里有两个类文件,名称是pointk和polygon



这里我粘贴我的代码



PointinPolygon1.cs

i have created one dll name is PointinPolygon1 in this have two class files the name is pointk and polygon

here i paste my code

PointinPolygon1.cs

public  class PointinPolygon1
    {
        public Polygon poly = new Polygon();
        public Pointk pt;
        public int count = 0;
        //string latti;
        double pi = 3.14159;
        double earthRadius = 3964.037911746;
       // pt=new Point(15.219171, 78.691695);
         public bool PointInPolygon(Pointk point, Polygon polygon)
         {
             int i,j,nvert=polygon.Points.Count();
             bool c=false;
             for(i=0,j=nvert-1;i<nvert;j=i++)
             {
                 Pointk iPt=polygon.getPointAtIndex(i);
                 Pointk jPt=polygon.getPointAtIndex(j);
                 if(((iPt.longitude>=point.longitude)!=(jPt.longitude>=point.longitude))&&(point.lattitude<=(jPt.lattitude-iPt.lattitude)*(point.longitude-iPt.longitude)/(jPt.longitude-iPt.longitude)+iPt.lattitude))
                     c=!c;

                     
             }
             return c;
         }
        public Pointk Addmovementsperhour(double heading,double speedMph,TimeSpan Duration,Pointk point1)
         {
             double x = speedMph * System.Math.Sin(heading * pi / 180) * Duration.TotalSeconds / 3600;
             double y = speedMph * System.Math.Cos(heading * pi / 180) * Duration.TotalSeconds / 3600;
             double newLat = point1.lattitude + 180 / pi * y / earthRadius;
             double newlong = point1.longitude + 180 / pi / System.Math.Sin(point1.lattitude * pi / 180) * x / earthRadius;
             return new Pointk(newLat, newlong);
         }
        public Boolean getpolygonvalues(double heading, double speed, double lattitude, double longitude)
        {

            List<Polygon> polygonList = new List<Polygon>();
            string path = @"f:\Polygon.txt";

            string[] Polygonpoints = File.ReadAllLines(path);
            for (int i = 0; i < Polygonpoints.Length; i++)
            {
                string s1 = Polygonpoints[i];
                string[] A = s1.Split('=');
                if (A[0].Trim() == "PolygonPoints")
                {
                    poly = new Polygon();
                    string S2 = A[1].Trim();
                    string [] B=S2.Split(' ');
                    foreach(string Polygon in B)
                    {
                        string[] S3 = Polygon.Split(',');
                        Pointk pt1 = new Pointk(Convert.ToDouble(S3[1]),Convert.ToDouble(S3[0]));
                        poly.addPoint(pt1);
                    }
                }
                else if (A[0].Trim() == "PolygonName")
                {
                    poly.setPolygonName(A[1].Trim().ToString());
                }
                else if (A[0].Trim() == "AirPortCode")
                {
                    poly.setAirportName(A[1].Trim().ToString());
                    polygonList.Add(poly);
                }
            }
            pt=new Pointk(15.219171, 78.691695);
            Pointk lpoint = Addmovementsperhour(50, 50, TimeSpan.FromSeconds(10), pt);
            Pointk mpoint = Addmovementsperhour(55, 50, TimeSpan.FromSeconds(10), pt);
            Pointk rpoint = Addmovementsperhour(60, 50, TimeSpan.FromSeconds(10), pt);
            for (int i = 0; i < polygonList.Count; i++)
            {
                Polygon tpoly = (Polygon)polygonList[i];
                Boolean retval = false;
                retval = PointInPolygon(pt, tpoly);
                if (retval)
                    return retval;
                retval = PointInPolygon(lpoint, tpoly);
                if (retval)
                    return retval;
                retval = PointInPolygon(mpoint, tpoly);
                if (retval)
                    return retval;
                retval = PointInPolygon(rpoint, tpoly);
                if (retval)
                    return retval;
            }

            return false;
        }
    }



pointk.cs




pointk.cs

public class Pointk
    {
        public double lattitude;
        public double longitude;
        public Pointk(double x, double y)
        {
            lattitude = x;
            longitude = y;
        }



       
    }



Polygon.cs


Polygon.cs

public class Polygon
    {
        public List<Pointk> Points;
        string Polygonname;
        string AirportName;

        public Polygon()
        {
            Points = new List<Pointk>();
        }
        public void addPoint(Pointk p)
        {
            Points.Add(p);
        }

        public string getPolygonName()
        {
            return Polygonname;
        }
        public string getairportname()
        {
            return AirportName;
        }
        public void setAirportName(string Aname)
        {
            AirportName = Aname;
        }

        public void setPolygonName(string name)
        {
            Polygonname = name;
        }

        public Pointk getPointAtIndex(int index)
        {
            return (Pointk)Points[index];
        }

    }







之后工作正常创建为dll然后使用另一个窗口应用程序按钮单击事件






it is work fine after creating as a dll and then using another window application button click event

PointinPolygon1 obj = new PointinPolygon1();
            bool x = obj.getpolygonvalues(50, 50, -97.08215655572718, 32.90984427311083);
            label1.Text = x.ToString();





i当我到达断点时以断点运行/>



i am run with break point when i reach the break point

bool x = obj.getpolygonvalues(50, 50, -97.08215655572718, 32.90984427311083);



i我收到错误


i am getting error

Input string was not in a correct format.



请告诉我原因



我尝试过的事情:



i我不能传递参数


please tell me the reason

What I have tried:

i am not able to pass the argument

推荐答案

在解决方案中包含DLL项目,并删除对编译版本的引用。然后将DLL项目的引用添加到您的Windows应用程序项目而不是DLL文件。

现在,当您运行程序时,它将停止在DLL中,让您查看确切的行和涉及到什么数据。



但请相信我,你永远不应该在你的应用程序或DLL中硬编码文件路径 - 如果数据是固定的(即你从不写入它,它永远不会改变)然后将它保存在应用程序(或带有EXE / DLL文件的DLL文件夹中,并通过 Environment.SpecialFolder枚举 [ ^ ]使用 Environment.GetFolderPath方法(Environment.SpecialFolder)(系统) [ ^ ]。

如果确实发生变化,请将其保存在安全位置:我应该在哪里存储我的数据? [ ^ ]应该有帮助。

绝对不要将它存储在任何设备的根文件夹中 - 出于安全考虑,这些通常是受限制的,它可以使你的如果你不是非常小心,app会无法预测地失败。
Include the DLL Project in your Solution, and remove the reference to the compiled version. Then add a reference to the DLL project to your windows App project instead of to the DLL file.
Now when you run your program, it will stop in the DLL and let you look at exactly what line and what data is involved.

But trust me, you should never hard-code file paths in your app or DLL - if the data is fixed (i.e. you never write to it, it never changes) then keep it in the application (or DLL folder with the EXE / DLL file, and refer to it via Environment.SpecialFolder enum[^] using the Environment.GetFolderPath Method (Environment.SpecialFolder) (System)[^].
If it does change, then keep it in a "safe" place: Where should I store my data?[^] should help.
And definitely, never store it in the root folder of any device - these are generally restricted for security reasons, and it can make your app fail unpredictably if you aren't extremely careful.


这篇关于当我在项目中使用DLL时,不会采用文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆