اذهب الي المحتوي
أوفيسنا

اجعل برنامجك يعمل على النواتين 32بت و 64بت


jjafferr

الردود الموصى بها

تم التوصل الى الخلل 

في هذه الدالة apiGetUserName

 

 

بالذات هذا السطر 

nSize As Long

لازم يكون 

nSize As LongPtr

 

طلبي الان هو التعديل في الكود بخيث يعمل على النواتين

Option Compare Database
Option Explicit
#If VBA7 Then
Private Declare PtrSafe Function apiGetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As LongPtr) As Long

#Else
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    #End If

Function fOSUserName() As String
' Returns the network login name




Dim lngLen As Long, lngx As Long

Dim strUserName As String
    strUserName = String$(254, 0)
    lngLen = 255
    lngx = apiGetUserName(strUserName, lngLen)
    If (lngx > 0) Then
        fOSUserName = Left$(strUserName, lngLen - 1)
    Else
        fOSUserName = vbNullString
    End If
End Function

بالذات في هذه الدالة

 

Function fOSUserName() As String
' Returns the network login name




Dim lngLen As Long, lngx As Long

Dim strUserName As String
    strUserName = String$(254, 0)
    lngLen = 255
    lngx = apiGetUserName(strUserName, lngLen)
    If (lngx > 0) Then
        fOSUserName = Left$(strUserName, lngLen - 1)
    Else
        fOSUserName = vbNullString
    End If
End Function

 

لانها ظهرت اخطاء في هذه الاسطر 

 

 lngx = apiGetUserName(strUserName, lngLen)


   

وهذا السطر


       

 fOSUserName = Left$(strUserName, lngLen - 1)

 

 

 

رابط هذا التعليق
شارك

جرب هذا

احذف هذه الاسطر
#If VBA7 Then
Private Declare PtrSafe Function apiGetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As LongPtr) As Long

#Else
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    #End If


واستبدلها بهذا
Private Declare PtrSafe Function apiGetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

 

فيه تعديل في السطر الاخير ، فلا تستعمل السطر اللي عندك ، وانما اعمل نسخ للسطر الذي كتبته لك اعلاه 🙂

 

جعفر

رابط هذا التعليق
شارك

هل تقصد ان الدالة بوضعها التالي 

Private Declare PtrSafe Function apiGetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

ستعمل على النواتين

 

رابط هذا التعليق
شارك

في ٤‏/٥‏/٢٠٢٢ at 20:52, عبدالله المجرب said:

هل تقصد ان الدالة بوضعها التالي 

Private Declare PtrSafe Function apiGetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

ستعمل على النواتين

 

جربت هذا الحل والى الان الامور تمام 

سلمت استاذ جعفر 

شكرا لك وكل عام والجميع بخير

رابط هذا التعليق
شارك

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

زائر
اضف رد علي هذا الموضوع....

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • اضف...

Important Information