Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Passing empty String to DLL

  1. #1

    Default Passing empty String to DLL

    Hi

    I'm wondering how i can pass an empty String to a Unicode DLL. This is the DLL Declaration:

    Code:
    External_Function LlDefineLayoutEf "LlDefineLayoutW" LLDllName Integer hLLJob Handle hWnd WString wTitle Integer nObjType WString wObjName Returns Integer
    When i call the Function with an empty ("") wObjName Parameter it is translated in a NULL Pointer, not into a pointer to an empty String which is sometimes needed.

    How can i manage it to get a Pointer to an empty String?

    Best Thanks

    Regards
    Bernhard

  2. #2
    Join Date
    Mar 2009
    Location
    Beech Hill - a village near Reading in the UK
    Posts
    1,991

    Default Re: Passing empty String to DLL

    Move "" to sVal
    Move (yourFuncName(AddressOf(sVal)) to ...

    I think!

    Mike

  3. #3

    Default Re: Passing empty String to DLL

    Hi Mike

    Thanks for your input. Unfortunately AddressOf(sVal) returns also a NULL Pointer

    Regards
    Bernhard

  4. #4
    Join Date
    Feb 2009
    Posts
    973

    Default Re: Passing empty String to DLL

    Bernard,

    Not my subjects but maybe look at AnsiValueToVariant in the cJGridColumn grid class.

    Peter
    Peter H. van Wijk
    X-Organize Consultancy N.V.

  5. #5
    Join Date
    Feb 2009
    Posts
    973

    Default Re: Passing empty String to DLL

    The following look like working.

    Code:
    //Top code
    
            Pointer pEmpty
            Boolean bOk
    
    //some code
    
            Move (Alloc(0)) to pEmpty
            Move (PointerToWString (pEmpty)) to sFile
            
            Move (LLDefineLayoutEf(piJobNumber(Self),hWnd,sText,iType,sFile)) to iRet
            
            Move (Free(pEmpty)) to bOk
    
    //Some more code


    Peter
    Peter H. van Wijk
    X-Organize Consultancy N.V.

  6. #6
    Join Date
    Feb 2009
    Location
    Brazil
    Posts
    3,462

    Default Re: Passing empty String to DLL

    That’s what I call “what a hack!”
    Samuel Pizarro

  7. #7

    Default Re: Passing empty String to DLL

    Peter,

    I also expect the following to work (which will avoid the manual allocation/freeing of memory)

    Code:
    WString sFile
    Pointer pEmpty
    
    //some code
    
    Move (""+Character(0)) to sFile
    Move (LLDefineLayoutEf(piJobNumber(Self),hWnd,sText,iType,sFile)) to iRet
    Putting the character(0) is not for putting the zero character at the end, but to have the runtime allocate the memory.
    Without that step you are passing a zero pointer like Bernhard mentioned.

    So you can put anything else, as long you do not put another empty string (even " " will allocate the memory for the string too)

    If you do the following however then you'll be surprised...

    Code:
      WString sFile
      Pointer pFile
    
       Move ("" + " ") to sFile
       Move (AddressOf(sFile)) to pFile  // <-- we have a pointer to a string
       Move (Replaces(sFile," ","")) to sFile
       Move (AddressOf(sFile)) to pFile // <-- runtime has released the memory already, this pointer is now zero
    So in short you cannot have a zero length string in DataFlex, but if you zero terminate it, then you can.

    (All tests DF20 64 bit, change the WString for a String and the results are the same)
    --
    Wil

  8. #8
    Join Date
    Mar 2009
    Location
    Beech Hill - a village near Reading in the UK
    Posts
    1,991

    Default Re: Passing empty String to DLL

    Bernard

    Have you initialized the string to ""?

    Mike

  9. #9

    Default Re: Passing empty String to DLL

    Mike,

    PMJI,
    Quote Originally Posted by Mike Peat View Post
    Bernard

    Have you initialized the string to ""?

    Mike
    Initializing it to "" does not work, it makes no difference, you'll get the null pointer.
    You can however initialize it to a single space.
    eg.
    Code:
    Move " " to sFile
    does work and will have the runtime allocate memory for your string.

    --
    Wil

  10. #10
    Join Date
    Mar 2009
    Location
    Beech Hill - a village near Reading in the UK
    Posts
    1,991

    Default Re: Passing empty String to DLL

    Ah ha!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •