Tech Off Thread

3 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Generating p/invoke declarations?

Back to Forum: Tech Off
  • User profile image

    I'm looking for the smart card api in Windows and found the functions to be in winscard.dll. How do I generate the neccesary code in so I can use those functions? I looked it up at but they only have the c# version.

    Is there not an automated way of creating these functions?

  • User profile image
    Sven Groot

    Not directly from the original C declaration, no. But if you have the C# version, getting the VB version is trivial. I think there are even some automated C# to VB converters, you could look for those.

  • User profile image

    The Foundations of .NET Cert Study Guide (70-536) goes over this in Chapter 13:

    Referencing unmanaged code from in a class:

    Public Class WindowExample

        Private Const BufferSize As Int32 = 256

        <DllImport("user32.dll")> _
        Private Shared Function GetForegroundWindow() As IntPtr
        End Function

        <DllImport("user32.dll")> _
        Private Shared Function GetWindowText(ByVal hWnd As IntPtr, _
            ByVal textValue As StringBuilder, ByVal counter As Int32) As Int32
        End Function

        Public Shared Sub GetScreenDemo()
            Dim DemoBuilder As New StringBuilder(BufferSize)
            Dim DemoHandle = GetForegroundWindow()

            If GetWindowText(DemoHandle, DemoBuilder, BufferSize) > 0 Then
            End If
        End Sub
    End Class

    The GetScreenDemo calls unmanaged code function GetWindowText(IntPtr, StringBuilder, Int32)

    I highley recommend this test and the book behind it. It is a must read for anyone who is new to .NET 2.0.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.