Announcement

Collapse
No announcement yet.

Using CopyMemory : "Err 519/Missing declaration COPYMEMORY"?

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

  • Using CopyMemory : "Err 519/Missing declaration COPYMEMORY"?

    Hi,

    I call NetServerEnum to query the local master browser for the list of servers connected to the network. This API returns a pointer to a buffer, whose contents I must copy into a structure to display one of its fields. For this, the code snippet I found in a VB-oriented web site uses the classic CopyMemory... but PB/DLL says it's undefined even though it shows up in win32api.inc. I made sure that all the variables are defined. Any idea?

    Thx
    FF.
    --------------------------------
    'win32api.inc
    DECLARE SUB CopyMemory LIB "KERNEL32.DLL" ALIAS "RtlCopyMemory" (pDestination AS ANY, pSource AS ANY, BYVAL cbLength AS LONG)

    'my prog
    #INCLUDE "win32api.inc"

    FUNCTION GetServers(sDomain AS STRING) AS LONG
    'lists all servers of the specified type
    'that are visible in a domain.

    DIM bufptr AS LONG
    DIM dwEntriesread AS LONG
    DIM dwTotalentries AS LONG
    DIM dwResumehandle AS LONG
    DIM se100 AS SERVER_INFO_100
    DIM success AS LONG
    DIM nStructSize AS LONG
    DIM cnt AS LONG

    nStructSize = LEN(se100)

    success = NetServerEnum(0&, _
    100, _
    bufptr, _
    %MAX_PREFERRED_LENGTH, _
    dwEntriesread, _
    dwTotalentries, _
    %SV_TYPE_ALL, _
    0&, _
    dwResumehandle) 'if all goes well
    IF success = %NERR_SUCCESS AND _
    success <> %ERROR_MORE_DATA THEN

    FOR cnt = 0 TO dwEntriesread - 1
    CopyMemory se100, BYVAL bufptr + (nStructSize * cnt), nStructSize
    'List1.AddItem GetPointerToByteStringW(se100.sv100_name)
    NEXT

    END IF

    CALL NetApiBufferFree(bufptr)

    GetServers = dwEntriesread

    END FUNCTION




    ------------------

  • #2
    It turns out that the RtlCopyMemory call, also known as CopyMemory, is not
    really available under 32-bit Windows. The Microsoft SDKs define all of
    these *Memory routines as C macros... oddly enough, since RtlMoveMemory
    does seem to actually exist. I'd guess that what you're thinking of as
    CopyMemory is, in fact, aliased to RtlMoveMemory, which does about the same
    thing.

    The latest version of the Win32API file provides SUBs that mimic the C
    macros for the Rtl*Memory functions.

    Keep an eye on http://www.powerbasic.com/files/pub/pbwin/ for the Win32API
    files. These are updated pretty much continuously. While you certainly don't
    need to download every new version, it wouldn't hurt to get the latest files
    every month or two.


    ------------------
    Tom Hanlin
    PowerBASIC Staff

    Comment


    • #3
      Thx Tom!

      After searching through the archives of this forum (why didn't I think of this?), someone mentionned MoveMemory instead... which solved the issue:

      MoveMemory VARPTR(se100), BYVAL bufptr + (nStructSize * cnt), nStructSize

      But then, does "moving" data mean that the original buffer is emptied?

      BTW, as I venture into the wild world of playing with pointers, did someone write a summary of how to use them in PowerBasic?

      Thx for the prompt answer
      FF.


      ------------------

      Comment


      • #4
        Frederic,

        The online Help available in the PB/DLL IDE has a page that covers
        the use of pointers.

        Regards,


        ------------------
        Clay C. Clear

        [email protected]

        http://www.v3space.com/a/a39/202/

        Comment


        • #5
          But then, does "moving" data mean that the original buffer is emptied?
          No. It's a copy operation.

          ------------------
          Tom Hanlin
          PowerBASIC Staff

          Comment


          • #6
            Thx again Tom.

            I've learned sthing else when playing with that MoveMemory(): An ASCIIZ variable is really like a string in C, and totally different from a STRING in Basic: The variable actually contains the address of the buffer allocated to the string. Which is why the following works:

            LOCAL sMyString AS ASCIIZ * 128
            LOCAL pMyString as ASCIIZ PTR

            pMyString = VARPTR(sMyString)

            'Both work
            MoveMemory @pMyString, BYVAL se100.sv100_name, 1
            MoveMemory BYVAL pMyString, BYVAL se100.sv100_name, 1

            pMyString actually contains the address of sMyString. Therefore, MoveMemory() can be passed this address either by derefencing pMyString with @pMyString, or by passing the contents of pMyString with BYVAL (otherwise, PB will pass the address of pMyString instead of the address it contains.)

            Correct?

            Thx
            FF.

            ------------------

            Comment


            • #7
              Yes, you are correct Frederic.

              Of course, you can also use BYVAL VARPTR(MyString) too, eliminating the need for a separate pointer.

              ------------------
              Lance
              PowerBASIC Support
              mailto:supp[email protected][email protected]</A>
              Lance
              mailto:[email protected]

              Comment


              • #8
                Originally posted by Lance Edmonds:
                Of course, you can also use BYVAL VARPTR(MyString) too, eliminating the need for a separate pointer.
                Thx for the tip!

                Now, I just have to find why NetServerEnum() and NetMessageBufferSend() take each a good 10s to execute on my stand-alone W2K Pro host... To investigate, I enabled it to register and look up NetBIOS infos on a Linux host running Samba 2.2.x, but it makes no difference.

                Ciao
                FF.



                ------------------

                Comment

                Working...
                X