Announcement

Collapse
No announcement yet.

How can I pass an ASCIIZ array to a dll?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Michael Mattias
    replied
    If the strings are not all the same length (or if they are) you can advance the pointer dynamically by getting the length of each piece......
    Code:
    pszStr = pArr ' First array element
    ? @pszStr
    pszStr = pszStr  + Lstrlen(BYVAL pszStr) + 1 
    ? @pszStr
    pszStr = pszStr  + Lstrlen(BYVAL pszStr) + 1 
    ? @pszStr 
    ...

    Leave a comment:


  • Kev Peel
    replied
    Michael,

    No problem, glad to help

    You may want to use a size variable or constant to reference the array elements (if the size changes) by using arithmetic, ie: pszStr = pArr + (255 * element).

    Another method is a UDT pointer:

    Code:
    TYPE STR_ELEMENT
         szElement As Asciiz * 255
    END TYPE
     
    LOCAL pEle AS STR_ELEMENT PTR
    pEle = pArr
     
    ? @pEle[0].szElement ' First array element

    Leave a comment:


  • Michael Rich
    replied
    Kev,

    You got me going in the right direction and using a modification to your Method two, I got it to work!.

    See below:

    LOCAL pszStr AS ASCIIZ PTR
    pszStr = pArr ' First array element
    ? @pszStr
    pszStr = pArr + 255 ' Second array element
    ? @pszStr
    pszStr = pArr + 510 ' Third array element
    ? @pszStr

    Kev - thanks again for all your help, and thanks to all who took the time to reply.

    Michael

    Leave a comment:


  • Chris Holbrook
    replied
    if you have the address of the array then you can examine memory at that address and get clues, particularly if you know what kind of data to expect. Warning - if you try to examine memory to which you do not have access, you will GPF!

    you may find this viewer useful, given the address of the array.

    Leave a comment:


  • Michael Rich
    replied
    Hi Walter;

    I just need to get the array strings FROM IBASIC into the PB dll. I do NOT need to modify strings and pass them back to IBASIC.

    Michael

    Leave a comment:


  • Walt Thompson
    replied
    Hi Michael;

    According to the PB ASCIIZ documentation PB passes ACSIIZ strings by reference. That is the pointer to the ASCIIZ data is passed to the called function, not the actual data. Does IBASIC expect the actual data?

    If IBASIC expects the data, then you could create a standard string, append a $NUL to it, and pass it to IBASIC.
    Last edited by Walt Thompson; 19 Jun 2008, 01:18 PM. Reason: spelling correction

    Leave a comment:


  • Kev Peel
    replied
    This might work for the array:

    Code:
    Function TestFunc(ByVal pArr As DWORD PTR) As Long
     
    ' Method one (comment out to disable)
    local pszStr As Ascii Ptr
    pszStr = @pArr[0] ' First array element
    ? @pszStr
    pszStr = @pArr[1] ' Second array element
    ? @pszStr
     
    ' Method two (comment out to disable)
    local pszStr As Ascii Ptr
    pszStr = pArr ' First array element
    ? @pszStr
    pszStr = pArr + 4 ' Second array element
    ? @pszStr
     
    End Function
    If the above doesn't work either then odds are it's using an array descriptor instead of actual pointer locations. It can be very difficult to discover the format of a descriptor if you don't have a definition for it.
    Last edited by Kev Peel; 19 Jun 2008, 01:05 PM.

    Leave a comment:


  • Michael Rich
    replied
    Chris - all good questions - but that's the problem, I checked the IBASIC documentation and I am unable to find the answers. So it is all trial and error. So far, all my trials have been errors.

    Thanks,

    Michael

    Leave a comment:


  • Michael Rich
    replied
    Thanks for the reply MCM.

    I tried you're suggested code and it crashed.

    You're right - "But ya gots to know what iBasic is passing" - if we lnew what it was passing then anyone could be a clever programmer! I checked their documentation - couldn't find the answer. IBASIC is no longer supported - that's one of the may reasons I just switched to PowerBASIC.

    Any suggestions on how to attack this by trial and error?

    Thanks again,

    Michael

    Leave a comment:


  • Michael Mattias
    replied
    "Array" to PowerBASIC means something special... a PB-proprietary array descriptor is passed on the stack by reference.

    If IBasic is passing an array, it could be what Windows would pass for an "array of null-teminated strings" : a contiguous block of memory with individual strings delimited by $NUL (CHR$(0)) with an additional $NUL at the end.

    In this case you will have to PARSE out that string into elements; your function will probably use the address of the memory block as its parameter.

    But Ibasic might be passing an array of OLE string handles. In that case it is probably passing the address of a block of memory containing those strings, and you could use in your procedure...
    Code:
    FUNCTION foo ( BYVAL addr AS DWORD, BYVAL nEl AS LONG) EXPORT AS LONG
    
     LOCAL S() AS STring
     REDIM S (nEl-1) AT addr 
    
    ..
    .. to use a string array.

    It all depends what iBasic is actually passing. If it's not some kind of proprietary descriptor, writing your function to handle it will be really straightforward.

    But ya gots to know what iBasic is passing.

    MCM

    Leave a comment:


  • Chris Holbrook
    replied
    Does the IBASIC function pass the array on the stack, or does it allocate memory and pass a pointer to it? And does it pass an array of fixed-length asiz strings, or an array of DWORD pointers?

    Leave a comment:


  • Michael Rich
    started a topic How can I pass an ASCIIZ array to a dll?

    How can I pass an ASCIIZ array to a dll?

    I need to pass a single dimension string array from IBASIC to a dll created with PowerBASIC. I believe IBASIC uses ASCIIZ strings.

    Tried lots of different things, but can’t get it to work.

    BTW - Passing a single string variable from IBASIC to the function in the PowerBASIC dll works using ASCIIZ.

    Help.

    Thanks,

    Michael Rich
Working...
X