SHChangeNotify in VB 2005 Express

JumpyNET

Well-known member
Joined
Apr 4, 2005
Messages
151
My old VB6 code for changing icons does not seem to work with out modifications. Now Im stuck with the SHChangeNotify. Does any one know how to get this API work in VB 2005 Express?


Code:
Declarations
Private Declare Function SHChangeNotify Lib "Shell32.dll" (ByVal wEventID As Long, ByVal uFlags As Long, ByVal dwItem1 As Long, ByVal dwItem2 As Long) As Long
Private Declare Sub SHChangeNotify Lib "shell32.dll" (ByVal wEventId As Long, ByVal uFlags As Long, ByVal dwItem1 As Object, ByVal dwItem2 As Object)
Const SHCNE_ASSOCCHANGED = &H8000000
Const SHCNF_IDLIST = &H0


In a sub
Notify shell icon has changed
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, vbNullString, vbNullString)

Oh and heres the error Im getting:
A call to PInvoke function JaMP!JaMP.FormAssociations::SHChangeNotify has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.
 
Last edited by a moderator:
Longs, Integers, and IntPtrs

You should be using the Sub version rather than the Function version of SHChangeNotify since the function does not return a value. However, the parameters you are using are incorrect. Long in VB6 is Integer in VB.Net:

Code:
Declarations
Private Declare Sub SHChangeNotify Lib "shell32.dll" ( _
    ByVal wEventId As Integer, _
    ByVal uFlags As Integer, _
    ByVal dwItem1 As IntPtr, _
    ByVal dwItem2 As IntPtr _
)
Const SHCNE_ASSOCCHANGED = &H8000000
Const SHCNF_IDLIST = &H0


In a sub
Notify shell icon has changed
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, IntPtr.Zero, IntPtr.Zero)

Good luck :cool:
 
Just so you know, VB6 longs can translate not only into Integer, but also IntPtr and possibly a couple other uncommon types.

You might want to download API Viewer. It doesnt make use of the IntPtr type, which is the correct type for hWnds and other handle types, but for the most part it is very handy.
 
Back
Top