No announcement yet.

Opaque structures: equiv. in PB

  • Filter
  • Time
  • Show
Clear All
new posts

  • Opaque structures: equiv. in PB

    Hello, All.

    I am being driven out of my mind trying to convert a tiny little C program using an off-the-shelf network DLL into PB.

    As far as I can tell, the only substantive difference that remains is the use of an opaque structure in C as a return value for a DLL initialization function. This opaque structure is then passed to a follow-up function like so:

    int hr, port;
    char *host, *login, *password;
    LDAP *ld;

    if (( ld = init( host, port )) != NULL)
    hr = bind( ld, login, password );

    Where LDAP is officially referred to in the DLL docs as an opaque structure and thus is not really "defined."

    So, vaguely understanding its purpose in C but knowing that there is nothing by that name in PB, I have tried it as a DWORD PTR, LONG PTR, DWORD, and LONG, all to no success:

    LOCAL host AS STRING, login AS STRING, password AS STRING
    LOCAL port AS LONG, hr AS LONG
    LOCAL LDAP AS (various options)

    ldap = init(host,port)
    hr = bind(ldap,login,password)

    The MOST annoying thing--and maybe this means there's a bug elsewhere in the DLL?--is that according to a network trace, my PB routine is actually sending and receiving the same decoded requests/responses as the C routine! The one thing that appears to differ is that PB never gets the SUCCESS value of 0 returned to hr, so it acts as if the call to bind() fails. Instead, I get hr as -1 or 1, depending on the datatype used for the struct.

    Anybody have an idea on this?

    Thanks in advance,



  • #2
    LDAP is the type, ld is the variable name. As an undefined pointer,
    you might as well make it a DWORD, although any of the types you've
    mentioned are compatible. Odds are, the declare for bind is wrong, or
    there's another similar error. Are you sure you're checking for the right
    value? It's common for C routines to return 0 for failure, not success,
    although conventions differ.

    C strings defined by "char *" should be ASCIIZ, not STRING, in PB.

    Tom Hanlin
    PowerBASIC Staff


    • #3

      Thanks so much for (a) being awake, (b) posting back, and (c) prodding me to solve the problem! You would not believe what I've put myself through, only to conclude yet again that I'm an idiot. Why don't these things ever have empowering endings?

      > Odds are, the declare for bind is wrong


      ldap_simple_bind_s LDAP_P((
      LDAP *ld,
      LDAP_CONST char *who,
      LDAP_CONST char *passwd ));


      DECLARE FUNCTION ldap_simple_bind_s LIB "ldapsdk.DLL" ALIAS "ldap_simple_bind" ( ldap AS DWORD, ldap_login AS ASCIIZ, ldap_password AS ASCIIZ) AS LONG

      Yep, I caught it too--FINALLY! Problem is, o'course, there's an another function by that OTHER alias which returns (basically) a callback for an asynchronous call. So since the alias existed, it never threw an outright error.

      For the record, though:

      > C strings defined by "char *" should be ASCIIZ, not STRING, in PB.

      I should have taken out the STRINGs, which were in there from my troubleshooting. They don't affect the function (that is, on the wire).

      > common for C routines to return 0 for failure...Are you sure you're checking for the right value?

      Yes, it returns 0 for no error, probably because it's made to be called from C++ under Win32.

      Thanks again,