C to VB .NET

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nikolay Petrov

    C to VB .NET

    Can anyone convert some C code to VB .NET for me?
    Thanks in advance!!


    #define LOGONID_CURRENT ((ULONG)-1)
    #define SERVERNAME_CURR ENT ((HANDLE)NULL)


    typedef enum _WINSTATIONINFO CLASS {
    WinStationInfor mation = 8



    } WINSTATIONINFOC LASS;


    typedef struct _WINSTATIONINFO RMATIONW {
    BYTE Reserved1[72];
    ULONG SessionId;
    BYTE Reserved2[4];
    FILETIME ConnectTime;
    FILETIME DisconnectTime;
    FILETIME LastInputTime;
    FILETIME LoginTime;
    BYTE Reserved3[1096];
    FILETIME CurrentTime;


    } WINSTATIONINFOR MATIONW, * PWINSTATIONINFO RMATIONW;


    typedef BOOLEAN (WINAPI * PWINSTATIONQUER YINFORMATIONW)(
    HANDLE, ULONG, WINSTATIONINFOC LASS, PVOID, ULONG, PULONG );

    BOOL Result;
    HANDLE hServer = NULL;
    HANDLE hWinSta = NULL;
    ULONG SessId;
    ULONG BufLen;
    ULONG RetLen;
    WINSTATIONINFOR MATION Buf;
    PWINSTATIONQUER YINFORMATIONW WinStationQuery InformationW = NULL;


    hWinSta = LoadLibrary("WI NSTA.DLL");


    WinStatonQueryI nformationW =
    GetProcAddress( hWinSta,"WinSta tionQueryInform atoinW");


    BufLen = sizeof(Buf);


    // Assume that hServer is a valid server handle previously obtained
    from
    // WTSOpenServer() .
    //
    // Assume that SessId has been set to the desired session id value.
    The
    // term "logon id" is synonymous with "session id".


    Result =
    WinStationQuery InformationW(hS erver,SessId,Wi nStationInforma tion,&Buf,BufLe ­n,&RetLen);



    if (Result)
    {
    // Use the SYSTEMTIME structure and the FileTimeToSyste mTime()
    function
    // to convert from FILETIME to SYSTEMTIME format. Remember, these
    time
    // values are GMT values; they don't have the local time zone
    offset
    // applied to them.


    }


    {
    // handle the error


    }

  • Mattias Sjögren

    #2
    RE: C to VB .NET

    > typedef enum _WINSTATIONINFO CLASS {[color=blue]
    > WinStationInfor mation = 8
    > } WINSTATIONINFOC LASS;[/color]

    Enum WINSTATIONINFOC LASS
    WinStationInfor mation = 8
    End Enum
    [color=blue]
    > typedef struct _WINSTATIONINFO RMATIONW {
    > BYTE Reserved1[72];
    > ULONG SessionId;
    > BYTE Reserved2[4];
    > FILETIME ConnectTime;
    > FILETIME DisconnectTime;
    > FILETIME LastInputTime;
    > FILETIME LoginTime;
    > BYTE Reserved3[1096];
    > FILETIME CurrentTime;
    > } WINSTATIONINFOR MATIONW, * PWINSTATIONINFO RMATIONW;[/color]

    That doesn't look anything like what I have in my header file, which is


    typedef struct _WINSTATIONINFO RMATIONW {
    BYTE Reserved2[70];
    ULONG LogonId;
    BYTE Reserved3[1140];
    } WINSTATIONINFOR MATIONW, * PWINSTATIONINFO RMATIONW;

    That translates to

    Structure WINSTATIONINFOR MATIONW
    <MarshalAs(Unma nagedType.ByVal Array, SizeConst=70)> _
    Public Reserved2() As Byte
    Public LogonId As Integer
    <MarshalAs(Unma nagedType.ByVal Array, SizeConst=1140) > _
    Public Reserved3() As byte
    End Strucure

    And finally the Declare

    Declare Unicode Function WinStationQuery InformationW(hS erver As IntPtr,
    LogonId As Integer, WinStationInfor mationClass As WINSTATIONINFOC LASS, ByRef
    pWinStationInfo rmation As WINSTATIONINFOR MATIONW, WinStationInfor mationLength
    As Integer, ByRef pReturnLength As Integer) As <MarshalAs(Unma nagedType.I1)>
    Boolean


    Mattias

    Comment

    • Nikolay Petrov

      #3
      Re: C to VB .NET

      thanks Mattias
      it is an undocumented function, a guess the structure too.

      thanks

      Comment

      • Mattias Sjögren

        #4
        Re: C to VB .NET

        >it is an undocumented function, a guess the structure too.

        Not completely undocumented, but only documented for one specific
        purpose (and I don't see why you'd use it rather than calling
        GetSystemMetric s(SM_REMOTESESS ION)).

        Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.



        Mattias

        --
        Mattias Sjögren [MVP] mattias @ mvps.org
        http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
        Please reply only to the newsgroup.

        Comment

        • Nikolay Petrov

          #5
          Re: C to VB .NET

          I am searching the idle times of Terminal Server sessions. And the only
          code i found was this:


          I am having troubles converting struct _WINSTATIONINFO RMATIONW. You
          have converted it in VB, but it's different from the source. I really
          need those 'FILETIME' type variebles, that you have let through. What
          is the corespondent .NET type for them? I guess 'Date', but I'm not
          quite sure.

          Comment

          • Nikolay Petrov

            #6
            Re: C to VB .NET

            Mattias, when you marshal struct _WINSTATIONINFO RMATIONW, you put
            parameter to SizeConst, different from ones in the C example, why? Any
            special reason?
            [color=blue]
            > typedef struct _WINSTATIONINFO RMATIONW {
            > BYTE Reserved1[72];
            > ULONG SessionId;
            > BYTE Reserved2[4];
            > FILETIME ConnectTime;
            > FILETIME DisconnectTime;
            > FILETIME LastInputTime;
            > FILETIME LoginTime;
            > BYTE Reserved3[1096];
            > FILETIME CurrentTime;
            > } WINSTATIONINFOR MATIONW, * PWINSTATIONINFO RMATIONW;[/color]



            Structure WINSTATIONINFOR MATIONW
            <MarshalAs(Unma nagedType.ByVal Array, SizeConst=70)> _
            Public Reserved2() As Byte
            Public LogonId As Integer
            <MarshalAs(Unma nagedType.ByVal Array, SizeConst=1140) > _
            Public Reserved3() As byte
            End Strucure

            Comment

            • Mattias Sjögren

              #7
              Re: C to VB .NET

              [color=blue]
              >What is the corespondent .NET type for them?[/color]

              FILETIME is available in the System.Runtime. InteropServices namespace.

              [color=blue]
              >Mattias, when you marshal struct _WINSTATIONINFO RMATIONW, you put
              >parameter to SizeConst, different from ones in the C example, why?[/color]

              I translated the definition the way it is in the Platform SDK header
              file.


              Mattias

              --
              Mattias Sjögren [MVP] mattias @ mvps.org
              http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
              Please reply only to the newsgroup.

              Comment

              • Nikolay Petrov

                #8
                Re: C to VB .NET

                Ok, thanks Mattias

                Comment

                Working...