Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

The one and only

Dr. Madz

eee-m@il

  • *Gurus*
Posted

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.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

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

The one and only

Dr. Madz

eee-m@il

  • *Experts*
Posted

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

"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
Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...