How can translate this in vb.net?

A

Antonio C

BOOL SipGetInfo(SIPINFO* pSipInfo);

typedef struct{
DWORD cbSize;
DWORD fdwFlags;
RECT rcVisibleDesktop;
RECT rcSipRect;
DWORD dwImDataSize;
VOID* pvImData;
} SIPINFO;

I've tried int this way but don't work:

<System.Runtime.InteropServices.DllImport("coredll.dll")>
Private Shared Function SipGetInfo(ByVal si As SIPINFO) As
Boolean
End Function

Private Structure SIPINFO
Public cbSize As Int32
Public fdwFlags As Int32
Public rcVisibleDesktop As RECT
Public rcSipRect As RECT
Public dwImDataSize As Int32
Public pvImData As Int32
End Structure

Private Structure RECT
Public left As Int32
Public top As Int32
Public right As Int32
Public Bottom As Int32
End Structure

Can anyone help me?
 
A

Alex Feinman [MVP]

It should work if you change the function definition to use SIPINFO byRef or
make it a class instead of a structure
 
A

Antonio C

Thank you Alex,
using byref now it doesn't give me error but the
structure after the execution of the function remain
empty, the full code is this:
==================================================
Public Class Sip
<System.Runtime.InteropServices.DllImport
("coredll.dll")> Private Shared Function SipShowIM(ByVal i
As SIPStatus) As Integer
End Function
<System.Runtime.InteropServices.DllImport
("coredll.dll")> Private Shared Function SipSetInfo(ByRef
si As SIPINFO) As Boolean
End Function
<System.Runtime.InteropServices.DllImport
("coredll.dll")> Private Shared Function SipGetInfo(ByRef
si As SIPINFO) As Boolean
End Function

Private Enum SIPStatus
SIPF_OFF = 0
SIPF_ON
End Enum
Private Structure SIPINFO
Public cbSize As Int32
Public fdwFlags As Int32
Public rcVisibleDesktop As RECT
Public rcSipRect As RECT
Public dwImDataSize As Int32
Public pvImData As Int32
End Structure

Private Structure RECT
Public left As Int32
Public top As Int32
Public right As Int32
Public bottom As Int32
End Structure


' Mostrar el SIP
Public Shared Sub Show()
SipShowIM(SIPStatus.SIPF_ON)
End Sub

' Ocultar el SIP
Public Shared Sub Hide()
SipShowIM(SIPStatus.SIPF_OFF)
End Sub

Public Shared Sub SetPosition(ByVal x as int32,ByVal y
as int32)
Dim mySi As New SIPINFO
SipGetInfo(mySi)
mySi.rcSipRect.left = 0
mySi.rcSipRect.top = 60
SipSetInfo(mySi)
End Sub

End Class
==================================================
I want to set the position of SIP through the SipGetInfo
(to get the current position) and SipSetInfo (to set the
new position) but, how I've told above the structure
SIPINFO remain empty after the SipGetInfo and if i set
manually the SIPINFO structure the SIP doesn't change
position.

Thank you all for attention.
Antonio.
 
A

Alex Feinman [MVP]

Perhaps you are forgetting to set cbSize to Marshal.SizeOf(GetType(SIPINFO))
 
A

Antonio C

I'm a noob in these kind of programming but you are GREAT
Alex!!!
Now all work very fine
So, because I've started to work on this class from a code
posted in this ng, I want to share with you this.
A SIP with a method to set the position.

Public Class Sip
<System.Runtime.InteropServices.DllImport
("coredll.dll")> Private Shared Function SipShowIM(ByVal i
As SIPStatus) As Integer
End Function
<System.Runtime.InteropServices.DllImport
("coredll.dll")> Private Shared Function SipSetInfo(ByRef
pSipInfo As SIPINFO) As Boolean
End Function
<System.Runtime.InteropServices.DllImport
("coredll.dll")> Private Shared Function SipGetInfo(ByRef
pSipInfo As SIPINFO) As Boolean
End Function

Private pvtVisible As Boolean = False
Private Enum SIPStatus
SIPF_OFF = 0
SIPF_ON
End Enum
Private Structure SIPINFO
Public cbSize As Int32
Public fdwFlags As Int32
Public rcVisibleDesktop As RECT
Public rcSipRect As RECT
Public dwImDataSize As Int32
Public pvImData As Int32
End Structure

Private Structure RECT
Public left As Int32
Public top As Int32
Public right As Int32
Public bottom As Int32
End Structure


' Mostrar el SIP
Public Shared Sub Show()
SipShowIM(SIPStatus.SIPF_ON)
End Sub

' Ocultar el SIP
Private Shared Sub Hide()
SipShowIM(SIPStatus.SIPF_OFF)
End Sub

Public Sub SetPosition(ByVal top As Int32)
Dim mySi As SIPINFO
Dim result As Boolean = True
mySi.cbSize =
System.Runtime.InteropServices.Marshal.SizeOf(GetType
(SIPINFO))
result = SipGetInfo(mySi)
mySi.rcSipRect.top = top
mySi.rcSipRect.bottom = top + 80
result = SipSetInfo(mySi)
End Sub

Public Property Visible() As Boolean
Get
Return pvtVisible
End Get
Set(ByVal Value As Boolean)
If Value = True Then
SipShowIM(SIPStatus.SIPF_ON)
Else
SipShowIM(SIPStatus.SIPF_OFF)
End If
pvtVisible = Value
End Set
End Property
End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top