You are here: آموزش توابع API ویندوز گروه Environment Variables

گروه Environment Variables

آموزش توابع API   ویندوز           گروه: Environment Variables

منبع: انجمن تخصصی برنامه نویسان ایران  

 

GetEnvironmentVariable,




نام تابع: GetEnvironmentVariable

اعلان: Declare Function GetEnvironmentVariable Lib "kernel32.dll" Alias "GetEnvironmentVariableA" (ByVal lpName As String, ByVal lpBuffer As String, ByVal nSize As Long) As Long

سيستم عامل: 2000 , NT , 98 , 95

توضيحات: اطلاعات مربوط به انوايرمنت (Environment) ميدهد مانند محل فايلهاي موقتي سيستم(Temp) و … . اين مقدار درون يك بافر از نوع استرينگ به نام lpBuffer قرار داده ميشود.

مقدار بازگشتي: اگر متغيري كه پاس داده شده براي پيدا كردن انوايرمنت آن پيدا نكند مقدار صفر برميگرداند و اگر مقدار پارامتر ارسالي به lpBuffer خيلي كوچك باشد مقدار برگشتي طول حداقل بافر ميباشد و اگر تابع موفق باشد طول مقدار برگشتي lpBuffer را برميگرداند.(كه با كاراكتر Null در آخر آن مشخص شده است)

پارامترها: lpName نام متغير انوايرمنت lpBuffer مقدار برگشتي انوايرمنت . اين متغير بايد به اندازه كافي بزرگ باشد تا بتواند اطلاعات را درخود جاي دهد . nSize اندازه پارامتر lpBuffer

ثابتهاي مورد استفاده: ---

کتابخانه: Kernel32

توابع مرتبط: SetEnvironmentVariable

نکات: ---

کد نمونه:

Read the BLASTER environment variable, which contains some information about the Sound Blaster configuration on the computer. Typically, this variable is only used by DOS programs, so it isn't very useful for Windows applications. But then again, this is just an example of how to use GetEnvironmentVariable. The example runs when button Command1 is clicked, so you must place a command button named Command1 on a form window before running this example. ' Declarations and such needed for the example: ' (Copy them to the (declarations) section of a module.) Public Declare Function GetEnvironmentVariable Lib "kernel32.dll" Alias "GetEnvironmentVariableA" (ByVal _ lpName As String, ByVal lpBuffer As String, ByVal nSize As Long) As Long ' *** Place the following code inside a form window. *** Private Sub Command1_Click() Dim envvar As String ' receives the value of the environment variable Dim slength As Long ' length of the string copied into envvar ' Make enough room in envvar to receive the data. envvar = Space(256) ' Read the value of the BLASTER environment variable. slength = GetEnvironmentVariable("BLASTER", envvar, Len(envvar)) If slength = 0 Then Debug.Print "The BLASTER environment variable does not exist on this system." Else ' Remove the terminating null and everything following it. envvar = Left(envvar, slength) Debug.Print "BLASTER = "; envvar End If End Sub