Working code:

int GetGlobalOrder(char *global, int start, int end, CACHE_EXSTRP result)
{
    if (isInitialized == false) {
        Initialize(NULL);
    }

    // narg Number of subscript expressions pushed onto the argument stack.
    int narg = 1;

    // Direction for the $Order is 1 for forward, -1 for reverse.
    int dir = 1;
    // Indicates whether the data value, if there is one, should be returned.
    int valueflag = 1;

    // Has argument flag
    int flag = 0;

    // key - current subscript
    int key = start - 1;
    
    // row count
    int c=0;

    while (key<end) {
        CACHEPUSHGLOBAL(strlen(global), global);
        CACHEPUSHINT(key);
        CACHEGLOBALORDER(narg,  dir, valueflag);

        CACHEPOPINT(&flag);
        if (flag) {
          //use CACHETYPE() to get the value type, then the appropriate CACHEPOP for the subscript
          CACHEEXSTRKILL(result);
          CACHEPOPEXSTR(result);
          // do stuff with result
        }
        //use CACHETYPE() to get the subscript type, then the appropriate CACHEPOP for the subscript
        int type = CACHETYPE();

        CACHEPOPINT(&key);

        if (key==NULL) {
            break;
        }

        c++;
    }
    return ZF_SUCCESS;
}

Thanks to  @Charles Sorenson II for help!