Пример #1
0
void AFXAPI AfxGlobalFree(HGLOBAL hGlobal)
{
	if (hGlobal == NULL)
		return;

	// avoid bogus warning error messages from various debugging tools
	ASSERT(GlobalFlags(hGlobal) != GMEM_INVALID_HANDLE);
	UINT nCount = GlobalFlags(hGlobal) & GMEM_LOCKCOUNT;
	while (nCount--)
		GlobalUnlock(hGlobal);

	// finally, really free the handle
	GlobalFree(hGlobal);
}
Пример #2
0
void* prim_globalFlags(HGLOBAL arg1)
{ static struct {HsWord32 res1;HsInt gc_failed;HsPtr gc_failstring;} gc_result;
  UINT res1;int gc_failed;
	    char* gc_failstring;
  do {res1 = GlobalFlags(arg1);
      if ((gc_failed = ( res1==GMEM_INVALID_HANDLE ))) {gc_failstring = ErrorWin("GlobalFlags") ;}
      else {gc_failed = 0;}
      gc_result.res1 = (UINT)(res1);
      gc_result.gc_failed = gc_failed;
      gc_result.gc_failstring = gc_failstring;
      
      return(&gc_result);} while(0);
}
Пример #3
0
void
_86_GlobalPageUnlock (ENV *envp,LONGPROC f)
{
    DWORD retcode;
    WORD wSel;
    HGLOBAL hGlobal;

    wSel = GETWORD(SP+4);
    hGlobal = GetSelectorHandle(wSel);
		
    retcode = GlobalFlags(hGlobal);
    GlobalUnlock(hGlobal);
    envp->reg.sp += HANDLE_86 + RET_86;
    envp->reg.ax = LOWORD(retcode);
    envp->reg.dx = HIWORD(retcode);
}
Пример #4
0
static void test_ImmGetIMCCLockCount(void)
{
    HIMCC imcc;
    DWORD count, g_count, ret, i;
    VOID *p;

    imcc = ImmCreateIMCC(sizeof(CANDIDATEINFO));
    count = ImmGetIMCCLockCount(imcc);
    ok(count == 0, "expect 0, returned %d\n", count);
    ImmLockIMCC(imcc);
    count = ImmGetIMCCLockCount(imcc);
    ok(count == 1, "expect 1, returned %d\n", count);
    ret = ImmUnlockIMCC(imcc);
    ok(ret == FALSE, "expect FALSE, ret %d\n", ret);
    count = ImmGetIMCCLockCount(imcc);
    ok(count == 0, "expect 0, returned %d\n", count);
    ret = ImmUnlockIMCC(imcc);
    ok(ret == FALSE, "expect FALSE, ret %d\n", ret);
    count = ImmGetIMCCLockCount(imcc);
    ok(count == 0, "expect 0, returned %d\n", count);

    p = ImmLockIMCC(imcc);
    ok(GlobalHandle(p) == imcc, "expect %p, returned %p\n", imcc, GlobalHandle(p));

    for (i = 0; i < GMEM_LOCKCOUNT * 2; i++)
    {
        ImmLockIMCC(imcc);
        count = ImmGetIMCCLockCount(imcc);
        g_count = GlobalFlags(imcc) & GMEM_LOCKCOUNT;
        ok(count == g_count, "count %d, g_count %d\n", count, g_count);
    }
    count = ImmGetIMCCLockCount(imcc);
    ok(count == GMEM_LOCKCOUNT, "expect GMEM_LOCKCOUNT, returned %d\n", count);

    for (i = 0; i < GMEM_LOCKCOUNT - 1; i++)
        GlobalUnlock(imcc);
    count = ImmGetIMCCLockCount(imcc);
    ok(count == 1, "expect 1, returned %d\n", count);
    GlobalUnlock(imcc);
    count = ImmGetIMCCLockCount(imcc);
    ok(count == 0, "expect 0, returned %d\n", count);

    ImmDestroyIMCC(imcc);
}
Пример #5
0
void
IT_GLOBALLOCK (ENV *envp,LONGPROC f)
{
	DWORD retcode;
	WORD wSel;
	HGLOBAL hGlobal=0;
	HMODULE hModule;
	MODULEINFO *modinfo = NULL;
	UINT	    memflags;

	wSel = GETWORD(SP+4) | 1;
	/* This is extra work that should be eliminated */
	if (!(wSel & OM_MASK)) {		/* can be hInstance */
	    hGlobal = GetSelectorHandle(wSel);
	    memflags = GlobalFlags(hGlobal);
	    retcode = (DWORD)GlobalLock(hGlobal);
	}
	else {
	    if ((hModule = GetModuleFromInstance(wSel))) {
		modinfo = GETMODULEINFO(hModule);
		if ((wSel = GetDataSelectorFromInstance(wSel))) {
	    	    hGlobal = GetSelectorHandle(wSel);
		    retcode = (DWORD)GlobalLock(hGlobal);
		}
		else 
		    retcode = (DWORD) NULL;
	    }
	    else
		retcode = (DWORD) NULL;
	}
			
	envp->reg.sp += HANDLE_86 + RET_86;
	if (retcode)
		retcode = (DWORD)MAKELP(wSel,0);
	envp->reg.ax = LOWORD(retcode);
	envp->reg.dx = HIWORD(retcode);
	if (modinfo != NULL)
	  RELEASEMODULEINFO(modinfo);
}
Пример #6
0
static void test_heap(void)
{
    LPVOID  mem;
    LPVOID  msecond;
    DWORD   res;
    UINT    flags;
    HGLOBAL gbl;
    HGLOBAL hsecond;
    SIZE_T  size, size2;
    const SIZE_T max_size = 1024, init_size = 10;

    /* Heap*() functions */
    mem = HeapAlloc(GetProcessHeap(), 0, 0);
    ok(mem != NULL, "memory not allocated for size 0\n");
    HeapFree(GetProcessHeap(), 0, mem);

    mem = HeapReAlloc(GetProcessHeap(), 0, NULL, 10);
    ok(mem == NULL, "memory allocated by HeapReAlloc\n");

    for (size = 0; size <= 256; size++)
    {
        SIZE_T heap_size;
        mem = HeapAlloc(GetProcessHeap(), 0, size);
        heap_size = HeapSize(GetProcessHeap(), 0, mem);
        ok(heap_size == size || heap_size == resize_9x(size), 
            "HeapSize returned %lu instead of %lu or %lu\n", heap_size, size, resize_9x(size));
        HeapFree(GetProcessHeap(), 0, mem);
    }

    /* test some border cases of HeapAlloc and HeapReAlloc */
    mem = HeapAlloc(GetProcessHeap(), 0, 0);
    ok(mem != NULL, "memory not allocated for size 0\n");
    msecond = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, ~(SIZE_T)0 - 7);
    ok(msecond == NULL, "HeapReAlloc(~0 - 7) should have failed\n");
    msecond = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, ~(SIZE_T)0);
    ok(msecond == NULL, "HeapReAlloc(~0) should have failed\n");
    HeapFree(GetProcessHeap(), 0, mem);
    mem = HeapAlloc(GetProcessHeap(), 0, ~(SIZE_T)0);
    ok(mem == NULL, "memory allocated for size ~0\n");

    /* large blocks must be 16-byte aligned */
    mem = HeapAlloc(GetProcessHeap(), 0, 512 * 1024);
    ok( mem != NULL, "failed for size 512K\n" );
    ok( (ULONG_PTR)mem % 16 == 0 || broken((ULONG_PTR)mem % 16) /* win9x */,
        "512K block not 16-byte aligned\n" );
    HeapFree(GetProcessHeap(), 0, mem);

    /* Global*() functions */
    gbl = GlobalAlloc(GMEM_MOVEABLE, 0);
    ok(gbl != NULL, "global memory not allocated for size 0\n");

    gbl = GlobalReAlloc(gbl, 10, GMEM_MOVEABLE);
    ok(gbl != NULL, "Can't realloc global memory\n");
    size = GlobalSize(gbl);
    ok(size >= 10 && size <= 16, "Memory not resized to size 10, instead size=%ld\n", size);

    gbl = GlobalReAlloc(gbl, 0, GMEM_MOVEABLE);
    ok(gbl != NULL, "GlobalReAlloc should not fail on size 0\n");

    size = GlobalSize(gbl);
    ok(size == 0, "Memory not resized to size 0, instead size=%ld\n", size);
    ok(GlobalFree(gbl) == NULL, "Memory not freed\n");
    size = GlobalSize(gbl);
    ok(size == 0, "Memory should have been freed, size=%ld\n", size);

    gbl = GlobalReAlloc(0, 10, GMEM_MOVEABLE);
    ok(gbl == NULL, "global realloc allocated memory\n");

    /* GlobalLock / GlobalUnlock with a valid handle */
    gbl = GlobalAlloc(GMEM_MOVEABLE, 256);

    SetLastError(MAGIC_DEAD);
    mem = GlobalLock(gbl);      /* #1 */
    ok(mem != NULL, "returned %p with %d (expected '!= NULL')\n", mem, GetLastError());
    SetLastError(MAGIC_DEAD);
    flags = GlobalFlags(gbl);
    ok( flags == 1, "returned 0x%04x with %d (expected '0x0001')\n",
        flags, GetLastError());

    SetLastError(MAGIC_DEAD);
    msecond = GlobalLock(gbl);   /* #2 */
    ok( msecond == mem, "returned %p with %d (expected '%p')\n",
        msecond, GetLastError(), mem);
    SetLastError(MAGIC_DEAD);
    flags = GlobalFlags(gbl);
    ok( flags == 2, "returned 0x%04x with %d (expected '0x0002')\n",
        flags, GetLastError());
    SetLastError(MAGIC_DEAD);

    SetLastError(MAGIC_DEAD);
    res = GlobalUnlock(gbl);    /* #1 */
    ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
    SetLastError(MAGIC_DEAD);
    flags = GlobalFlags(gbl);
    ok( flags , "returned 0x%04x with %d (expected '!= 0')\n",
        flags, GetLastError());

    SetLastError(MAGIC_DEAD);
    res = GlobalUnlock(gbl);    /* #0 */
    /* NT: ERROR_SUCCESS (documented on MSDN), 9x: untouched */
    ok(!res && ((GetLastError() == ERROR_SUCCESS) || (GetLastError() == MAGIC_DEAD)),
        "returned %d with %d (expected '0' with: ERROR_SUCCESS or "
        "MAGIC_DEAD)\n", res, GetLastError());
    SetLastError(MAGIC_DEAD);
    flags = GlobalFlags(gbl);
    ok( !flags , "returned 0x%04x with %d (expected '0')\n",
        flags, GetLastError());

    /* Unlock an already unlocked Handle */
    SetLastError(MAGIC_DEAD);
    res = GlobalUnlock(gbl);
    /* NT: ERROR_NOT_LOCKED,  9x: untouched */
    ok( !res &&
        ((GetLastError() == ERROR_NOT_LOCKED) || (GetLastError() == MAGIC_DEAD)),
        "returned %d with %d (expected '0' with: ERROR_NOT_LOCKED or "
        "MAGIC_DEAD)\n", res, GetLastError());
 
    GlobalFree(gbl);
    /* invalid handles are caught in windows: */
    SetLastError(MAGIC_DEAD);
    hsecond = GlobalFree(gbl);      /* invalid handle: free memory twice */
    ok( (hsecond == gbl) && (GetLastError() == ERROR_INVALID_HANDLE),
        "returned %p with 0x%08x (expected %p with ERROR_INVALID_HANDLE)\n",
        hsecond, GetLastError(), gbl);
    SetLastError(MAGIC_DEAD);
    flags = GlobalFlags(gbl);
    ok( (flags == GMEM_INVALID_HANDLE) && (GetLastError() == ERROR_INVALID_HANDLE),
        "returned 0x%04x with 0x%08x (expected GMEM_INVALID_HANDLE with "
        "ERROR_INVALID_HANDLE)\n", flags, GetLastError());
    SetLastError(MAGIC_DEAD);
    size = GlobalSize(gbl);
    ok( (size == 0) && (GetLastError() == ERROR_INVALID_HANDLE),
        "returned %ld with 0x%08x (expected '0' with ERROR_INVALID_HANDLE)\n",
        size, GetLastError());

    SetLastError(MAGIC_DEAD);
    mem = GlobalLock(gbl);
    ok( (mem == NULL) && (GetLastError() == ERROR_INVALID_HANDLE),
        "returned %p with 0x%08x (expected NULL with ERROR_INVALID_HANDLE)\n",
        mem, GetLastError());

    /* documented on MSDN: GlobalUnlock() return FALSE on failure.
       Win9x and wine return FALSE with ERROR_INVALID_HANDLE, but on 
       NT 3.51 and XPsp2, TRUE with ERROR_INVALID_HANDLE is returned.
       The similar Test for LocalUnlock() works on all Systems */
    SetLastError(MAGIC_DEAD);
    res = GlobalUnlock(gbl);
    ok(GetLastError() == ERROR_INVALID_HANDLE,
        "returned %d with %d (expected ERROR_INVALID_HANDLE)\n",
        res, GetLastError());

    gbl = GlobalAlloc(GMEM_DDESHARE, 100);

    /* first free */
    mem = GlobalFree(gbl);
    ok(mem == NULL, "Expected NULL, got %p\n", mem);

    /* invalid free */
    if (sizeof(void *) != 8)  /* crashes on 64-bit Vista */
    {
        SetLastError(MAGIC_DEAD);
        mem = GlobalFree(gbl);
        ok(mem == gbl || broken(mem == NULL) /* nt4 */, "Expected gbl, got %p\n", mem);
        if (mem == gbl)
            ok(GetLastError() == ERROR_INVALID_HANDLE ||
               GetLastError() == ERROR_INVALID_PARAMETER, /* win9x */
               "Expected ERROR_INVALID_HANDLE or ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
    }

    /* GMEM_FIXED block expands in place only without flags */
    for (size = 1; size <= max_size; size <<= 1) {
        gbl = GlobalAlloc(GMEM_FIXED, init_size);
        SetLastError(MAGIC_DEAD);
        hsecond = GlobalReAlloc(gbl, size + init_size, 0);
        ok(hsecond == gbl || (hsecond == NULL && GetLastError() == ERROR_NOT_ENOUGH_MEMORY),
           "got %p with %x (expected %p or NULL) @%ld\n", hsecond, GetLastError(), gbl, size);
        GlobalFree(gbl);
    }

    /* GMEM_FIXED block can be relocated with GMEM_MOVEABLE */
    for (size = 1; size <= max_size; size <<= 1) {
        gbl = GlobalAlloc(GMEM_FIXED, init_size);
        SetLastError(MAGIC_DEAD);
        hsecond = GlobalReAlloc(gbl, size + init_size, GMEM_MOVEABLE);
        ok(hsecond != NULL,
           "got %p with %x (expected non-NULL) @%ld\n", hsecond, GetLastError(), size);
        mem = GlobalLock(hsecond);
        ok(mem == hsecond, "got %p (expected %p) @%ld\n", mem, hsecond, size);
        GlobalFree(hsecond);
    }

    gbl = GlobalAlloc(GMEM_DDESHARE, 100);

    res = GlobalUnlock(gbl);
    ok(res == 1 ||
       broken(res == 0), /* win9x */
       "Expected 1 or 0, got %d\n", res);

    res = GlobalUnlock(gbl);
    ok(res == 1 ||
       broken(res == 0), /* win9x */
       "Expected 1 or 0, got %d\n", res);

    GlobalFree(gbl);

    gbl = GlobalAlloc(GMEM_FIXED, 100);

    SetLastError(0xdeadbeef);
    res = GlobalUnlock(gbl);
    ok(res == 1 ||
       broken(res == 0), /* win9x */
       "Expected 1 or 0, got %d\n", res);
    ok(GetLastError() == 0xdeadbeef, "got %d\n", GetLastError());

    GlobalFree(gbl);

    /* GlobalSize on an invalid handle */
    if (sizeof(void *) != 8)  /* crashes on 64-bit Vista */
    {
        SetLastError(MAGIC_DEAD);
        size = GlobalSize((HGLOBAL)0xc042);
        ok(size == 0, "Expected 0, got %ld\n", size);
        ok(GetLastError() == ERROR_INVALID_HANDLE ||
           GetLastError() == ERROR_INVALID_PARAMETER, /* win9x */
           "Expected ERROR_INVALID_HANDLE or ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
    }

    gbl = GlobalAlloc( GMEM_FIXED, 0 );
    SetLastError(0xdeadbeef);
    size = GlobalSize( gbl );
    ok( size == 1, "wrong size %lu\n", size );
    GlobalFree( gbl );

    /* ####################################### */
    /* Local*() functions */
    gbl = LocalAlloc(LMEM_MOVEABLE, 0);
    ok(gbl != NULL, "local memory not allocated for size 0\n");

    gbl = LocalReAlloc(gbl, 10, LMEM_MOVEABLE);
    ok(gbl != NULL, "Can't realloc local memory\n");
    size = LocalSize(gbl);
    ok(size >= 10 && size <= 16, "Memory not resized to size 10, instead size=%ld\n", size);

    gbl = LocalReAlloc(gbl, 0, LMEM_MOVEABLE);
    ok(gbl != NULL, "LocalReAlloc should not fail on size 0\n");

    size = LocalSize(gbl);
    ok(size == 0, "Memory not resized to size 0, instead size=%ld\n", size);
    ok(LocalFree(gbl) == NULL, "Memory not freed\n");
    size = LocalSize(gbl);
    ok(size == 0, "Memory should have been freed, size=%ld\n", size);

    gbl = LocalReAlloc(0, 10, LMEM_MOVEABLE);
    ok(gbl == NULL, "local realloc allocated memory\n");

    /* LocalLock / LocalUnlock with a valid handle */
    gbl = LocalAlloc(LMEM_MOVEABLE, 256);
    SetLastError(MAGIC_DEAD);
    mem = LocalLock(gbl);      /* #1 */
    ok(mem != NULL, "returned %p with %d (expected '!= NULL')\n", mem, GetLastError());
    SetLastError(MAGIC_DEAD);
    flags = LocalFlags(gbl);
    ok( flags == 1, "returned 0x%04x with %d (expected '0x0001')\n",
        flags, GetLastError());

    SetLastError(MAGIC_DEAD);
    msecond = LocalLock(gbl);   /* #2 */
    ok( msecond == mem, "returned %p with %d (expected '%p')\n",
        msecond, GetLastError(), mem);
    SetLastError(MAGIC_DEAD);
    flags = LocalFlags(gbl);
    ok( flags == 2, "returned 0x%04x with %d (expected '0x0002')\n",
        flags, GetLastError());
    SetLastError(MAGIC_DEAD);

    SetLastError(MAGIC_DEAD);
    res = LocalUnlock(gbl);    /* #1 */
    ok(res, "returned %d with %d (expected '!= 0')\n", res, GetLastError());
    SetLastError(MAGIC_DEAD);
    flags = LocalFlags(gbl);
    ok( flags , "returned 0x%04x with %d (expected '!= 0')\n",
        flags, GetLastError());

    SetLastError(MAGIC_DEAD);
    res = LocalUnlock(gbl);    /* #0 */
    /* NT: ERROR_SUCCESS (documented on MSDN), 9x: untouched */
    ok(!res && ((GetLastError() == ERROR_SUCCESS) || (GetLastError() == MAGIC_DEAD)),
        "returned %d with %d (expected '0' with: ERROR_SUCCESS or "
        "MAGIC_DEAD)\n", res, GetLastError());
    SetLastError(MAGIC_DEAD);
    flags = LocalFlags(gbl);
    ok( !flags , "returned 0x%04x with %d (expected '0')\n",
        flags, GetLastError());

    /* Unlock an already unlocked Handle */
    SetLastError(MAGIC_DEAD);
    res = LocalUnlock(gbl);
    /* NT: ERROR_NOT_LOCKED,  9x: untouched */
    ok( !res &&
        ((GetLastError() == ERROR_NOT_LOCKED) || (GetLastError() == MAGIC_DEAD)),
        "returned %d with %d (expected '0' with: ERROR_NOT_LOCKED or "
        "MAGIC_DEAD)\n", res, GetLastError());

    LocalFree(gbl);
    /* invalid handles are caught in windows: */
    SetLastError(MAGIC_DEAD);
    hsecond = LocalFree(gbl);       /* invalid handle: free memory twice */
    ok( (hsecond == gbl) && (GetLastError() == ERROR_INVALID_HANDLE),
        "returned %p with 0x%08x (expected %p with ERROR_INVALID_HANDLE)\n",
        hsecond, GetLastError(), gbl);
    SetLastError(MAGIC_DEAD);
    flags = LocalFlags(gbl);
    ok( (flags == LMEM_INVALID_HANDLE) && (GetLastError() == ERROR_INVALID_HANDLE),
        "returned 0x%04x with 0x%08x (expected LMEM_INVALID_HANDLE with "
        "ERROR_INVALID_HANDLE)\n", flags, GetLastError());
    SetLastError(MAGIC_DEAD);
    size = LocalSize(gbl);
    ok( (size == 0) && (GetLastError() == ERROR_INVALID_HANDLE),
        "returned %ld with 0x%08x (expected '0' with ERROR_INVALID_HANDLE)\n",
        size, GetLastError());

    SetLastError(MAGIC_DEAD);
    mem = LocalLock(gbl);
    ok( (mem == NULL) && (GetLastError() == ERROR_INVALID_HANDLE),
        "returned %p with 0x%08x (expected NULL with ERROR_INVALID_HANDLE)\n",
        mem, GetLastError());

    /* This Test works the same on all Systems (GlobalUnlock() is different) */
    SetLastError(MAGIC_DEAD);
    res = LocalUnlock(gbl);
    ok(!res && (GetLastError() == ERROR_INVALID_HANDLE),
        "returned %d with %d (expected '0' with ERROR_INVALID_HANDLE)\n",
        res, GetLastError());

    /* LMEM_FIXED block expands in place only without flags */
    for (size = 1; size <= max_size; size <<= 1) {
        gbl = LocalAlloc(LMEM_FIXED, init_size);
        SetLastError(MAGIC_DEAD);
        hsecond = LocalReAlloc(gbl, size + init_size, 0);
        ok(hsecond == gbl || (hsecond == NULL && GetLastError() == ERROR_NOT_ENOUGH_MEMORY),
           "got %p with %x (expected %p or NULL) @%ld\n", hsecond, GetLastError(), gbl, size);
        LocalFree(gbl);
    }

    /* LMEM_FIXED memory can be relocated with LMEM_MOVEABLE */
    for (size = 1; size <= max_size; size <<= 1) {
        gbl = LocalAlloc(LMEM_FIXED, init_size);
        SetLastError(MAGIC_DEAD);
        hsecond = LocalReAlloc(gbl, size + init_size, LMEM_MOVEABLE);
        ok(hsecond != NULL,
           "got %p with %x (expected non-NULL) @%ld\n", hsecond, GetLastError(), size);
        mem = LocalLock(hsecond);
        ok(mem == hsecond, "got %p (expected %p) @%ld\n", mem, hsecond, size);
        LocalFree(hsecond);
    }

    /* trying to unlock pointer from LocalAlloc */
    gbl = LocalAlloc(LMEM_FIXED, 100);
    SetLastError(0xdeadbeef);
    res = LocalUnlock(gbl);
    ok(res == 0, "Expected 0, got %d\n", res);
    ok(GetLastError() == ERROR_NOT_LOCKED ||
       broken(GetLastError() == 0xdeadbeef) /* win9x */, "got %d\n", GetLastError());
    LocalFree(gbl);

    gbl = LocalAlloc( LMEM_FIXED, 0 );
    SetLastError(0xdeadbeef);
    size = LocalSize( gbl );
    ok( !size || broken(size == 1), /* vistau64 */
        "wrong size %lu\n", size );
    LocalFree( gbl );

    /* trying to lock empty memory should give an error */
    gbl = GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT,0);
    ok(gbl != NULL, "returned NULL\n");
    SetLastError(MAGIC_DEAD);
    mem = GlobalLock(gbl);
    /* NT: ERROR_DISCARDED,  9x: untouched */
    ok( (mem == NULL) &&
        ((GetLastError() == ERROR_DISCARDED) || (GetLastError() == MAGIC_DEAD)),
        "returned %p with 0x%x/%d (expected 'NULL' with: ERROR_DISCARDED or "
        "MAGIC_DEAD)\n", mem, GetLastError(), GetLastError());

    GlobalFree(gbl);

    /* trying to get size from data pointer (GMEM_MOVEABLE) */
    gbl = GlobalAlloc(GMEM_MOVEABLE, 0x123);
    ok(gbl != NULL, "returned NULL\n");
    mem = GlobalLock(gbl);
    ok(mem != NULL, "returned NULL.\n");
    ok(gbl != mem, "unexpectedly equal.\n");

    size = GlobalSize(gbl);
    size2 = GlobalSize(mem);
    ok(size == 0x123, "got %lu\n", size);
    ok(size2 == 0x123, "got %lu\n", size2);

    GlobalFree(gbl);

    /* trying to get size from data pointer (GMEM_FIXED) */
    gbl = GlobalAlloc(GMEM_FIXED, 0x123);
    ok(gbl != NULL, "returned NULL\n");
    mem = GlobalLock(gbl);
    ok(mem != NULL, "returned NULL.\n");
    ok(gbl == mem, "got %p, %p.\n", gbl, mem);

    size = GlobalSize(gbl);
    ok(size == 0x123, "got %lu\n", size);

    GlobalFree(gbl);

    size = GlobalSize((void *)0xdeadbee0);
    ok(size == 0, "got %lu\n", size);

}
Пример #7
0
static void test_pattern_brush(void)
{
    char buffer[sizeof(BITMAPINFOHEADER) + 2 * sizeof(RGBQUAD) + 32 * 32 / 8];
    BITMAPINFO *info = (BITMAPINFO *)buffer;
    HBRUSH brush;
    HBITMAP bitmap;
    LOGBRUSH br;
    INT ret;
    void *bits;
    DIBSECTION dib;
    HGLOBAL mem;

    bitmap = CreateBitmap( 20, 20, 1, 1, NULL );
    ok( bitmap != NULL, "CreateBitmap failed\n" );
    brush = CreatePatternBrush( bitmap );
    ok( brush != NULL, "CreatePatternBrush failed\n" );
    memset( &br, 0x55, sizeof(br) );
    ret = GetObjectW( brush, sizeof(br), &br );
    ok( ret == sizeof(br), "wrong size %u\n", ret );
    ok( br.lbStyle == BS_PATTERN, "wrong style %u\n", br.lbStyle );
    ok( br.lbColor == 0, "wrong color %u\n", br.lbColor );
    ok( (HBITMAP)br.lbHatch == bitmap, "wrong handle %p/%p\n", (HBITMAP)br.lbHatch, bitmap );
    DeleteObject( brush );

    br.lbStyle = BS_PATTERN8X8;
    br.lbColor = 0x12345;
    br.lbHatch = (ULONG_PTR)bitmap;
    brush = CreateBrushIndirect( &br );
    ok( brush != NULL, "CreatePatternBrush failed\n" );
    memset( &br, 0x55, sizeof(br) );
    ret = GetObjectW( brush, sizeof(br), &br );
    ok( ret == sizeof(br), "wrong size %u\n", ret );
    ok( br.lbStyle == BS_PATTERN, "wrong style %u\n", br.lbStyle );
    ok( br.lbColor == 0, "wrong color %u\n", br.lbColor );
    ok( (HBITMAP)br.lbHatch == bitmap, "wrong handle %p/%p\n", (HBITMAP)br.lbHatch, bitmap );
    ret = GetObjectW( bitmap, sizeof(dib), &dib );
    ok( ret == sizeof(dib.dsBm), "wrong size %u\n", ret );
    DeleteObject( bitmap );
    ret = GetObjectW( bitmap, sizeof(dib), &dib );
    ok( ret == 0, "wrong size %u\n", ret );
    DeleteObject( brush );

    memset( info, 0, sizeof(buffer) );
    info->bmiHeader.biSize = sizeof(info->bmiHeader);
    info->bmiHeader.biHeight = 32;
    info->bmiHeader.biWidth = 32;
    info->bmiHeader.biBitCount = 1;
    info->bmiHeader.biPlanes = 1;
    info->bmiHeader.biCompression = BI_RGB;
    bitmap = CreateDIBSection( 0, info, DIB_RGB_COLORS, (void**)&bits, NULL, 0 );
    ok( bitmap != NULL, "CreateDIBSection failed\n" );

    /* MSDN says a DIB section is not allowed, but it works fine */
    brush = CreatePatternBrush( bitmap );
    ok( brush != NULL, "CreatePatternBrush failed\n" );
    memset( &br, 0x55, sizeof(br) );
    ret = GetObjectW( brush, sizeof(br), &br );
    ok( ret == sizeof(br), "wrong size %u\n", ret );
    ok( br.lbStyle == BS_PATTERN, "wrong style %u\n", br.lbStyle );
    ok( br.lbColor == 0, "wrong color %u\n", br.lbColor );
    ok( (HBITMAP)br.lbHatch == bitmap, "wrong handle %p/%p\n", (HBITMAP)br.lbHatch, bitmap );
    ret = GetObjectW( bitmap, sizeof(dib), &dib );
    ok( ret == sizeof(dib), "wrong size %u\n", ret );
    DeleteObject( brush );
    DeleteObject( bitmap );

    brush = CreateDIBPatternBrushPt( info, DIB_RGB_COLORS );
    ok( brush != NULL, "CreatePatternBrush failed\n" );
    memset( &br, 0x55, sizeof(br) );
    ret = GetObjectW( brush, sizeof(br), &br );
    ok( ret == sizeof(br), "wrong size %u\n", ret );
    ok( br.lbStyle == BS_DIBPATTERN, "wrong style %u\n", br.lbStyle );
    ok( br.lbColor == 0, "wrong color %u\n", br.lbColor );
    ok( (BITMAPINFO *)br.lbHatch == info || broken(!br.lbHatch), /* nt4 */
        "wrong handle %p/%p\n", (BITMAPINFO *)br.lbHatch, info );
    DeleteObject( brush );

    br.lbStyle = BS_DIBPATTERNPT;
    br.lbColor = DIB_PAL_COLORS;
    br.lbHatch = (ULONG_PTR)info;
    brush = CreateBrushIndirect( &br );
    ok( brush != NULL, "CreatePatternBrush failed\n" );
    memset( &br, 0x55, sizeof(br) );
    ret = GetObjectW( brush, sizeof(br), &br );
    ok( ret == sizeof(br), "wrong size %u\n", ret );
    ok( br.lbStyle == BS_DIBPATTERN, "wrong style %u\n", br.lbStyle );
    ok( br.lbColor == 0, "wrong color %u\n", br.lbColor );
    ok( (BITMAPINFO *)br.lbHatch == info || broken(!br.lbHatch), /* nt4 */
        "wrong handle %p/%p\n", (BITMAPINFO *)br.lbHatch, info );

    mem = GlobalAlloc( GMEM_MOVEABLE, sizeof(buffer) );
    memcpy( GlobalLock( mem ), buffer, sizeof(buffer) );

    br.lbStyle = BS_DIBPATTERN;
    br.lbColor = DIB_PAL_COLORS;
    br.lbHatch = (ULONG_PTR)mem;
    brush = CreateBrushIndirect( &br );
    ok( brush != NULL, "CreatePatternBrush failed\n" );
    memset( &br, 0x55, sizeof(br) );
    ret = GetObjectW( brush, sizeof(br), &br );
    ok( ret == sizeof(br), "wrong size %u\n", ret );
    ok( br.lbStyle == BS_DIBPATTERN, "wrong style %u\n", br.lbStyle );
    ok( br.lbColor == 0, "wrong color %u\n", br.lbColor );
    ok( (HGLOBAL)br.lbHatch != mem, "wrong handle %p/%p\n", (HGLOBAL)br.lbHatch, mem );
    bits = GlobalLock( mem );
    ok( (HGLOBAL)br.lbHatch == bits || broken(!br.lbHatch), /* nt4 */
        "wrong handle %p/%p\n", (HGLOBAL)br.lbHatch, bits );
    ret = GlobalFlags( mem );
    ok( ret == 2, "wrong flags %x\n", ret );
    DeleteObject( brush );
    ret = GlobalFlags( mem );
    ok( ret == 2, "wrong flags %x\n", ret );

    brush = CreateDIBPatternBrushPt( info, DIB_PAL_COLORS );
    ok( brush != 0, "CreateDIBPatternBrushPt failed\n" );
    DeleteObject( brush );
    brush = CreateDIBPatternBrushPt( info, DIB_PAL_COLORS + 1 );
    ok( brush != 0, "CreateDIBPatternBrushPt failed\n" );
    DeleteObject( brush );
    brush = CreateDIBPatternBrushPt( info, DIB_PAL_COLORS + 2 );
    ok( !brush, "CreateDIBPatternBrushPt succeeded\n" );
    brush = CreateDIBPatternBrushPt( info, DIB_PAL_COLORS + 3 );
    ok( !brush, "CreateDIBPatternBrushPt succeeded\n" );

    info->bmiHeader.biBitCount = 8;
    info->bmiHeader.biCompression = BI_RLE8;
    brush = CreateDIBPatternBrushPt( info, DIB_RGB_COLORS );
    ok( !brush, "CreateDIBPatternBrushPt succeeded\n" );

    info->bmiHeader.biBitCount = 4;
    info->bmiHeader.biCompression = BI_RLE4;
    brush = CreateDIBPatternBrushPt( info, DIB_RGB_COLORS );
    ok( !brush, "CreateDIBPatternBrushPt succeeded\n" );

    br.lbStyle = BS_DIBPATTERN8X8;
    br.lbColor = DIB_RGB_COLORS;
    br.lbHatch = (ULONG_PTR)mem;
    brush = CreateBrushIndirect( &br );
    ok( !brush, "CreatePatternBrush succeeded\n" );

    br.lbStyle = BS_MONOPATTERN;
    br.lbColor = DIB_RGB_COLORS;
    br.lbHatch = (ULONG_PTR)mem;
    brush = CreateBrushIndirect( &br );
    ok( !brush, "CreatePatternBrush succeeded\n" );

    br.lbStyle = BS_INDEXED;
    br.lbColor = DIB_RGB_COLORS;
    br.lbHatch = (ULONG_PTR)mem;
    brush = CreateBrushIndirect( &br );
    ok( !brush, "CreatePatternBrush succeeded\n" );

    GlobalFree( mem );
}
Пример #8
0
int LightOPCServer::send_callback(LightOPCGroup *grp, 
                                  unsigned group_key, loUpdList *upl, int advmask)
{
 int tr = 0;
 IOPCDataCallback *c_databack = 0;
 IAdviseSink *c_datatime = 0,
             *c_dataonly = 0,
             *c_writecomp = 0;
 unsigned cform_dtime, cform_donly, cform_wrcompl;
 OPCHANDLE client_handle;

// UL_DEBUG((LOGID, "send_notify(){..."));
 if (!upl->used)
   {
    if (!upl->trqid) return 0;
    if (S_OK == upl->master_err) upl->master_err = S_FALSE;
   }

 if (FAILED(upl->master_err)) upl->master_qual = S_FALSE;

 if (!grp)
   {
    lock_read();
    if (0 == (grp = by_handle_g(group_key)))
      {
       unlock();
       UL_INFO((LOGID, "send_callback(%x) FAILED: No such group"));
       return 0;
      }
   }
#if LO_USE_BOTHMODEL && 0
 else group_key = grp->ServerHandle;
#endif
 client_handle = grp->ClientHandle;

/* There is only client_sched() thread allowed to change connection info under read_lock ! */
 if ((advmask & loRQ_CONN_DATABACK) && grp->conn_databack)
   loGET_IFACE(c_databack, grp->conn_databack, IOPCDataCallback, grp->initphase);

 if (advmask & (loRQ_CONN_DATA_1 | loRQ_CONN_WRITECOMPL))
   {
    if ((advmask & loRQ_CONN_DATATIME) && grp->conn_datatime)
      {
       cform_dtime = se->cform_datatime;
       loGET_IFACE(c_datatime, grp->conn_datatime, IAdviseSink, grp->initphase);
/* ?? advise_present &= ~loRQ_CONN_DATATIME */
      }

    if ((advmask & loRQ_CONN_DATAONLY) && grp->conn_dataonly)
      {
       cform_donly = se->cform_dataonly;
       loGET_IFACE(c_dataonly, grp->conn_dataonly, IAdviseSink, grp->initphase);
/* ?? advise_present &= ~loRQ_CONN_DATAONLY */
      }

    if ((advmask & loRQ_CONN_WRITECOMPL) && grp->conn_writecompl)
      {
       cform_wrcompl = se->cform_writecompl;
       loGET_IFACE(c_writecomp, grp->conn_writecompl, IAdviseSink, grp->initphase);
/* ?? advise_present &= ~loRQ_CONN_WRITECOMPL */
      }
   }

 unlock();

// UL_DEBUG((LOGID, "send_notify() #3"));
 if (c_databack)
   {
    HRESULT hr = E_INVALIDARG;

    switch(advmask & loRQ_OPER_MASK)
      {
    case loRQ_OP_REFRESH:
       hr = c_databack->OnDataChange(upl->trqid, client_handle,
            upl->master_err, upl->master_qual, upl->used, upl->opchandle,
            upl->variant, upl->quality, upl->timestamp, upl->errors);
       break;
    case loRQ_OP_READ:
       hr = c_databack->OnReadComplete(upl->transaction_id, client_handle,
            upl->master_err, upl->master_qual, upl->used, upl->opchandle,
            upl->variant, upl->quality, upl->timestamp, upl->errors);
       break;
    case loRQ_OP_WRITE:
       hr = c_databack->OnWriteComplete(upl->transaction_id, client_handle,
            upl->master_err, upl->used, upl->opchandle, upl->errors);
       break;
    case loRQ_OP_CANCEL:
       hr = c_databack->OnCancelComplete(upl->transaction_id, client_handle);
       break;
      }
    c_databack->Release();
    if (S_OK == hr) 
      {
       tr++;
       UL_DEBUG((LOGID, "OnDataChange2(0x%X) Ok", advmask));
      }
    else
      {
       UL_WARNING((LOGID, "%!l OnDataChange2(0x%X) FAILED", hr, advmask));
      }
//    UL_WARNING((LOGID, "OnDataChange() 2 Ok"));
   }

 if (advmask & loRQ_CONN_DATA_1)
   {
    HGLOBAL gmem = 0;
    unsigned datasize = 0;

    if (c_datatime)
      {
//       UL_DEBUG((LOGID, "OnDataChange1() with time"));
       if (0 <= lo_OnDataChange1(upl, client_handle, cform_dtime,
                                1, c_datatime, &gmem, &datasize)) tr++;
       c_datatime->Release();
      }
    if (c_dataonly)
      {
//       UL_DEBUG((LOGID, "OnDataChange1() without time"));
       if (0 <= lo_OnDataChange1(upl, client_handle, cform_donly,
                                0, c_dataonly, &gmem, &datasize)) tr++;
       c_dataonly->Release();
      }

    if (gmem && (// && (!GlobalSize(gmem) ||*/ GlobalFree(gmem)))
      //(GlobalFlags(gmem) & (GMEM_INVALID_HANDLE | GMEM_DISCARDED)) || 
        GlobalFree(gmem) ) )
      {
       UL_WARNING((LOGID, "%!L GlobalFree(%X) FAILED flags=0x%X", 
                           gmem, GlobalFlags(gmem)));       
      }
   }
 else if (c_writecomp)
   {
//    UL_DEBUG((LOGID, "OnWriteComplete1()"));
    if (0 <= lo_OnWriteComplete1(upl, client_handle, cform_wrcompl,
                                 c_writecomp, 0)) tr++;
    c_writecomp->Release();
   }

// UL_DEBUG((LOGID, "send_datachange() finished}"));
 return tr;
}
Пример #9
0
DWORD
main(
    int argc,
    char *argv[],
    char *envp[]
    )
{
    NTSTATUS Status;
    LPVOID p1, p2, p3, p4, p5, p6;
    HANDLE h1, h2, h3, h4, h5, h6;
    BOOL result;
    LPDWORD p;

    printf( "TMEM: Entering Test Program\n" );

    p1 = LocalAlloc( LMEM_ZEROINIT, 0 );
    printf( "LocalAlloc( 0 ) == %lX\n", p1 );
    printf( "LocalSize( %lX ) == %ld\n", p1, LocalSize( p1 ) );

    p2 = LocalReAlloc( p1, 23, 0 );
    printf( "LocalReAlloc( %lX, 23 ) == %lX\n", p1, p2 );
    printf( "LocalSize( %lX ) == %ld\n", p2, LocalSize( p2 ) );
    printf( "LocalFree( %lX ) == %ld\n", p2, LocalFree( p2 ) );

    p1 = LocalAlloc( LMEM_ZEROINIT, 123 );
    printf( "LocalAlloc( 123 ) == %lX\n", p1 );
    printf( "LocalSize( %lX ) == %ld\n", p1, LocalSize( p1 ) );

    p2 = LocalReAlloc( p1, 23, 0 );
    printf( "LocalReAlloc( %lX, 23 ) == %lX\n", p1, p2 );
    printf( "LocalSize( %lX ) == %ld\n", p2, LocalSize( p2 ) );

    p3 = LocalReAlloc( p2, 223, LMEM_ZEROINIT );
    printf( "LocalReAlloc( %lX, 223 ) == %lX\n", p2, p3 );
    printf( "LocalSize( %lX ) == %ld\n", p3, LocalSize( p3 ) );

    p4 = LocalReAlloc( p3, 22, 0 );
    printf( "LocalReAlloc( %lX, 22 ) == %lX\n", p3, p4 );
    printf( "LocalSize( %lX ) == %ld\n", p4, LocalSize( p4 ) );
    printf( "LocalFree( %lX ) == %ld\n", p4, LocalFree( p4 ) );

    h1 = LocalAlloc( LMEM_MOVEABLE | LMEM_ZEROINIT, 123 );
    printf( "LocalAlloc( MOVEABLE, 123 ) == %lX (-> %lX)\n", h1, LocalLock( h1 ) );
    printf( "LocalSize( %lX ) == %ld\n", h1, LocalSize( h1 ) );

    h2 = LocalReAlloc( h1, 23, 0 );
    printf( "LocalReAlloc( %lX, 23 ) == %lX\n", h1, h2, LocalLock( h2 ) );
    printf( "LocalSize( %lX ) == %ld\n", h2, LocalSize( h2 ) );

    h3 = LocalReAlloc( h2, 223, LMEM_ZEROINIT );
    printf( "LocalReAlloc( %lX, 223 ) == %lX\n", h2, h3, LocalLock( h3 ) );
    printf( "LocalSize( %lX ) == %ld\n", h3, LocalSize( h3 ) );

    h4 = LocalReAlloc( h3, 22, 0 );
    printf( "LocalReAlloc( %lX, 22 ) == %lX\n", h3, h4, LocalLock( h4 ) );
    printf( "LocalSize( %lX ) == %ld\n", h4, LocalSize( h4 ) );
    printf( "LocalFree( %lX ) == %ld\n", h4, LocalFree( h4 ) );


    h1 = GlobalAlloc( GMEM_ZEROINIT, 123 );
    printf( "GlobalAlloc( 123 ) == %lX\n", h1 );
    printf( "GlobalFlags( %lX ) == %ld\n", h1, GlobalFlags( h1 ) );
    printf( "GlobalSize( %lX ) == %ld\n", h1, GlobalSize( h1 ) );

    h2 = GlobalReAlloc( h1, 23, 0 );
    printf( "GlobalReAlloc( %lX, 23 ) == %lX\n", h1, h2 );
    printf( "GlobalSize( %lX ) == %ld\n", h2, GlobalSize( h2 ) );

    h3 = GlobalReAlloc( h2, 223, GMEM_ZEROINIT );
    printf( "GlobalReAlloc( %lX, 223 ) == %lX\n", h2, h3 );
    printf( "GlobalSize( %lX ) == %ld\n", h3, GlobalSize( h3 ) );

    h4 = GlobalReAlloc( h3, 22, 0 );
    printf( "GlobalReAlloc( %lX, 22 ) == %lX\n", h3, h4 );
    printf( "GlobalSize( %lX ) == %ld\n", h4, GlobalSize( h4 ) );
    printf( "GlobalFree( %lX ) == %ld\n", h4, GlobalFree( h4 ) );

    h1 = GlobalAlloc( GMEM_ZEROINIT, 12003 );
    printf( "GlobalAlloc( 123 ) == %lX\n", h1 );
    printf( "GlobalFlags( %lX ) == %ld\n", h1, GlobalFlags( h1 ) );
    printf( "GlobalSize( %lX ) == %ld\n", h1, GlobalSize( h1 ) );

    h2 = GlobalReAlloc( h1, 4000, 0 );
    printf( "GlobalReAlloc( %lX, 23 ) == %lX\n", h1, h2 );
    printf( "GlobalSize( %lX ) == %ld\n", h2, GlobalSize( h2 ) );

    h3 = GlobalReAlloc( h2, 8000, GMEM_ZEROINIT );
    printf( "GlobalReAlloc( %lX, 223 ) == %lX\n", h2, h3 );
    printf( "GlobalSize( %lX ) == %ld\n", h3, GlobalSize( h3 ) );

    h4 = GlobalReAlloc( h3, 22, 0 );
    printf( "GlobalReAlloc( %lX, 22 ) == %lX\n", h3, h4 );
    printf( "GlobalSize( %lX ) == %ld\n", h4, GlobalSize( h4 ) );
    printf( "GlobalFree( %lX ) == %ld\n", h4, GlobalFree( h4 ) );

    DbgBreakPoint();

    h1 = GlobalAlloc( GMEM_DDESHARE, 123 );
    printf( "GlobalAlloc( 123 ) == %lX\n", h1 );
    printf( "GlobalFlags( %lX ) == %ld\n", h1, GlobalFlags( h1 ) );
    printf( "GlobalSize( %lX ) == %ld\n", h1, GlobalSize( h1 ) );

    p = GlobalLock( h1 );
    if (*p != 0xABCDEF01) {
        DbgBreakPoint();
        }

    h2 = GlobalReAlloc( h1, 23, 0 );
    printf( "GlobalReAlloc( %lX, 23 ) == %lX\n", h1, h2 );
    printf( "GlobalSize( %lX ) == %ld\n", h2, GlobalSize( h2 ) );

    h3 = GlobalReAlloc( h2, 223, GMEM_ZEROINIT );
    printf( "GlobalReAlloc( %lX, 223 ) == %lX\n", h2, h3 );
    printf( "GlobalSize( %lX ) == %ld\n", h3, GlobalSize( h3 ) );

    h4 = GlobalReAlloc( h3, 22, 0 );
    printf( "GlobalReAlloc( %lX, 22 ) == %lX\n", h3, h4 );
    printf( "GlobalSize( %lX ) == %ld\n", h4, GlobalSize( h4 ) );
    printf( "GlobalFree( %lX ) == %ld\n", h4, GlobalFree( h4 ) );

    printf( "TMEM: Exiting Test Program\n" );

    return 0;
}
Пример #10
0
/* %%Function:FIdle %%Owner:PETERJ */
FIdle()
{ /* Idle routine -- executes in the background when no messages are waiting */
	/* Returns fTrue iff there is a message in the queue on return */

	/* WARNING: in Preview mode, we skip everything except:
				Enable AwfulNoise
				OnTime Macro
				Updating Menus
				Initializing SDM
				Autosave
				Debug Checks
		Due to the special nature of the font cache while in preview, we cannot
		do FormatLines except while in the preview code!
	*/
	extern int vfDeactByOtherApp;
	extern int vlm;
	extern HWND vhwndRibbon;
	extern HWND vhwndStatLine;
	struct RPL rpl;
	struct LBS lbsText, lbsFtn;
	int ww;
	int wwHdr = wwNil;
	int docCur = PselActive()->doc;
	static int cPassUninterrupt = 0;
#define cPassOne    5
#define cPassTwo    20

#ifdef DEBUG
	int iGotoLRet = -1;
#endif /* DEBUG */

	Assert(vidf.fInIdle == 0);
	vidf.fInIdle = fTrue;

#ifdef RSH
	RestartUatTimer();
	CheckUat();
#endif /* RSH */

	Assert(vpvs.lmSave != lmPreview);
#ifdef BATCH
	/* If vfBatchIdle is true, allow idle-ing in batch mode */
	if (vfBatchMode && !vfBatchIdle)
		BatchModeError(SzShared("Idle entered!"), NULL, 0, 0);
#endif /* BATCH */

/* if free heap space has changed, dump the new cbFree to the comm port */
	Debug (vdbs.fReportHeap ? ReportHeapSz (SzShared("memory usage "), 1) : 0);
	Debug (vdbs.fHeapAct||vdbs.fWinAct ? ReportFailCalls() : 0);

#ifdef DEBUG
/* show each pass through idle */
		{
		static int cIdlePasses = 0;

		Scribble (ispIdle1, 'I'); /* indicate in idle */
		Scribble (ispIdle2, '0'+cIdlePasses);
		cIdlePasses = (cIdlePasses + 1) % 10;
		}

	if (vdbs.fShowDirty)
		ScribbleDirty(DocMother(selCur.doc));
#endif  /* DEBUG */

	Assert( cHpFreeze == 0 );
	Debug( cHpFreeze = 0 );
	Assert( vfInsertMode || cpInsert == cpNil );
	Assert(vcPreload == 0 && vfnPreload == fnNil);

	ClearInputState();

	if (vidf.fInvalSeqLev)
		{
		InvalSeqLevFields();
		Assert(!vidf.fInvalSeqLev);
		}

/* Re-enable beep, disk full alert, memory alert, other alerts */
	vfAwfulNoise = fFalse;

	if (vlm == lmPreview)
		goto LPrvw1;

/* Reset the cound of consecutive scrolls. */
	if (vcConseqScroll != 0 &&
			GetKeyState(VK_UP) >= 0 && GetKeyState(VK_DOWN) >= 0 &&
			GetKeyState(VK_LBUTTON) >= 0 && GetKeyState(VK_RBUTTON) >= 0)
		{
		vcConseqScroll = 0;
		}

	Assert(vlm != lmPreview);
/* Update all document windows */
	UpdateAllWws( fTrue );

	Debug (iGotoLRet = 0);
	if (FMsgPresent(mtyIdle & ~mtyMouseMove))
		goto LRet;

/* scroll active cp of selection into view */
	if (vfSeeSel && hwwdCur != hNil)
		SeeSel();
	vfSeeSel = fFalse;

	Debug (iGotoLRet = 1);
	if (FMsgPresent(mtyIdle))
		goto LRet;

	Assert(vlm != lmPreview);
/* turn on selection highlight */
	if (!vfDeactByOtherApp)
		{
		if (!selCur.fNil && selCur.fHidden)
			TurnOnSelCur();
		if (!selDotted.fNil && selDotted.fHidden)
			TurnOnSel(&selDotted);
		}

	Debug (iGotoLRet = 2);
	if (FMsgPresent(mtyIdle))
		goto LRet;

	Assert(vlm != lmPreview);

/* make sure we have our full swap area (or reduce if we have used up memory) */
	if (!(cPassUninterrupt+1 & 0x00ff))
		{
#ifdef DEBUG
		if (vcShrinkSwapArea != 0)
			ReportSz("vcShringSwapArea non zero at idle");
#endif /* DEBUG */
		vcShrinkSwapArea = 0;
		OurSetSas(sasFull);
		}

/* bring in our core (wait until now so screen is up to date & we don't
	postpone our responsiveness) */
	if (cPassUninterrupt > cPassOne)
		CoreNewest (cPassUninterrupt >= cPassTwo/*fLoad*/);

	Debug (iGotoLRet = 3);
	if (FMsgPresent(mtyIdle))
		goto LRet;

/* update ruler */
	if (hmwdCur != hNil && (*hmwdCur)->hwndRuler != hNil)
		if (selCur.fUpdatePap || selCur.fUpdateRuler)
			UpdateRuler(hmwdCur, fFalse /*!fInit*/, -1/*rk*/, fTrue /*fAbortOK*/);

	Debug (iGotoLRet = 4);
	if (FMsgPresent(mtyIdle))
		goto LRet;

	Assert(vlm != lmPreview);
/* update outline iconbar if in outline. */
	if (hwwdCur != hNil && (*hwwdCur)->fOutline)
		{
		UpdateOutlineIconBar();
		}

	Debug (iGotoLRet = 5);
	if (FMsgPresent(mtyIdle))
		goto LRet;

/* Update the beautification of edited text in the various macro windows */
	if (vhmes != hNil)
		{
		uns imei;
		uns imeiMax;
		MEI * pmei;
		MES * pmes;
		struct CA ca;

		pmes = *vhmes;
		pmei = &pmes->rgmei[0];
		imeiMax = pmes->imeiMax;
		for (imei = 0; imei < imeiMax; ++imei, ++pmei)
			/* okay to ignore expansion failure 
				as beauty is at stake */
			if (pmei->fNotExpanded && !DiDirtyDoc(pmei->docEdit))
				{
				if (FExpandHqrgbToPca(pmei->hqrgbTokens, 
						pmei->cbTokens, 
						PcaSetWholeDoc(&ca,pmei->docEdit),imei,fTrue))
					PmeiImei(imei)->fNotExpanded = fFalse;
				pmei = PmeiImei(imei);
				}
		}

/* Update Start/Continue button on macro icon bar */
	{
	MEI * pmei;
	
	if (vhmes != hNil && (pmei = PmeiCur())->heli != hNil && 
			PdodDoc(pmei->docEdit)->fDirty)
		{
		FreeEditMacro(iNil);
		}
	}

	Debug (iGotoLRet = 6);
	if (FMsgPresent(mtyIdle))
		goto LRet;

/* notice editing in header pane, enable "link with prev/reset" button if 
	it is not the first section's header/footer */
/* Why is this not done at NewCurWw time? - because you don't know when it 
is dirtied */
	if (wwCur != wwNil && PwwdWw(wwCur)->wk == wkHdr && 
			PdodDoc(docCur)->fDirty)
		{
		Assert(PdodDoc(docCur)->fDispHdr);
		if (FCanLinkPrev(wwCur))
			{
			SetSameAsPrevCtl(wwCur, fTrue /*fEnable*/);
			}
		}

	Assert(vlm != lmPreview);
/* update ribbon */
	if (vhwndRibbon != NULL)
		if (selCur.fUpdateChp || selCur.fUpdateChpGray ||
				selCur.fUpdateRibbon)
			UpdateRibbon(fFalse);

	Debug (iGotoLRet = 7);
	if (FMsgPresent(mtyIdle))
		goto LRet;

	Assert(vlm != lmPreview);

/* update header window's iconbar text */
	if (vdocHdrEdit != docNil)
		{
		int docHdrDisp = docNil;
		int docMom = vdocHdrEdit; /* saved away because vdocHdrEdit may
		be reset to zero */
		while ((wwHdr = WwHdrFromDocMom(docMom, &docHdrDisp)) != wwNil)
			{
			Assert(docHdrDisp);
			if (PwwdWw(wwHdr)->fHdr)
				SetHdrIBarName(docHdrDisp, IhtstFromDoc(docHdrDisp), wwHdr);
			}
		}

	Debug (iGotoLRet = 8);
	if (FMsgPresent(mtyIdle))
		goto LRet;

	Assert(vlm != lmPreview);

/* perform background DDE processes, if any */
	if (vfDdeIdle)
		{
		DoDdeIdle ();
		}

	Debug (iGotoLRet = 9);
	if (FMsgPresent(mtyIdle))
		goto LRet;

	/* WwCur enhancement for pictures. If window was dirtied and there
		are lines with pictures whose display was postponed, do the
		full display now. Other windows done later.
	
		Can use this loop for gray-scale fonts too.
	
	*/

	Assert(vlm != lmPreview);
	if (hwwdCur != hNil && (*hwwdCur)->fNeedEnhance)   /* wwCur first */
		{
		UpdateWw(wwCur, fTrue /* fAbortOK */); /* be sure window is up to date first */
		if (FEnhanceWw(wwCur))
			(*hwwdCur)->fNeedEnhance = fFalse;
		else  /* false if interrupted */				
			{
			Debug (iGotoLRet = 10);
			goto LRet;
			}
		}

	Debug (iGotoLRet = 11);
	if (FMsgPresent(mtyIdle))
		goto LRet;

/* Update the status line */
	if (vhwndStatLine != NULL && 
			(selCur.fUpdateStatLine || selCur.fUpdateStatLine2))
		UpdateStatusLine(usoCache);
	Debug (iGotoLRet = 12);
	if (FMsgPresent(mtyIdle))
		goto LRet;

/* preload font, if changed, to avoid delay when typing commences */
	if (vrf.fPreloadSelFont)
		{
		vrf.fPreloadSelFont = fFalse;
		if (selCur.fIns && hwwdCur != hNil &&
				DocMother(vfli.doc) == DocMother(selCur.doc))
	/* one case where vfli.doc not equal to selCur.doc is we are stepping
	through macro statement in an active window.  vfli.doc may point to the
	macro doc because we just hilighted the macro statement but selCur.doc
	is the active doc that the macro is executing on.
*/
			{
#ifdef BRYANL
			CommSz( SzShared( "Preloading font!!\r\n") );
#endif
			SetFlm( (*hwwdCur)->grpfvisi.flm );
			LoadFont( &selCur.chp, fFalse /*fWidthsOnly*/ );
			}
		}
	Debug (iGotoLRet = 12);
	if (FMsgPresent(mtyIdle))
		goto LRet;

LPrvw1:

/* Check for OnTime macro */
	if (vhotd != hNil)
		{
		extern unsigned long LTimeCur();
		OTD * potd;
		unsigned long lTime;

		lTime = LTimeCur();
		potd = *vhotd;
		if (lTime >= potd->lTime && 
				lTime < potd->lTime + potd->lTolerance)
			{
			extern BOOL vfAbortInsert;

			if (vfInsertMode)
				{
LAbortInsert:
				Assert(vfInsertMode); /* protect the label */
				/* Have to run next time in idle... */
				vfAbortInsert = fTrue;

				/* need to idle again ASAP! */
				Scribble (ispIdleComplete, 'M'); /* successful idle  */
				Scribble (ispIdle1, ' '); /* no longer in idle */
				cPassUninterrupt++;
				vidf.fInIdle = fFalse;
				return fFalse;
				}
			else
				{
				char stMacro [cchMaxSt];

				CopySt(potd->stMacro, stMacro);
				FreePh(&vhotd);
				FRunMacro(stMacro);
				}
			}
		}


	Debug (iGotoLRet = 13);
	if (FMsgPresent(mtyIdle))
		goto LRet;

/* make sure all the menus are up to date */
	if ((vgrfMenuCmdsAreDirty || vgrfMenuKeysAreDirty) && 
			cPassUninterrupt > cPassTwo)
		BringMenusUpToDate();

	Debug (iGotoLRet = 14);
	if (FMsgPresent(mtyIdle))
		goto LRet;

	if (cPassUninterrupt > cPassTwo+1 && 
			(!vmerr.fSdmInit||vpvs.fLoadPrvwFon))
		{
		FAbortNewestCmg(cmgInitStuff, fFalse, fTrue);
/* init SDM if we haven't already */
		if (!vmerr.fSdmInit)
			FAssureSdmInit();
		Debug (iGotoLRet = 15);
		if (FMsgPresent(mtyIdle))
			goto LRet;
/* Add preview font to master font table */
		if (vpvs.fLoadPrvwFon)
			LoadPreviewFont();
		OldestCmg(cmgInitStuff);
		}


	Debug (iGotoLRet = 16);
	if (FMsgPresent(mtyIdle))
		goto LRet;

	if (vlm == lmPreview)
		goto LPrvw2;

/* perform background repagination */
	if (selCur.doc != docNil && cPassUninterrupt >= cPassOne)
		{
		if (vpref.fBkgrndPag && !vpref.fDraftView 
				&& PwwdWw(wwCur)->wk != wkMacro)
			{
			int docMother = DocMother(selCur.doc);
			int lmSave = vlm;
			int flmSave = vflm;

			if (FInitWwLbsForRepag(wwCur, docMother, lmBRepag, &lbsText, &lbsFtn))
				{
				int fAbort, ipgdMacOld;

				SetWords(&rpl, pgnMax, cwRPL);
				rpl.cp = cpMax;
				ipgdMacOld = IMacPlc(PdodDoc(docMother)->hplcpgd);
				fAbort = !FUpdateHplcpgd(wwTemp, docMother, &lbsText, &lbsFtn, &rpl, patSilent );
				EndFliLayout(lmSave, flmSave);
				EndLayout(&lbsText, &lbsFtn);
				Debug (iGotoLRet = 17);
				if (fAbort)
					goto LRet;
				if (vhwndStatLine && ipgdMacOld !=
						IMacPlc(PdodDoc(docMother)->hplcpgd))
					UpdateStatusLine(usoCache);
				}
			}

		Debug (iGotoLRet = 18);
		if (FMsgPresent(mtyIdle))
			goto LRet;

		CoreNewest(fFalse);
		}


	Debug (iGotoLRet = 19);
	if (FMsgPresent(mtyIdle))
		goto LRet;

/* Get rid of the monster printer DC if we can live without it */
	if (vpri.hdc)
		{
		SetFlm( flmTossPrinter );
		Debug(hdcPrint = NULL);
		}

	Debug (iGotoLRet = 20);
	if (FMsgPresent(mtyIdle))
		goto LRet;

/* To improve global memory conditions, unlock any locked bitmaps */
	if (vsci.hdcScratch)
		SetScratchPbmi( &vbmiEmpty );

/* Shrink heap blocks for FormatLine.  Call this when it's
possible that the contents of the screen have gotten less complex */
	Assert(vbchrMax >= bchrMaxInit);
	if (vbchrMax - vbchrMac > bchrMaxFree)
		{
		vbchrMax = max(bchrMaxInit,vbchrMac);
		FChngSizeHCw(vhgrpchr, CwFromCch(vbchrMax + cbCHRE), fTrue);
		}

/* inside ruler functions the ruler grpprl is never shrunk.  This
	checks to see if it is bigger then it needs to be & shrinks it */
	if (vrulss.hgrpprl != hNil)
		CheckRulerGrpprlSize ();

	Assert (vdocTemp == docNil || mpdochdod[vdocTemp] != hNil);
	Assert (vdocScratch == docNil || mpdochdod[vdocScratch] != hNil);

	Assert(vlm != lmPreview);

	Debug (iGotoLRet = 21);
	if (FMsgPresent(mtyIdle))
		goto LRet;

/* delete vdocScratch here to free heap */
	if (vdocScratch != docNil)
		{
#ifdef DEBUG
		extern BOOL fDocScratchInUse;
		Assert (!fDocScratchInUse);
#endif /* DEBUG */
		DisposeDoc (vdocScratch);
		/* vdocScratch = docNil; */
		}
	if (vdocTemp != docNil && CpMacDocEdit(vdocTemp) > cp0)
		{
		struct CA caT;
		PdodDoc(vdocTemp)->doc = docScrap;   /* ensure valid chain */
		FDelete(PcaSetWholeDoc(&caT, vdocTemp));
		}

LPrvw2:
	Debug (iGotoLRet = 22);
	if (FMsgPresent(mtyIdle))
		goto LRet;

/* check to see if autosave should be done.  If so, do it. */
	Assert(GetTickCount() > 0L);
	if (vpref.iAS == iASNever || mwMac == 0 || !FAnyDirtyDocs())
		ResetASBase();
	else if (cPassUninterrupt > cPassTwo && FDoAutoSave())
		{
		if (vfInsertMode)
			/* must exit insert mode before we can save */
			goto LAbortInsert;
		else
			CmdAutosave();
		}

	Debug (iGotoLRet = 23);
	if (FMsgPresent(mtyIdle))
		goto LRet;

	/* check for discardable cursors */
	if (vhcOtlCross)
		{
		int ww;
		for (ww = 0; ww < wwMac; ww++)
			if (mpwwhwwd[ww] != hNil && PwwdWw(ww)->fOutline)
				break;
		if (ww == wwMac)
			/* no one in outline mode, discard outline cursors */
			{
			FreeIrcds(ircdsOtlCross);
			FreeIrcds(ircdsOtlVert);
			FreeIrcds(ircdsOtlHorz);
			}
		}
	if (vhcPrvwCross && vlm != lmPreview)
		FreeIrcds(ircdsPrvwCross);

	Assert(!vhcHelp == !vfHelp);

	Debug (iGotoLRet = 24);
	if (FMsgPresent(mtyIdle))
		goto LRet;

	if (vlm == lmPreview)
		goto LPrvw3;

	if (cPassUninterrupt > cPassTwo && selCur.doc != docNil)
		/* load pieces of selCur.doc into file cache */
		{
		int doc = DocMother(selCur.doc);
		int fn = PdodDoc(doc)->fn;
		CP ccpScan = CpMin((vbptbExt.ibpMac / 4) * cbSector, 
				CpMacDoc(doc));
		CP cpCur = doc != selCur.doc ? cp0 :
				CpMax(cp0, selCur.cpFirst - (ccpScan/3));
		if (fn != fnNil)
			EnablePreload(fn);
		while (ccpScan > cp0 && cpCur < CpMacDoc(doc) && 
				!FMsgPresent(mtyIdle))
			{
			CachePara(doc, cpCur);
			FetchCp(doc, cpCur, fcmProps+fcmChars);
			cpCur += vccpFetch;
			ccpScan -= vccpFetch;
			}
		if (fn != fnNil)
			DisablePreload();
		}

	Debug (iGotoLRet = 25);
	if (FMsgPresent(mtyIdle))
		goto LRet;

	/* GlobalWire the current font (leaves it unselected) 
		(DavidW says DON'T try to access the bits under win3) */
 	if (vwWinVersion < 0x0300)
		{
		int f;
		HFONT hfont;
		HANDLE hfontPhy;
		HDC hdc;

		if (vsci.pfti != NULL && (hfont = vsci.pfti->hfont) != NULL && 
				hwwdCur != hNil && (hdc = (*hwwdCur)->hdc) != NULL)
			{
			hfontPhy = GetPhysicalFontHandle(hdc);

			ResetFont(fFalse);

			if (((f = GlobalFlags(hfontPhy)) & GMEM_LOCKCOUNT) == 0 &&
					(f & ~GMEM_LOCKCOUNT) != 0)
				{
				Scribble(ispWireFont, 'W');
				/* Make the block non-discardable so that
				   windows won't throw out the block when
				   making room to GlobalWire it. */
				Assert(f & GMEM_DISCARDABLE);
				if (f & GMEM_DISCARDABLE)
					GlobalReAlloc(hfontPhy, GlobalSize(hfontPhy),
						GMEM_MODIFY);
				GlobalWire(hfontPhy);
				if (f & GMEM_DISCARDABLE)
					GlobalReAlloc(hfontPhy, GlobalSize(hfontPhy),
						GMEM_MODIFY | GMEM_DISCARDABLE);
				GlobalUnlock(hfontPhy);
				}
			}
		}

	/*  make sure temp files used (especially TIFF files, etc) won't cause
		us to run out of fns. */
	if (fnMac > fnMax-5 && cPassUninterrupt > cPassTwo)
		KillExtraFns();

	Debug (iGotoLRet = 26);
	if (FMsgPresent(mtyIdle))
		goto LRet;

	/* Enhancement loop for pictures. If window was dirtied and there
		are lines with pictures whose display was postponed, do the
		full display now.
	
		Did wwCur above before background repag; should not now be dirty 
		Can use this loop for gray-scale fonts too.
	
	*/

	Assert(vlm != lmPreview);

	if (cPassUninterrupt > cPassOne)
		{
		if (hwwdCur != hNil && (*hwwdCur)->fNeedEnhance && (*hwwdCur)->fDirty)
			UpdateWw(wwCur, fTrue /* fAbortOK */);

		for (ww = wwDocMin; ww < wwMac; ++ww)
			{
			struct WWD **hwwd;
			if (((hwwd = mpwwhwwd[ww]) != hNil) && (*hwwd)->fNeedEnhance)
				{
				if (FEnhanceWw(ww))
					(*hwwd)->fNeedEnhance = fFalse;
				else  /* false if interrupted */							
					{
					Debug (iGotoLRet = 27);
					goto LRet;
					}

				}
			}
		}

LPrvw3:
	Debug (iGotoLRet = 28);
	if (FMsgPresent(mtyIdle))
		goto LRet;

/* debugging checks */
#ifdef DEBUG
/* Check to see if the toolbox has been trashed */
	Debug(vdbs.fCkTlbx ? CkTlbx(fFalse) : 0 );

/* following Asserts try to catch storing into NULL pointers */
	Assert( *((char *) 0) == 0 );
	Assert( *((char *) 2) == 0 );
	Assert( *((char *) 8) == 0 );

	if (cPassUninterrupt > cPassOne)
		DoDebugTests(fTrue);
#endif  /* DEBUG */

	Debug (iGotoLRet = 29);
	if (FMsgPresent(mtyIdle))
		goto LRet;

	if (vlm == lmPreview)
		goto LPrvw4;

/* quietly load each of the code segments we use */
	if (!(cPassUninterrupt+1 & 0x0007))
		GetNextHcd();

	Debug (iGotoLRet = 30);
	if (FMsgPresent(mtyIdle))
		goto LRet;

/* make sure our core is loaded in */
	CoreNewest (fFalse);

LPrvw4:
	Scribble (ispIdleComplete, '*'); /* successful idle  */
	Scribble (ispIdle1, ' '); /* no longer in idle */
	cPassUninterrupt++;
	vidf.fInIdle = fFalse;
	return fFalse;

LRet:   /* Idle was interrupted by the arrival of an interesting message */

/* show each interrupted pass through idle with indicator of how far through */
	Scribble (ispIdleComplete, 'a'+iGotoLRet);
	Scribble (ispIdle1, ' '); /* no longer in idle */
	cPassUninterrupt = 0;
	vidf.fInIdle = fFalse;
	return fTrue;
}