none
callback function from dll library throws NullRefernceException RRS feed

  • Question

  • Hello!

     

    Can you help me, I get NullRefernceException when I use callback function cal from dll library:

    "Object reference not set to an instance of an object."

    I use .net 1.1 for LDAP client.

    I use Microsoft "winldap" dll.

    Some functions from dll use callback function:

    [DllImport("wldap32.dll", CallingConvention=CallingConvention.Cdecl)]

    public static extern int ldap_set_optionW([In] IntPtr ldapHandle, [In] LdapOption option, VERIFYSERVERCERT outValue);

    VERIFYSERVERCERT  outValue - callback function;

    This method save pointer to callback functions in settings Smile

    public delegate bool VERIFYSERVERCERT(IntPtr Connection, IntPtr pServerCert);  //calback function delegate

     

    [DllImport("wldap32.dll", CallingConvention=CallingConvention.Cdecl)]

    public static extern int ldap_connect([In] IntPtr ldapHandle, LDAP_TIMEVAL timeout);

     

    This function uses calback function which was set in "ldap_set_optionW" function.

    Using:

    //1. Callback function

    public static bool CallbackFunction(IntPtr Connection, IntPtr pServerCert)

    {

       return true;

    }

     

    //2. save function pointer in settings
    ldap_set_optionW(ldapHandle, LdapOption.LDAP_OPT_SERVER_CERTIFICATE, new VERIFYSERVERCERT(CallbackFunction))


    //3. Call main function
    ldap_connect([In] IntPtr ldapHandle, LDAP_TIMEVAL timeout);

     

    But after point "3." I get exception:
    System.NullReferenceException:
    "Object reference not set to an instance of an object."
    HResult: -2147467261

    I got this code from System.DirectoryServices.Protocols library from .net 2.0, in original code it was:

    [DllImport("wldap32.dll", CallingConvention=CallingConvention.Cdecl, CharSet=CharSet.Unicode)]

    public static extern int ldap_connect([In] IntPtr ldapHandle, LDAP_TIMEVAL timeout);

     

    [DllImport("wldap32.dll", CallingConvention=CallingConvention.Cdecl, CharSet=CharSet.Unicode)]

    public static extern int ldap_set_optionW([In] IntPtr ldapHandle, [In] LdapOption option, VERIFYSERVERCERT1 outValue);

     

    [UnmanagedFunctionPointer(CallingConvention.Cdecl)]

    internal delegate bool VERIFYSERVERCERT(IntPtr Connection, IntPtr pServerCert);

     

    as I undestand all problems that .net 1.1 does not have [UnmanagedFunctionPointer(CallingConvention.Cdecl)] attribute. How can I use it for net 1.1.?

    P.S.
    I can not use .net 2 and System.DirectoryServices.Protocols functions Smile

    P.P.S
    I can not use System.DirectoryServices from .net 1.1 because System.DirectoryServices does not support custom server certificate validation and soes not support bind() method Smile


    Please, help me Smile

    Monday, February 18, 2008 12:39 PM

Answers

All replies