Madz Posted January 22, 2003 Posted January 22, 2003 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 Quote The one and only Dr. Madz eee-m@il
*Gurus* divil Posted January 22, 2003 *Gurus* Posted January 22, 2003 Yes, you'll 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. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Madz Posted January 22, 2003 Author Posted January 22, 2003 Thank You, Problem Solved Thank Dear, I have tried and succefully Locked My WorkStation 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 Quote The one and only Dr. Madz eee-m@il
*Experts* Nerseus Posted January 22, 2003 *Experts* Posted January 22, 2003 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 won't hurt to use IntPtr as the return (that I know of), but you might want to change it so it doesn't look confusing in the future. -nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Recommended Posts