Results 1 to 3 of 3

Thread: Compile err Too many local, nonstatic variables

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177

    Question

    I am getting this compile error when I hit my winsock_DataArrival routine. The error occurs on the CopyMemory statement in the following snippet.
    Code:
        Case giStatusByProc, giStatusByCust   ' 3000, 4000
             ' get the status reply record
             CopyMemory StatusReply, bHoldRec(0), sizeofStatusRep
             With StatusReply
              NewRequest(StandardHeader.curr_wndw).sbProcReq.Panels(1).Text = _
                                "Receiving data from " & .sysname
    The user defined structure StatusReply is defined as follows in my main.bas module:
    Code:
    Public Const giMaxLines           As Integer = 150&
    ...
    Public Type dclStatusRep
                rep_hdr               As String * 52 ' holder for dclStdHeader
                repid                 As Integer     ' short rep;
                sysname               As String * 8  ' char  sys[8];
                lines                 As Integer     ' short lines;
                statline(giMaxLines)  As String * 66 ' holders for dclTypeStatus
           End Type
    ...
    Public StatusReply                As dclStatusRep
    Changing the constant giMaxLines to 100 will compile. Obviously there is some maximum value between 100 and 150 that I can use. I am wondering if someone knows if there is a way to manipulate the number of local variables allowed. Or is this some fixed nonchangable number.

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,176

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177
    Sorry, I had intended to look for something on this before posting. I guess I got sidetracked.

    This is an odd message for what appears to be an allocation problem.

    Having read the kb article, I can say that it was not much help.
    CAUSE
    The above error is the result of a bug in the Visual Basic compiler when allocating memory for passing User Defined Types (UDTs) to functions or subroutines in DLLs. The error may occur when this amount exceeds approximately 64KB.
    At just over 10,100 bytes my UDT is well under the 64KB mentioned in the article.
    RESOLUTION
    You can work around this problem by changing the way that such UDTs are passed to the DLL. When you pass a UDT to a DLL, you are actually passing a pointer to the first memory location of the UDT. Another way to pass this pointer is by copying the UDT to a Byte array and passing the first element of the Byte array by reference.
    This raises some more questions...
    1) I am using CopyMemory to convert from a Byte array to the UDT. I would assume that I would see the same eror trying to convert the UDT to a Byte array.
    2) If the UDT is being passed by reference, why does the dll have to allocate memory? Is my C background getting in the way here?

Posting Permissions

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



Click Here to Expand Forum to Full Width