PDA

View Full Version : کمک در استفاده از API



mirage041
یک شنبه 23 فروردین 1388, 12:15 عصر
سلام منیک سری از توابع API رو گیر آوردم از این صفحه :
http://barnamenevis.org/forum/showthread.php?t=121103
ولی روش استفادشون نمی دونم.
می شه آموزش استفاده از توابع بالا رو در سی شارپ دات نت یاد بدین.
ممنون

NewFoxStudent
یک شنبه 23 فروردین 1388, 15:17 عصر
اگه متوجه نشدی بگید تا توضیح بدم

#region Dll Imports
//declare the Netapi32 : NetServerEnum method import
[DllImport("Netapi32", CharSet = CharSet.Auto,
SetLastError = true),
SuppressUnmanagedCodeSecurityAttribute]
///<summary>
/// Netapi32.dll : The NetServerEnum function lists all servers
/// of the specified type that are
/// visible in a domain. For example, an
/// application can call NetServerEnum
/// to list all domain controllers only
/// or all SQL servers only.
/// You can combine bit masks to list
/// several types. For example, a value
/// of 0x00000003 combines the bit
/// masks for SV_TYPE_WORKSTATION
/// (0x00000001) and SV_TYPE_SERVER (0x00000002)
///</summary>
public static extern int NetServerEnum(
string ServerNane, // must be null
int dwLevel,
ref IntPtr pBuf,
int dwPrefMaxLen,
out int dwEntriesRead,
out int dwTotalEntries,
int dwServerType,
string domain, // null for login domain
out int dwResumeHandle
);
//declare the Netapi32 : NetApiBufferFree method import
[DllImport("Netapi32", SetLastError = true),
SuppressUnmanagedCodeSecurityAttribute]
///<summary>
/// Netapi32.dll : The NetApiBufferFree function frees
/// the memory that the NetApiBufferAllocate function allocates.
/// Call NetApiBufferFree to free
/// the memory that other network
/// management functions return.
///</summary>
public static extern int NetApiBufferFree(
IntPtr pBuf);
//create a _SERVER_INFO_100 STRUCTURE
[StructLayout(LayoutKind.Sequential)]
public struct _SERVER_INFO_100
{
internal int sv100_platform_id;
[MarshalAs(UnmanagedType.LPWStr)]
internal string sv100_name;
}

mirage041
سه شنبه 25 فروردین 1388, 16:12 عصر
نه متاسفانه
اگه بتونی توضیح بدی عالی میشه.
اون پستی که من بالا زدم خیلی عالی بود دسته بندی کرده بود قشنگ اوکی میگفت.
اگه اون طوری باشه عالیه.

NewFoxStudent
سه شنبه 25 فروردین 1388, 16:21 عصر
در کدهای بالا چندین تابع API تعریف شده



//declare the Netapi32 : NetServerEnum method import
[DllImport("Netapi32", CharSet = CharSet.Auto,
SetLastError = true),
SuppressUnmanagedCodeSecurityAttribute]

این دستور برای معرفی فایل مربوط به تابع و خصوصیاتش هست




public static extern int NetServerEnum(
string ServerNane, // must be null
int dwLevel,
ref IntPtr pBuf,
int dwPrefMaxLen,
out int dwEntriesRead,
out int dwTotalEntries,
int dwServerType,
string domain, // null for login domain
out int dwResumeHandle
);


این قسمت هم خود تابع رو تعریف میکنه

mirage041
پنج شنبه 27 فروردین 1388, 08:41 صبح
خوب تا اینجا که حله؟
فقط الان من اگه اون توابع (http://barnamenevis.org/forum/showthread.php?t=121103 (http://barnamenevis.org/forum/showthread.php?t=121103)) کجا باید بریزم و باهاشون کار کنم؟

NewFoxStudent
پنج شنبه 27 فروردین 1388, 08:53 صبح
شما هرجایی میتونید این توابع رو تعریف کنید و ازشون استفاده کنید

mirage041
پنج شنبه 27 فروردین 1388, 19:38 عصر
منظورم کجای قطعه کد بالاست
یک مقاله جامع می تونی در این ارتباط بنویسی و و سایت قرار بدی