void TAppDictionary::FreeTable(TAppDictionaryEntry *pTable)
{
    HANDLE hMem =
#ifdef STRICT	
	    LocalHandle((void NEAR*)FP_OFF(pTable));
#else
	    LocalHandle(FP_OFF(pTable));
#endif
    if (LocalUnlock(hMem))
        LocalFree(hMem);
}
Пример #2
0
static BOOL GetDeviceRegistryProperty( HDEVINFO hDevInfo, PSP_DEVINFO_DATA pDeviceInfoData, DWORD dwProperty, CString& strProperty )
{
    BOOL bRet = TRUE;
    DWORD dwDataType = 0;
    LPTSTR pszBuf = NULL;
    DWORD dwBuffersize = 0;

    while ( !SetupDiGetDeviceRegistryProperty( hDevInfo, pDeviceInfoData, dwProperty, &dwDataType, ( PBYTE )pszBuf, dwBuffersize, &dwBuffersize ) )
    {
        if ( ERROR_INVALID_DATA == GetLastError() )
        {
            // 不存在 Device desc
            bRet = FALSE;
            break;
        }
        else if ( ERROR_INSUFFICIENT_BUFFER == GetLastError() )
        {
            // buffer size 不对
            if ( NULL != pszBuf )
            {
                LocalFree( LocalHandle( pszBuf ) );
                pszBuf = NULL;
            }

            pszBuf = ( LPTSTR )LocalAlloc( LPTR, dwBuffersize );
            if ( NULL == pszBuf )
            {
                bRet = FALSE;
                break;
            }
        }
        else
        {
            // 未知错误
            bRet = FALSE;
            break;
        }
    }

    if ( bRet )
    {
        strProperty = pszBuf;
    }

    if ( NULL != pszBuf )
    {
        LocalFree( LocalHandle( pszBuf ) );
        pszBuf = NULL;
    }

    return bRet;
}
Пример #3
0
int 
message(int id)
{
    if (!silent) {
	LPVOID lpMessageBuffer = NULL;
	TCHAR buf[256];
	TCHAR mess[256];
	DWORD error = GetLastError();
	LoadString(phInstance, id, mess, sizeof(mess)/sizeof(TCHAR)-1);
	wsprintf(buf, mess, error);

	if (error)
	    FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
		FORMAT_MESSAGE_FROM_SYSTEM,
		NULL, error, /* user default language */
		MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
		(LPTSTR) &lpMessageBuffer, 0, NULL);
	if (lpMessageBuffer) {
	    lstrcat(buf, "\n");
	    lstrcat(buf, lpMessageBuffer);
	    LocalFree(LocalHandle(lpMessageBuffer));
	}

        MessageBox(HWND_DESKTOP, buf, title, MB_OK);
    }
    return 1; 
}
Пример #4
0
static
VOID
HandleSetHandlePrintHex(HWND handle,DWORD Msg,WPARAM wParam,LPARAM lParam)
    {
      LPVOID pMem;
      HANDLE hNewBuffer;
      int ret;

      LocalFree((HLOCAL)SendMessage(handle, EM_GETHANDLE, 0, 0L));
      if (UnicodeUsed)
          {
            hNewBuffer = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT, 100);
            pMem = LocalLock(hNewBuffer);
            strcpyw_((wchar_t*)pMem,NewTextW);
          }
      else
          {
            hNewBuffer = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT,50);
            pMem = LocalLock(hNewBuffer);
            strcpy_((char*)pMem,NewText);
          }

      LocalUnlock(pMem);
      hNewBuffer = LocalHandle(pMem);

	  /* Updates the buffer and displays new buffer */
      ret =  SendMessage(handle, EM_SETHANDLE, (WPARAM)hNewBuffer, 0L);

      htoa(ret,&TextBuffer[8]);
      PrintTextXY(TextBuffer,ResultX,ResultY,16);
    }
