VB.netでのCopyMemoryを利用するには


マー坊  2005-06-02 05:52:46  No: 122144

下記のようなコードがあります。
これはターミナルサービスに現在のセッション情報を取得し
デバック情報として表示するものです。
(microsoft社のサンプルより)

Private Type WTS_SESSION_INFO
    SessionID As Long
    pWinStationName As Long
    state As WTS_CONNECTSTATE_CLASS
End Type

Private Declare Function WTSEnumerateSessions _
    Lib "wtsapi32.dll" Alias "WTSEnumerateSessionsA" ( _
    ByVal hServer As Long, ByVal Reserved As Long, _
    ByVal Version As Long, ByRef ppSessionInfo As Long, _
    ByRef pCount As Long _
    ) As Long

Private Declare Sub WTSFreeMemory Lib "wtsapi32.dll" ( _
    ByVal pMemory As Long)

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
    Destination As Any, Source As Any, ByVal length As Long)

Private Function GetWTSSessions() As WTS_SESSION_INFO()
    Dim RetVal As Long
    Dim lpBuffer As Long
    Dim Count As Long
    Dim p As Long
    Dim arrSessionInfo() As WTS_SESSION_INFO
  Dim i As Integer

    RetVal = WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE, _
                                   0&, _
                                   1, _
                                   lpBuffer, _
                                   Count)
    If RetVal Then
        ' WTSEnumerateProcesses was successful.

        p = lpBuffer
        ReDim arrSessionInfo(Count - 1)

    問題箇所
        CopyMemory arrSessionInfo(0), ByVal p,Count * LenB(arrSessionInfo(0))
   

   For i = LBound(arrWTSSessions) To UBound(arrWTSSessions)

        Debug.Print "Session ID: " & arrWTSSessions(i).SessionID
        Debug.Print "Machine Name: " & _
           PointerToStringA(arrWTSSessions(i).pWinStationName)
        Debug.Print "Connect State: " & arrWTSSessions(i).state
        Debug.Print "***********"

    Next i

しかしこれはVB6用のもののためVB.netにコンバートしようとしたのですがうまくいきません。

問題点
  1.問題となっているのはWTSEnumerateSessionsの4番目の引数(lpBuffer)を
  WTS_SESSION_INFO型の構造体にコピーしているCopyMemory(API)がVB.netでは
  うまくいきません。

  ご存知の方どうかお力添えをおねがいします。


特攻隊長まるるう  2005-06-06 18:24:34  No: 122145

http://www.microsoft.com/japan/msdn/net/vbtransitionguide/
コンバートされてませんので何が変わったのか?基本的なことは
自分で調べて下さい。
そのあと、過去ログ検索『CopyMemory』でどうぞ。


※返信する前に利用規約をご確認ください。

※Google reCAPTCHA認証からCloudflare Turnstile認証へ変更しました。






  このエントリーをはてなブックマークに追加