No announcement yet.

Macro Expansion Errors

  • Filter
  • Time
  • Show
Clear All
new posts

  • Macro Expansion Errors

    I am trying to find a list of errors that appears as "Macro Expansion Error" codes, but can not find anything. The closest I can find is the help manual mentioning how if you had a space in your macro in the wrong spot it would cause an error.

    or more specifically
    Macro parameters are substituted directly, so whitespace characters in the passed macro parameters may cause unexpected problems if the expanded code is syntactically incorrect with the additional whitespace. For example, this can be important when specifying UDT variables as macro parameters. Consider the following code:

    TYPE MyType

    lCount AS LONG

    szText AS ASCIIZ * 256


    MACRO PresetUDT(u)

    u.lCount = 1

    u.szText = SPACE$(256)



    DIM x AS MyType


    PresetUDT(x ) ' This line causes an Error 526


    In the code above, the second macro expansion fails to compile because the trailing space in the passed macro parameter becomes part of the expanded code. In this situation, this additional space character breaks the syntax of the UDT variable reference within the expanded macro, triggering a compile-time Error 526 ("Period not allowed"). If we examine how the two expanded macro statements would appear, the problem becomes immediately obvious:

    x .lCount = 1


    x .szText = SPACE$(256)


    (Please note that the caret symbols (^) above have been added purely to illustrate the exact position of the problem)
    Now in my case my code is
            Result = SetupDiGetDeviceInterfaceDetail _
               (DeviceInfoSet, _
               MyDeviceInterfaceData, _
               VARPTR(DetailDataBuffer(0)), _
               DetailData, _
               Needed, _
               BYVAL %NULL)
    and the functions are defined as
    MACRO SetupDiGetDeviceInterfaceDetail(DeviceInfoSet, DeviceInterfaceData, DeviceInterfaceDetailData, DeviceInterfaceDetailDataSize, RequiredSize, DeviceInfoData) = _
    SetupDiGetDeviceInterfaceDetailW(DeviceInfoSet, DeviceInterfaceData, DeviceInterfaceDetailData, DeviceInterfaceDetailDataSize, RequiredSize, DeviceInfoData)
    DECLARE FUNCTION SetupDiGetDeviceInterfaceDetailA LIB "SETUPAPI.DLL" ALIAS "SetupDiGetDeviceInterfaceDetailA" (BYVAL DeviceInfoSet AS DWORD, _
                                                                                                                   BYREF DeviceInterfaceData AS SP_DEVICE_INTERFACE_DATA, _
                                                                                                                   BYREF DeviceInterfaceDetailData AS SP_DEVICE_INTERFACE_DETAIL_DATA_A, _
                                                                                                                   BYVAL DeviceInterfaceDetailDataSize AS DWORD, _
                                                                                                                   BYREF RequiredSize AS DWORD, _
                                                                                                                   BYREF DeviceInfoData AS SP_DEVINFO_DATA) AS LONG
    MACRO SetupDiGetDeviceInterfaceDetail(DeviceInfoSet, DeviceInterfaceData, DeviceInterfaceDetailData, DeviceInterfaceDetailDataSize, RequiredSize, DeviceInfoData) = _
    SetupDiGetDeviceInterfaceDetailA(DeviceInfoSet, DeviceInterfaceData, DeviceInterfaceDetailData, DeviceInterfaceDetailDataSize, RequiredSize, DeviceInfoData)
    so I am stuck determining what am I doing wrong? and what does the error code mean?
    The help file does point out that a probable cause would be in a UDT which I am using, but if necessary I will post my code in whole (in progress because I am porting USB Complete VB code, and not sure how it works just yet, so it may be TMI, but maybe I have missed relevant code by snippets?)

    Anyways, any help finding what the macro expansion error codes are, or correcting my error would be of great help
    Engineer's Motto: If it aint broke take it apart and fix it

    "If at 1st you don't succeed... call it version 1.0"

    "Half of Programming is coding"....."The other 90% is DEBUGGING"

    "Document my code????" .... "WHYYY??? do you think they call it CODE? "

  • #2
    The beauty of Macros can also be the bane of their use. Since they are direct text substitutions you have to make sure of the syntax both the parameter list (white space warning) and the code in the body of the macro. The onus is squarely on the programmer in this regard. There are a few areas where where the compiler can and does check MACRO constructs, but not the code in them per-se, except as it will appear in the in-line result.

    To see all the error codes associated with macros, use the search feature of the help file, type MACRO and press enter. The list here includes the following direct macro structuring and possible macro errors:

    In your posted code, macro/function definitions ... looks like you have 2 different macros with the same name: SetupDiGetDeviceInterfaceDetail

    If you need more help, please post more code and specific errors you may be seeing.
    Rick Angell