Пример #5
0
/* disconnect from all the sessions that this client asked us to make */
void
ss_cleanconnections(PFNAMELIST connects)
{
        PFNAMELIST server, next;

        for (server = connects; server != NULL; ) {

                WNetCancelConnection2(server->szFile, 0, 0);

                /* free block of memory */
                next = server->next;
                LocalUnlock(LocalHandle( (PSTR) server));
                LocalFree(LocalHandle( (PSTR) server));
                server = next;
        }
        connects = NULL;
} /* ss_cleanconnections */
Пример #6
0
void *
LocalReAllocPtr(void * ptr, UINT flags, UINT size)
{
HLOCAL hlocal;
	hlocal = LocalHandle(ptr);
	LocalUnlock(hlocal);
	hlocal = LocalReAlloc(hlocal, size+1, flags);
	return (char *)LocalLock(hlocal);
}
Пример #7
0
void
LocalFreePtr(void *ptr)
{
HLOCAL hlocal;
	hlocal = LocalHandle(ptr);
	LocalUnlock(hlocal);
	LocalFree(hlocal);
	return;
}
Пример #8
0
void
iC_efree(void *	p)
{
#if defined(_LARGE_) || defined(_HUGE_)
    GLOBALHANDLE		hglobal;

    hglobal = GlobalHandle(p);		/* retrieve the handle */
    GlobalUnlock(hglobal);
    GlobalFree(hglobal);		/* big deal */
#else
    LOCALHANDLE		hlocal;

    hlocal = LocalHandle(p);		/* retrieve the handle */
    LocalUnlock(hlocal);
    LocalFree(hlocal);			/* big deal */
#endif
} /* iC_efree */
Пример #9
0
HANDLE DoLocalHandle(WORD wHeapDS, WORD wMem)
{
    HANDLE hMem ;

_asm {
     push DS
     mov  AX, wHeapDS
     mov  DS, AX
     }

	hMem = LocalHandle(wMem);

_asm {
     pop DS
     }

    return hMem ;
}
Пример #10
0
// --------------------------------------------------------------------------
//
//  UnpatchDDI()
//
//  Unpatches the DDI for the caller
//
// --------------------------------------------------------------------------
BOOL WINAPI
UnpatchDdi(HPATCH hpatch)
{
    if (!LocalHandle((HANDLE)hpatch))
        return(FALSE);

    //
    // Unhook the DDI
    //
    UnhookDDIHook(hpatch->hddi);

    //
    // Post a message to the caller.
    //
    PostThreadMessage32(hpatch->idThread, WM_ENDDDIPATCH, 0, hpatch->cCalls, 0);

    //
    // Free structure
    //
    LocalFree((HANDLE)hpatch);

    return(TRUE);
}
Пример #11
0
void CDECL free (void *block)
{
    HANDLE  hSeg;
    WORD    wSeg;
    SEGHEADER *Seg;
    HANDLE  hBlock;
#if MEMTRACE
    WORD    RealSize = 0;
#endif

    if (FarStorage == FALSE) {  /* use the local heap */
	HANDLE hMem;

	hMem = LocalHandle (LOWORD(block));
	LocalUnlock (hMem);
	LocalFree (hMem);
	return;
    }

    wSeg = HIWORD((DWORD)block);
    hSeg = LOWORD(GlobalHandle (wSeg));

    SWITCH_DS(wSeg)
    LocalUnlock (hBlock = LocalHandle (LOWORD(block)));
#if MEMTRACE
    RealSize = LocalSize (hBlock);
#endif
    LocalFree (hBlock);
    RESTORE_DS

    Seg = (SEGHEADER *)(MAKELONG(SEGHEADOFFSET,HIWORD(block)));
#if MEMTRACE
    mtr[mtrx].m_func = MTR_FREE;
    mtr[mtrx].m_ptr.m_block = block;
    mtr[mtrx].m_cnt = Seg->alloc_count;
    mtr[mtrx].m_size = RealSize;
    mtr[mtrx++].m_optimseg = OptimumSeg;
#endif
    if (--(Seg->alloc_count) == 0) {  /* this segment is no longer used!
					 Let's get rid of it */
        SEGHEADER   *sp;

        if (Seg == OptimumSeg) OptimumSeg = NULL;
        sp = &SegList;
        while (sp->next != Seg) {
            sp = sp->next;
            if (sp == NULL) {   /* this segment is not in the list!!! */
                /* this should not happen, but you never know... */
                static BOOL WarningDisplayed = FALSE;

                if (!WarningDisplayed) {
		    MessageBox (hFrameWnd,
                                "Please shutdown EMACS as soon as possible",
                                "Corrupted memory",
                                MB_OK | MB_ICONSTOP);
                }
                WarningDisplayed = TRUE;
                return;
            }
        }
        sp->next = Seg->next;       /* unlink the segment */
#if MEMTRACE
        mtr[mtrx].m_func = MTR_FREESEG;
        mtr[mtrx].m_ptr.m_segh = Seg;
        mtr[mtrx].m_cnt = Seg->alloc_count;
        mtr[mtrx].m_size = GlobalSize (hSeg);
        mtr[mtrx++].m_optimseg = OptimumSeg;
#endif

        SWITCH_DS(wSeg)
	UnlockData (0);
	RESTORE_DS
	
        GlobalUnlock (hSeg);
        GlobalFree (hSeg);          /* and release it */
    }
    else {  /* segment still in use */
	OptimumSeg = Seg;       /* next malloc will try this segment
				   first */
    }
} /* free */
Пример #12
0
BOOL DisplayPrinterDriverInfo (HWND hwnd)
{
  HANDLE        hPrinter;
  DWORD         dwBytesNeeded;
  DRIVER_INFO_1 *pDriverInfo1;
  DRIVER_INFO_2 *pDriverInfo2;
  char          buf[BUFSIZE];
  char          pEnvironment[BUFSIZE] = "";
  BOOL          bReturn = TRUE;

  //
  // open selected printer & alloc buffers & get sundry info, close printer
  //

  OpenPrinter (gszDeviceName, &hPrinter, NULL);

  if (!hPrinter)
  {
    char buf[BUFSIZE];

    _snprintf_s (buf, BUFSIZE, _TRUNCATE, GetStringRes(IDS_FMT_OPNPRTFAIL), gszDeviceName);
    ErrMsgBox ((LPCSTR) buf, ERR_MOD_NAME);
    bReturn  = FALSE;
    goto display_prt_drv_info_done1;
  }

  GetPrinterDriver (hPrinter, pEnvironment, 1, NULL, 0, &dwBytesNeeded);

  //
  // simple error checking, if these work assume rest will too
  //

  if (!(pDriverInfo1 = (DRIVER_INFO_1 *) LocalAlloc (LPTR, dwBytesNeeded)))
  {
    ErrMsgBox (GetStringRes(IDS_LALLOCFAIL), ERR_MOD_NAME);
    bReturn = FALSE;
    goto display_prt_drv_info_done1;
  }

  if (!GetPrinterDriver (hPrinter, pEnvironment, 1, (LPBYTE) pDriverInfo1,
                         dwBytesNeeded, &dwBytesNeeded))
  {
    ErrMsgBox (GetStringRes(IDS_GETPRTDRVFAIL), ERR_MOD_NAME);
    bReturn = FALSE;
    goto display_prt_drv_info_done2;
  }

  GetPrinterDriver (hPrinter, pEnvironment, 2, NULL, 0, &dwBytesNeeded);
  pDriverInfo2 = (DRIVER_INFO_2 *) LocalAlloc (LPTR, dwBytesNeeded);
  GetPrinterDriver (hPrinter, pEnvironment, 2, (LPBYTE) pDriverInfo2,
                    dwBytesNeeded, &dwBytesNeeded);

  ClosePrinter (hPrinter);

  //
  // shove info in listbox
  //

  if ( _snprintf_s (buf, BUFSIZE, _TRUNCATE, gaDrvInfo[0]) > 0 )
	outstr();

  if ( _snprintf_s (buf, BUFSIZE, _TRUNCATE, gaDrvInfo[1], pDriverInfo1->pName) > 0 )
	outstr();

  if ( _snprintf_s (buf, BUFSIZE, _TRUNCATE, gaDrvInfo[2]) > 0 )
	outstr();

  if ( _snprintf_s (buf, BUFSIZE, _TRUNCATE, gaDrvInfo[3], pDriverInfo2->cVersion) > 0 )
	outstr();

  if ( _snprintf_s (buf, BUFSIZE, _TRUNCATE, gaDrvInfo[4], pDriverInfo2->pName) > 0 )
	outstr();

  if ( _snprintf_s (buf, BUFSIZE, _TRUNCATE, gaDrvInfo[5], pDriverInfo2->pEnvironment) > 0 )
	outstr();

  if ( _snprintf_s (buf, BUFSIZE, _TRUNCATE, gaDrvInfo[6], pDriverInfo2->pDriverPath) > 0 )
	outstr();

  if ( _snprintf_s (buf, BUFSIZE, _TRUNCATE, gaDrvInfo[7], pDriverInfo2->pDataFile) > 0 )
	outstr();

  if ( _snprintf_s (buf, BUFSIZE, _TRUNCATE, gaDrvInfo[8], pDriverInfo2->pConfigFile) > 0 )
	outstr();

  LocalFree (LocalHandle (pDriverInfo2));

display_prt_drv_info_done2:

  LocalFree (LocalHandle (pDriverInfo1));

display_prt_drv_info_done1:

  return bReturn;
}
Пример #13
0
static void test_LocalAlloc(void)
{
    ULONG memchunk;
    HLOCAL mem1,mem2,mem2a,mem2b;
    UCHAR *mem2ptr;
    UINT i;
    BOOL error;
    memchunk=100000;

    /* Check that a normal alloc works */
    mem1=LocalAlloc(0,memchunk);
    ok(mem1!=NULL,"LocalAlloc failed: error=%d\n",GetLastError());
    if(mem1) {
      ok(LocalSize(mem1)>=memchunk, "LocalAlloc should return a big enough memory block\n");
    }

    /* Check that a 'zeroing' and lock alloc works */
    mem2=LocalAlloc(LMEM_ZEROINIT|LMEM_MOVEABLE,memchunk);
    ok(mem2!=NULL,"LocalAlloc failed: error=%d\n",GetLastError());
    if(mem2) {
      ok(LocalSize(mem2)>=memchunk,"LocalAlloc should return a big enough memory block\n");
      mem2ptr=LocalLock(mem2);
      ok(mem2ptr!=NULL,"LocalLock: error=%d\n",GetLastError());
      if(mem2ptr) {
        error=FALSE;
        for(i=0;i<memchunk;i++) {
          if(mem2ptr[i]!=0) {
            error=TRUE;
          }
        }
        ok(!error,"LocalAlloc should have zeroed out its allocated memory\n");
        SetLastError(0);
        error=LocalUnlock(mem2);
        ok(!error && GetLastError()==NO_ERROR,
           "LocalUnlock Failed: rc=%d err=%d\n",error,GetLastError());
      }
    }
   mem2a=LocalFree(mem2);
   ok(mem2a==NULL, "LocalFree failed: %p\n",mem2a);

   /* Reallocate mem2 as moveable memory */
   mem2=LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT,memchunk);
   ok(mem2!=NULL, "LocalAlloc failed to create moveable memory, error=%d\n",GetLastError());

   /* Check that ReAllocing memory works as expected */
    mem2a=LocalReAlloc(mem2,2*memchunk,LMEM_MOVEABLE | LMEM_ZEROINIT);
    ok(mem2a!=NULL,"LocalReAlloc failed, error=%d\n",GetLastError());
    if(mem2a) {
      ok(LocalSize(mem2a)>=2*memchunk,"LocalReAlloc failed\n");
      mem2ptr=LocalLock(mem2a);
      ok(mem2ptr!=NULL,"LocalLock Failed\n");
      if(mem2ptr) {
        error=FALSE;
        for(i=0;i<memchunk;i++) {
          if(mem2ptr[memchunk+i]!=0) {
            error=TRUE;
          }
        }
        ok(!error,"LocalReAlloc should have zeroed out its allocated memory\n");
        /* Check that LocalHandle works */
        mem2b=LocalHandle(mem2ptr);
        ok(mem2b==mem2a,"LocalHandle didn't return the correct memory handle %p/%p for %p\n",
           mem2a, mem2b, mem2ptr);
        /* Check that we can't discard locked memory */
        mem2b=LocalDiscard(mem2a);
        ok(mem2b==NULL,"Discarded memory we shouldn't have\n");
        SetLastError(NO_ERROR);
        ok(!LocalUnlock(mem2a) && GetLastError()==NO_ERROR, "LocalUnlock Failed\n");
      }
    }
    if(mem1) {
      ok(LocalFree(mem1)==NULL,"LocalFree failed\n");
    }
    if(mem2a) {
      ok(LocalFree(mem2a)==NULL,"LocalFree failed\n");
    } else {
      ok(LocalFree(mem2)==NULL,"LocalFree failed\n");
    }
}
Пример #14
0
/* read all entries in a directory, and create a sorted list of files
 * in that directory, and a sorted list of subdirs.
 *
 * for each file found, call ss_process_file to checksum and report on
 * the file.
 * for each subdir, report the name of the new dir and then
 * recursively call this function to scan it.
 *
 * We have two names for the dir- the absolute name (which we use to
 * scan it) and the name relative to the pRoot starting point - which
 * pass on to the client
 *
 * return TRUE if all ok, or FALSE if the connection has been lost
 */
