首页 新闻 会员 周边

C#如何设置工作路径?

0
悬赏园豆:50 [已解决问题] 解决于 2016-02-26 12:01

我的问题是这样的:

1、我引用了一个DLL,DLL中有一个应用程序,需要调用大量数据,如果该DLL与现有的调用程序同在一个路径下,且需调用的数据也在同一路径下时,可以工作,没有问题。但现有的调用程序在工作中需要生成新的工作目录,将数据分配到新的工作目录下,这样的情况下,调用的DLL就无法工作了。

2、请问如何给DLL设置一个工作路径,前提是DLL没有提供如何接口,接受新路径的参数。

以下是我的程序代码:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Drawing;
 4 using System.Runtime.InteropServices;
 5 using System.Windows.Forms;
 6 using System.Threading;
 7 
 8 namespace TestDLL
 9 {
10     
13 public partial class MainForm : Form 14 { 15 16 17 public MainForm() 18 { 19 // 20 // The InitializeComponent() call is required for Windows Forms designer support. 21 // 22 InitializeComponent(); 23 24 // 25 // TODO: Add constructor code after the InitializeComponent() call. 26 // 27 } 28 29 30 void Button2_Click(object sender, EventArgs e) 31 { 32 NewGIS ANewGIS=new NewGIS(); 33 this.textBox1.Text ="模拟开始..."; 34 this.Refresh(); 35 Thread NewGISThead=new Thread(NewGIS.RUN ); 36 NewGISThead.Start(); 37 this.button2.Enabled=false; 38 } 39 40 void Button3Click(object sender, EventArgs e) 41 { 42 float a=8; 43 float b=9; 44 float c=NewGIS.GetWillUsedTime(a,b); 45 if(c>0) 46 { 47 this.button2.Enabled=false; 48 } 49 else 50 { 51 this.button2.Enabled=true; 52 } 53 this.textBox1.Text =c.ToString(); 54 } 55 56 57 void Button1_Click(object sender, EventArgs e) 58 { 59 int a=98; 60 int b=100; 61 b=NewGIS.GetInfor(a); 62 this.textBox1.Text=b.ToString(); 63 } 64 } 65 public class NewGIS 66 { private static float GISEND; 67 [DllImport("G:\\TestDll\\bin\\DLL\\GISDLL.dll",CallingConvention = CallingConvention.Cdecl)] 68 public static extern float RunGIS(float a, float b); 69 [DllImport("G:\\TestDll\\bin\\DLL\\GISDLL.dll",CallingConvention = CallingConvention.Cdecl)] 70 public static extern float GetWillUsedTime(float a, float b); 71 72 73 public static void RUN() 74 { 75 GISEND=0; 76 float a=50; 77 float b=50; 78 GISEND=NewGIS.RunGIS(a,b); 79 } 80 81 82 } 83 }
向北方的主页 向北方 | 初学一级 | 园豆:154
提问于:2016-02-26 09:50
< >
分享
最佳答案
0

Directory.SetCurrentDirectory(string path)

收获园豆:50
德年 | 小虾三级 |园豆:810 | 2016-02-26 10:31

这个语句是否可以出现在程序的如何部位?

向北方 | 园豆:154 (初学一级) | 2016-02-26 12:06

这个语句是否可以出现在程序的任何部位?

向北方 | 园豆:154 (初学一级) | 2016-02-26 12:07

谢谢,非常感谢。

向北方 | 园豆:154 (初学一级) | 2016-02-26 12:07
其他回答(1)
0

其实还有更简单的方法 就是通过App.config 文件配置 制定的路径即可,不懂的自己研究。

傲雪江南 | 园豆:174 (初学一级) | 2016-02-26 16:28
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册