PDA

View Full Version : پیدا کردن درایو و پوشه ویندوز



mohammad diba
پنج شنبه 24 آبان 1386, 12:23 عصر
سلام بر دوستان
می خواستم بدونم چه جوری در سی شارپ می تونم محل پوشه ویندوز رو پیدا کنم
توی وی بی از API استفاده می کردیم توی سی شارپ نیز می شه از API استفاده کرد.
ممنون

manitack
پنج شنبه 24 آبان 1386, 13:42 عصر
MessageBox.Show("CurrentDirectory " + Environment.CurrentDirectory);
MessageBox.Show("GetFolderPath System:" + Environment.GetFolderPath(Environment.SpecialFolde r.System).ToString());

mohammad272005
جمعه 25 آبان 1386, 00:55 صبح
1-
Environment.ExpandEnvironmentVariables("%windi%")
2- بله میشه. قدم اول استفاده از DllImport هست.

mohammad diba
دوشنبه 28 آبان 1386, 07:35 صبح
می شه یه مثال از Dllimport ضمیمه کنید ممنون

hassan razavi
دوشنبه 28 آبان 1386, 09:48 صبح
این کد رو از سایت زیر براتون گرفتم


// http://www.c-sharpcenter.com/Tutorial/UnManaged.htm
using System.Runtime.InteropServices;
using System;
class call_dll {
[StructLayout(LayoutKind.Sequential, Pack=1)]
private struct STRUCT_DLL {
public Int32 count_int;
public IntPtr ints;
}

[DllImport("mingw_dll.dll")]
private static extern int func_dll(
int an_int,
[MarshalAs(UnmanagedType.LPArray)] byte[] string_filled_in_dll,
ref STRUCT_DLL s
);

public static void Main() {
byte[] string_filled_in_dll = new byte[21];
STRUCT_DLL struct_dll = new STRUCT_DLL();
struct_dll.count_int = 5;
int[] ia = new int[5];
ia[0] = 2; ia[1] = 3; ia[2] = 5; ia[3] = 8; ia[4] = 13;

GCHandle gch = GCHandle.Alloc(ia);
struct_dll.ints = Marshal.UnsafeAddrOfPinnedArrayElement(ia, 0);

int ret=func_dll(5,string_filled_in_dll, ref struct_dll);

Console.WriteLine("Return Value: " + ret);
Console.WriteLine("String filled in DLL: " + System.Text.Encoding.ASCII.GetString(string_filled _in_dll));
}
}