BOOL
ss_processdir(  HANDLE hpipe,
                long lVersion,
                LPSTR pAbsName,         /* absolute name of dir (to open) */
                LPSTR pRelName,         /* relative name of dir (to report) */
                BOOL bChecksum,         /* TRUE iff checksums are wanted */
                BOOL fDeep              /* TRUE iff subdirs to be included */
                )
{
        PFNAMELIST pfiles = NULL;
        PFNAMELIST pdirs = NULL;
        PFNAMELIST pnext;
        HANDLE hFind;
        WIN32_FIND_DATA finddata;
        BOOL bMore;
        char szNewAbs[MAX_PATH], szNewRel[MAX_PATH];
        HANDLE hFile;

        /* initiate a search of the directory - append
         * *.* to the directory name
         */
        lstrcpy(szNewAbs, pAbsName);
        lstrcat(szNewAbs, "\\*.*");

        hFind = FindFirstFile(szNewAbs, &finddata);

        if (hFind == INVALID_HANDLE_VALUE) {
                bMore = FALSE;
        } else {
                bMore = TRUE;
        }

        /* loop reading all entries in the directory */
        while (bMore) {

                /* was it a directory or a file ? */
                if (finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {

                        /* ignore . and .. */
                        if ((strcmp(finddata.cFileName, ".") != 0)  &&
                           (strcmp(finddata.cFileName, "..") != 0)) {

                                /* insert in sorted list of dir names */
                                pdirs = ss_addtolist(pdirs, finddata.cFileName);
                        }

                } else {
                        /* insert in sorted list of file names */
                        pfiles = ss_addtolist(pfiles, finddata.cFileName);
                }

                /* get next entry in directory if there are any */
                bMore = FindNextFile(hFind, &finddata);
        }
        FindClose(hFind);

        /* we have now built the sorted lists.
         * go through the file list first and process each entry */
        for (pnext = pfiles; pnext != NULL; ) {

                /* build a new abs and relative name for this file */
                lstrcpy(szNewAbs, pAbsName);
                lstrcat(szNewAbs, "\\");
                lstrcat(szNewAbs, pnext->szFile);

                lstrcpy(szNewRel, pRelName);
                lstrcat(szNewRel, "\\");
                lstrcat(szNewRel, pnext->szFile);

                /* checksum the file and send response */
                if (!ss_processfile(hpipe, lVersion, szNewAbs, szNewRel, bChecksum)) {
                        return(FALSE);
                }

                /* free up the list entry */
                pfiles = pnext->next;
                LocalUnlock(LocalHandle( (PSTR) pnext));
                LocalFree(LocalHandle( (PSTR) pnext));
                pnext = pfiles;
        }
        if (!fDeep) return TRUE;

        /* loop through the subdirs and recursively scan those */
        for (pnext = pdirs; pnext != NULL; ) {

                /* build a new abs and relative name for this dir */
                lstrcpy(szNewAbs, pAbsName);
                lstrcat(szNewAbs, "\\");
                lstrcat(szNewAbs, pnext->szFile);

                lstrcpy(szNewRel, pRelName);
                lstrcat(szNewRel, "\\");
                lstrcat(szNewRel, pnext->szFile);

                /* send the name of the new dir to the client */
                if (!ss_sendnewresp( hpipe, lVersion, SSRESP_DIR
                                   , 0, 0, 0, 0, szNewRel)) {
                        return(FALSE);
                }

                if (!ss_processdir(hpipe, lVersion, szNewAbs, szNewRel, bChecksum, TRUE) ) {
                        return(FALSE);
                }

                /* free up the list entry */
                pdirs = pnext->next;
                LocalUnlock(LocalHandle( (PSTR) pnext));
                LocalFree(LocalHandle( (PSTR) pnext));
                pnext = pdirs;
        }
        return(TRUE);
} /* ss_processdir */
Пример #15
0
/* asqlBlobMemPut()
 *
 *************************************************************************/
_declspec(dllexport) long asqlBlobMemPut(TS_CLIENT_CURSOR *tscc, \
					LPCSTR lpszUser, \
					LPCSTR lpszUserDir,\
					void *df, \
					long recNo, \
					LPSTR fieldName, \
					EXCHNG_BUF_INFO *exbuf )
{
    TS_COM_PROPS tscp;
    unsigned short iw;
    char           *sp;
    long           memSize;
    BOOL 	   pbIfEnd;

    memset(&tscp, 0, sizeof(TS_COM_PROPS));

    while( tscc != NULL ) {
	if( tscc->p == (void *)df )
	    goto  agdr_dfTrueR;
	tscc = tscc->pNext;
    }
	df = NULL;
agdr_dfTrueR:

    if( SrvReadExchngBufEx(exbuf, &sp, &memSize, &pbIfEnd) != 0 ) {
	tscp.lp = -5;
	SrvWriteExchngBuf(exbuf, &tscp, sizeof(TS_COM_PROPS));
	return  -5;
    }

    tscp.packetType = 'R';
    tscp.msgType = 'E';
    tscp.len = 0;

    if( df == NULL || recNo <= 0 ) {
	HANDLE hDataBuf;

	hDataBuf = LocalHandle(sp);
	LocalUnlock( hDataBuf );
	LocalFree( hDataBuf );

	tscp.lp = -1;
	SrvWriteExchngBuf(exbuf, &tscp, sizeof(TS_COM_PROPS));

	return  -1;
    }

    iw = GetFldid((dFILE *)df, fieldName);
    if( iw == 0xFFFF ) {
	HANDLE hDataBuf;

	hDataBuf = LocalHandle(sp);
	LocalUnlock( hDataBuf );
	LocalFree( hDataBuf );

	tscp.lp = -4;
	SrvWriteExchngBuf(exbuf, &tscp, sizeof(TS_COM_PROPS));
	return  -4;
    }

    //((dFILE *)df)->rec_p = recNo;
    dseek((dFILE *)df, recNo-1, dSEEK_SET);

    if( get1rec((dFILE *)df) == NULL ) {
	HANDLE hDataBuf;

	hDataBuf = LocalHandle(sp);
	LocalUnlock( hDataBuf );
	LocalFree( hDataBuf );

	tscp.lp = -4;
	SrvWriteExchngBuf(exbuf, &tscp, sizeof(TS_COM_PROPS));
	return  -4;
    }

    //2000.7.21
    /*
    if( memSize < 0 ) {
	
    } else {
	blobFromMem((dFILE *)df, iw, sp, memSize);
    }*/
  
    if( memSize >= 0 ) {
	blobFromMem((dFILE *)df, iw, sp, memSize);
    }


    { ///////////////////////
	HANDLE hDataBuf;

	hDataBuf = LocalHandle(sp);
	LocalUnlock( hDataBuf );
	LocalFree( hDataBuf );
    }

    tscp.msgType = 'D';
    tscp.lp = 0;
    SrvWriteExchngBuf(exbuf, &tscp, sizeof(TS_COM_PROPS));

    return  0;

} //end of asqlBlobMemPut()
Пример #16
0
static int createAboutBox( HINSTANCE hInstance, HWND hwnd )
{
    WORD*	p, *pdlgtemplate;
    int		nchar;
    DWORD	lStyle;
    HWND	hwndReturn;
    /*
     *	Allocate some memory to play with
     */
    pdlgtemplate = p = ( PWORD ) LocalAlloc( LPTR, 1000 );
    /*
     *	Start to fill in the dlgtemplate information.  addressing by WORDs
     */
    lStyle = WS_DLGFRAME | WS_POPUP | WS_VISIBLE | WS_CLIPCHILDREN | DS_SETFONT;
    *p++ = LOWORD( lStyle );
    *p++ = HIWORD( lStyle );
    *p++ = 0;          /* LOWORD (lExtendedStyle) */
    *p++ = 0;          /* HIWORD (lExtendedStyle) */
    *p++ = 7;          /* Number Of Items	*/
    *p++ = 210;        /* x */
    *p++ = 10;         /* y */
    *p++ = 200;        /* cx */
    *p++ = 100;        /* cy */
    *p++ = 0;          /* Menu */
    *p++ = 0;          /* Class */
    /*
     *	Copy the title of the dialog
     */
    nchar = nCopyAnsiToWideChar( p, "GoAhead WebServer" );
    p += nchar;
    /*
     *	Font information because of DS_SETFONT
     */
    *p++ = 11;     /* point size */
    nchar = nCopyAnsiToWideChar( p, T( "Arial Bold" ) );
    p += nchar;
    /*
     *	Make sure the first item starts on a DWORD boundary
     */
    p = lpwAlign( p );
    /*
     *	Now start with the first item (Product Identifier)
     */
    lStyle = SS_CENTER | WS_VISIBLE | WS_CHILD | WS_TABSTOP;
    *p++ = LOWORD( lStyle );
    *p++ = HIWORD( lStyle );
    *p++ = 0;			/* LOWORD (lExtendedStyle) */
    *p++ = 0;			/* HIWORD (lExtendedStyle) */
    *p++ = 10;			/* x */
    *p++ = 10;			/* y  */
    *p++ = 180;			/* cx */
    *p++ = 15;			/* cy */
    *p++ = 1;			/* ID */
    /*
     *	Fill in class i.d., this time by name
     */
    nchar = nCopyAnsiToWideChar( p, TEXT( "STATIC" ) );
    p += nchar;
    /*
     *	Copy the text of the first item
     */
    nchar = nCopyAnsiToWideChar( p,
                                 TEXT( "GoAhead WebServer 2.1.8" ) );
    p += nchar;
    /*
     *	Advance pointer over nExtraStuff WORD
     */
    *p++ = 0;
    /*
     *	Make sure the next item starts on a DWORD boundary
     */
    p = lpwAlign( p );
    /*
     *	Next, the Copyright Notice.
     */
    lStyle = SS_CENTER | WS_VISIBLE | WS_CHILD | WS_TABSTOP;
    *p++ = LOWORD( lStyle );
    *p++ = HIWORD( lStyle );
    *p++ = 0;			/* LOWORD (lExtendedStyle) */
    *p++ = 0;			/* HIWORD (lExtendedStyle) */
    *p++ = 10;			/* x */
    *p++ = 30;			/* y  */
    *p++ = 180;			/* cx */
    *p++ = 15;			/* cy */
    *p++ = 1;			/* ID */
    /*
     *	Fill in class i.d. by name
     */
    nchar = nCopyAnsiToWideChar( p, TEXT( "STATIC" ) );
    p += nchar;
    /*
     *	Copy the text of the item
     */
    nchar = nCopyAnsiToWideChar( p, GOAHEAD_COPYRIGHT );
    p += nchar;
    /*
     *	Advance pointer over nExtraStuff WORD
     */
    *p++ = 0;
    /*
     *	Make sure the next item starts on a DWORD boundary
     */
    p = lpwAlign( p );
    /*
     *	Add third item ("Version:")
     */
    lStyle = SS_RIGHT | WS_VISIBLE | WS_CHILD | WS_TABSTOP;
    *p++ = LOWORD( lStyle );
    *p++ = HIWORD( lStyle );
    *p++ = 0;
    *p++ = 0;
    *p++ = 28;
    *p++ = 50;
    *p++ = 70;
    *p++ = 10;
    *p++ = 1;
    nchar = nCopyAnsiToWideChar( p, T( "STATIC" ) );
    p += nchar;
    nchar = nCopyAnsiToWideChar( p, T( "Version:" ) );
    p += nchar;
    *p++ = 0;
    /*
     *	Add fourth Item (IDC_VERSION)
     */
    p = lpwAlign( p );
    lStyle = SS_LEFT | WS_VISIBLE | WS_CHILD | WS_TABSTOP;
    *p++ = LOWORD( lStyle );
    *p++ = HIWORD( lStyle );
    *p++ = 0;
    *p++ = 0;
    *p++ = 102;
    *p++ = 50;
    *p++ = 70;
    *p++ = 10;
    *p++ = IDC_VERSION;
    nchar = nCopyAnsiToWideChar( p, T( "STATIC" ) );
    p += nchar;
    nchar = nCopyAnsiToWideChar( p, T( "version" ) );
    p += nchar;
    *p++ = 0;
    /*
     *	Add fifth item ("Build Date:")
     */
    p = lpwAlign( p );
    lStyle = SS_RIGHT | WS_VISIBLE | WS_CHILD | WS_TABSTOP;
    *p++ = LOWORD( lStyle );
    *p++ = HIWORD( lStyle );
    *p++ = 0;
    *p++ = 0;
    *p++ = 28;
    *p++ = 65;
    *p++ = 70;
    *p++ = 10;
    *p++ = 1;
    nchar = nCopyAnsiToWideChar( p, T( "STATIC" ) );
    p += nchar;
    nchar = nCopyAnsiToWideChar( p, T( "Build Date:" ) );
    p += nchar;
    *p++ = 0;
    /*
     *	Add sixth item (IDC_BUILDDATE)
     */
    p = lpwAlign( p );
    lStyle = SS_LEFT | WS_VISIBLE | WS_CHILD | WS_TABSTOP;
    *p++ = LOWORD( lStyle );
    *p++ = HIWORD( lStyle );
    *p++ = 0;
    *p++ = 0;
    *p++ = 102;
    *p++ = 65;
    *p++ = 70;
    *p++ = 10;
    *p++ = IDC_BUILDDATE;
    nchar = nCopyAnsiToWideChar( p, T( "STATIC" ) );
    p += nchar;
    nchar = nCopyAnsiToWideChar( p, T( "Build Date" ) );
    p += nchar;
    *p++ = 0;
    /*
     *	Add seventh item (IDOK)
     */
    p = lpwAlign( p );
    lStyle = BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD | WS_TABSTOP;
    *p++ = LOWORD( lStyle );
    *p++ = HIWORD( lStyle );
    *p++ = 0;
    *p++ = 0;
    *p++ = 80;
    *p++ = 80;
    *p++ = 40;
    *p++ = 10;
    *p++ = IDOK;
    nchar = nCopyAnsiToWideChar( p, T( "BUTTON" ) );
    p += nchar;
    nchar = nCopyAnsiToWideChar( p, T( "OK" ) );
    p += nchar;
    *p++ = 0;
    hwndReturn = CreateDialogIndirect( hInstance,
                                       ( LPDLGTEMPLATE ) pdlgtemplate, hwnd, ( DLGPROC ) websAboutProc );
    LocalFree( LocalHandle( pdlgtemplate ) );
    return 0;
}
Пример #17
0
BOOL
init_print_gdi(HDC hdc)
{
    // create the pipe for capturing printer output
    /* Set the bInheritHandle flag so pipe handles are inherited. */
    SECURITY_ATTRIBUTES saAttr;
    saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
    saAttr.bInheritHandle = TRUE;
    saAttr.lpSecurityDescriptor = NULL;
    HANDLE hPipeTemp;

    if (!CreatePipe(&hPipeTemp, &print_gdi_write_handle, &saAttr, 0)) {
	gs_addmess("failed to open printer pipe\n");
	return FALSE;
    }
    /* make the read handle non-inherited */
    if (!DuplicateHandle(GetCurrentProcess(), hPipeTemp,
	    GetCurrentProcess(), &print_gdi_read_handle, 0,
	    FALSE,       /* not inherited */
	    DUPLICATE_SAME_ACCESS)) {
	gs_addmess("failed to duplicate pipe handle\n");
	return FALSE;
    }
    CloseHandle(hPipeTemp);

    // open printer, get size and resolution
    DOCINFO di;
    TCHAR wpsname[MAXSTR];
    convert_multibyte(wpsname, psfile_name(&psfile), 
	sizeof(wpsname)/sizeof(TCHAR)-1);
    memset(&di, 0, sizeof(DOCINFO));
    di.cbSize = sizeof(DOCINFO);
    di.lpszDocName = wpsname;
    di.lpszOutput = NULL;
    if (StartDoc(hdc, &di) == SP_ERROR) {
	DWORD err = GetLastError();
	LPSTR lpMessageBuffer;
	char buf[MAXSTR];
	sprintf(buf, "StartDoc failed, error %d\n", err);
	gs_addmess(buf);
	FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
	    FORMAT_MESSAGE_FROM_SYSTEM,
	    NULL, err,
	    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* user default language */
	    (LPSTR)&lpMessageBuffer, 0, NULL);
	if (lpMessageBuffer) {
	    gs_addmess(lpMessageBuffer);
	    gs_addmess("\r\n");
	    LocalFree(LocalHandle(lpMessageBuffer));
	}
	return FALSE;
    }

    // Need to pass these back to gvcprn.cpp.
    // Use global variables for now.
    print_gdi_width = GetDeviceCaps(hdc, PHYSICALWIDTH);
    print_gdi_height = GetDeviceCaps(hdc, PHYSICALHEIGHT);
    print_gdi_xdpi = GetDeviceCaps(hdc, LOGPIXELSX);
    print_gdi_ydpi = GetDeviceCaps(hdc, LOGPIXELSY);
    if (debug & DEBUG_GDI) {
	char buf[MAXSTR];
	sprintf(buf, "GDI width=%d height=%d xdpi=%d ydpy=%d\n",
	    print_gdi_width, print_gdi_height, print_gdi_xdpi, print_gdi_ydpi);
	gs_addmess(buf);
    }

    if ( (print_gdi_width == 0) || (print_gdi_height == 0) ) {
	gs_addmess("Printer width or height is zero\n");
	return FALSE;
    }
 
    return TRUE;
}