API in .NET

Madz

Well-known member
Joined
Jan 22, 2003
Messages
155
I want to use WIN32API Funcitons such as "LockWorkStation" and other in Visual Basic.NET but i dont know how to use them
When ever i try to add them in VB.net it cause a Run Time Error.
Is there any way to use this
 
Yes, youll need the VB6 version of the declare for the API, and then convert Longs to Integers or IntPtrs.

LockWorkStation should present no difficulty in converting. There are items in the help that cover this, and several examples of calling APIs in the framework SDK.
 
Thank You, Problem Solved

Thank Dear,

I have tried and succefully Locked My WorkStation

Code:
Public Class Form1
    Inherits System.Windows.Forms.Form

    Private Declare Function LockWorkStation Lib "user32.dll" () As IntPtr
    
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LockWorkStation()
    End Sub
End Class
 
For the record, you probably want the return type to be Integer, not IntPtr. divil was suggesting that some "As Long" params from the VB6 API declarations may need to be converted to IntPtr. It depends on what the API needs.

For the vast majority of APIs, the return type will be Integer as most DLLs are C-style which return a success/error through the function return value. For that, you simply want an Integer so you can compare the value to 0 to check for success.

It wont hurt to use IntPtr as the return (that I know of), but you might want to change it so it doesnt look confusing in the future.

-nerseus
 
Back
Top