Upgrading Control from VB6 to .NET

mikesena

New member
Joined
Feb 17, 2006
Messages
1
Programming Experience
3-5
Hi,

I've searched Google on this but couldn't find an easy way to fix it. I'm getting the famous error on my control, which I have upgraded from VB6:

'AddressOf' expression cannot be converted to 'Integer' because 'Integer' is not a delegate type.

The function it is referring to is:
VB.NET:
Expand Collapse Copy
m_OrgCtrlProc = SetWindowLongPtr(Handle.ToInt32, GWLP_WNDPROC, AddressOf MainCtrlProc)

MainCtrlProc is:
VB.NET:
Expand Collapse Copy
Public Function MainCtrlProc(ByVal hwnd As Integer, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
        'This function is called when messages for the control arrive
        
        'hWnd is the handle to the HookControl the message is meant for
        'get pointer to correct instance of user control that
        'we previously stored in the UserData section
        pUserData = GetWindowLongPtr(hwnd, GWLP_USERDATA)
        'UPGRADE_WARNING: Couldn't resolve default property of object ctlRefToCtrl. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"'
        CopyMemory(ctlRefToCtrl, pUserData, 4)
        
        'call control procedure which resides in control itself
        MainCtrlProc = ctlRefToCtrl.CtrlProc(hwnd, Msg, wParam, lParam)
        
        'clean up
        'UPGRADE_WARNING: Couldn't resolve default property of object ctlRefToCtrl. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"'
        CopyMemory(ctlRefToCtrl, 0, 4)
        'UPGRADE_NOTE: Object ctlRefToCtrl may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1029"'
        ctlRefToCtrl = Nothing
        
    End Function


How do I upgrade correcltly?

Also:
VB.NET:
Expand Collapse Copy
Name 'ObjPtr' is not declared.

Would creating a DLL in VB6 that had a function 'ObjPtr_', which did the following:
VB.NET:
Expand Collapse Copy
ObjPtr_ = ObjPtr([I]object[/I])

work?


Please reply! :)
 
Back
Top