xHarbour para Harbour
Enviado: 07 Mar 2014 15:03
Colegas;
após ler alguns comentários dos colegas, revolvi migrar de xHarbour para Harbour 3.2 + mingw (Harbour-migtly-win);
dados arquivo .HBP em Harbour:
-lxhb
-lhbcomm
-lhbwin
-lhbct
-lgtwvg
-oexecutavel
-inc
-workdir=d:\temp
*.prg
utilizando as mesmas rotinas, observei:
- executável Harbour maior que o executável xHarbour em 42%;
- uma aplicação em Harbour executou a mesma aplicação em xharbor, 30% mais rápido;
- a compilação Harbour encontrou erros de programação que a compilação XHarbour não encontrou;
entendo que o ganho em velocidade justifica a migração;
mas encontrei 2 problemas que ainda não consegui resolver:
problema 1: ao chamar o executável, uma janela em branco do dos aparece por trás e se fechá-la a aplicação também fecha;
problema 2: utilizo alguns fragmentos das rotinas publicadas do Vailton para conexão com outros terminais e em Harbour na
compilação aparece um erro de rotina WNETOPENENUM não encontrada:
me perdoem, mas não sei como postar uma rotina como os colegas;
agradeço qualquer ajuda;
rotina do Vailton: TCP/IP e Network com Win32 API - NetOpenenumApp
após ler alguns comentários dos colegas, revolvi migrar de xHarbour para Harbour 3.2 + mingw (Harbour-migtly-win);
dados arquivo .HBP em Harbour:
-lxhb
-lhbcomm
-lhbwin
-lhbct
-lgtwvg
-oexecutavel
-inc
-workdir=d:\temp
*.prg
utilizando as mesmas rotinas, observei:
- executável Harbour maior que o executável xHarbour em 42%;
- uma aplicação em Harbour executou a mesma aplicação em xharbor, 30% mais rápido;
- a compilação Harbour encontrou erros de programação que a compilação XHarbour não encontrou;
entendo que o ganho em velocidade justifica a migração;
mas encontrei 2 problemas que ainda não consegui resolver:
problema 1: ao chamar o executável, uma janela em branco do dos aparece por trás e se fechá-la a aplicação também fecha;
problema 2: utilizo alguns fragmentos das rotinas publicadas do Vailton para conexão com outros terminais e em Harbour na
compilação aparece um erro de rotina WNETOPENENUM não encontrada:
me perdoem, mas não sei como postar uma rotina como os colegas;
agradeço qualquer ajuda;
rotina do Vailton: TCP/IP e Network com Win32 API - NetOpenenumApp
Código: Selecionar todos
-----------------------------------------------------------------------------------------------
* This example illustrates an how enumerates the resources on a network using
* Win32 API with Harbour/xHarbour.
*
* COMPILE WITH: hbmk2 -run NetOpenEnumApp.hbp
*
* 03/03/2011 - 14:25:12 - [vailtom]
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#include "common.ch"
#include "simpleio.ch"
/* Scope of the enumeration (from winnetwk.h) */
#define RESOURCE_CONNECTED 0x00000001
#define RESOURCE_GLOBALNET 0x00000002
#define RESOURCE_REMEMBERED 0x00000003
#define RESOURCE_RECENT 0x00000004
#define RESOURCE_CONTEXT 0x00000005
/* Resource types to be enumerated (from winnetwk.h) */
#define RESOURCETYPE_ANY 0x00000000
#define RESOURCETYPE_DISK 0x00000001
#define RESOURCETYPE_PRINT 0x00000002
/* Resource usage type to be enumerated */
#define RESOURCEUSAGE_CONNECTABLE 0x00000001
#define RESOURCEUSAGE_CONTAINER 0x00000002
#define RESOURCEUSAGE_ALL 0
/* ... */
#define RESOURCEDISPLAYTYPE_GENERIC 0x00000000
#define RESOURCEDISPLAYTYPE_DOMAIN 0x00000001
#define RESOURCEDISPLAYTYPE_SERVER 0x00000002
#define RESOURCEDISPLAYTYPE_SHARE 0x00000003
#define RESOURCEDISPLAYTYPE_FILE 0x00000004
#define RESOURCEDISPLAYTYPE_GROUP 0x00000005
#define RESOURCEDISPLAYTYPE_NETWORK 0x00000006
#define RESOURCEDISPLAYTYPE_ROOT 0x00000007
#define RESOURCEDISPLAYTYPE_SHAREADMIN 0x00000008
#define RESOURCEDISPLAYTYPE_DIRECTORY 0x00000009
#define RESOURCEDISPLAYTYPE_TREE 0x0000000A
#define RESOURCEDISPLAYTYPE_NDSCONTAINER 0x0000000B
/* Error codes */
#define ERROR_NOT_CONTAINER 1207
#define ERROR_INVALID_PARAMETER 87
#define ERROR_NO_NETWORK 1222
#define ERROR_EXTENDED_ERROR 1208
#define ERROR_INVALID_ADDRESS 487
* Main function demo
FUNCTION MAIN()
LOCAL ExeName
LOCAL Choice := '*'
ExeName := Substr( hb_ArgV(0), Rat( "\", hb_ArgV(0) ) +1 )
ExeName := Substr( ExeName, 1, LEN( ExeName ) -4 )
?? ExeName, 'by Vailton Renato <vailtom@gmail.com>'
? '--------------------------------------------------------'
? 'This example illustrates an how enumerates the resources'
? 'on a network using Win32 API with Harbour/xHarbour.'
DO WHILE Choice != '0'
? '--------------------------------------------------------'
?
? '1. Enumerates all resources on network'
? '2. Enumerates all computers and containers'
? '3. Enumerates all printers'
? '4. Enumerates all shares'
? '0. Exit'
?
? 'ENTER your choice: '
Choice := CHR( Inkey(0) )
?? Choice
SWITCH Choice
CASE '1'
?
? 'Searching resources on network (press any key to abort)'
?
WNetOpenEnum( {|aInfo| DisplayInfo(aInfo), .T. }, RESOURCE_GLOBALNET, RESOURCETYPE_ANY, RESOURCEUSAGE_ALL )
EXIT
CASE '2'
?
? 'Searching computers or containers (press any key to abort)'
?
WNetOpenEnum( {|aInfo| PrintComputers(aInfo) }, RESOURCE_GLOBALNET, RESOURCETYPE_ANY, RESOURCEUSAGE_ALL )
EXIT
CASE '3'
?
? 'Searching printers (press any key to abort)'
?
WNetOpenEnum( {|aInfo| PrintPrinters(aInfo) }, RESOURCE_GLOBALNET, RESOURCETYPE_ANY, RESOURCEUSAGE_ALL )
EXIT
CASE '4'
?
? 'Searching all shares (press any key to abort)'
?
WNetOpenEnum( {|aInfo| PrintShares(aInfo) }, RESOURCE_GLOBALNET, RESOURCETYPE_ANY, RESOURCEUSAGE_ALL )
EXIT
END
* To clear keyboard buffer...
Inkey(.5)
ENDDO
RETURN nil
* Filters only computers
FUNCTION PrintComputers( aInfo )
IF ( aInfo[4] >= RESOURCEUSAGE_CONTAINER) .AND. (Left( aInfo[6], 2 ) == '\\' )
DisplayInfo( aInfo )
ELSE
?? '.'
ENDIF ]
RETURN (NextKey() == 00)
* Filters only printers
FUNCTION PrintPrinters( aInfo )
IF ( aInfo[2] == RESOURCETYPE_PRINT )
DisplayInfo( aInfo )
ELSE
?? '.'
ENDIF ]
RETURN (NextKey() == 00)
* Filters all shared resources
FUNCTION PrintShares( aInfo )
IF ( aInfo[2] == RESOURCETYPE_DISK )
DisplayInfo( aInfo )
ELSE
?? '.'
ENDIF ]
RETURN (NextKey() == 00)
/*
* Print all info about this network resource
* 04/03/2011 - 10:13:36 - [vailtom]
*/
PROCEDURE DisplayInfo( aInfo )
? "Scope: "
SWITCH (aInfo[1])
CASE (RESOURCE_CONNECTED)
?? "connected"
EXIT
CASE (RESOURCE_GLOBALNET)
?? "all resources"
EXIT
CASE (RESOURCE_REMEMBERED)
?? "remembered"
EXIT
OTHERWISE
?? "unknown scope", aInfo[1]
EXIT
END
? "Type: "
SWITCH (aInfo[2])
CASE (RESOURCETYPE_ANY)
?? "any"
EXIT
CASE (RESOURCETYPE_DISK)
?? "disk"
EXIT
CASE (RESOURCETYPE_PRINT)
?? "print"
EXIT
OTHERWISE
?? "unknown type %d\n", aInfo[2]
EXIT
END
? "DisplayType: "
SWITCH (aInfo[3])
CASE (RESOURCEDISPLAYTYPE_GENERIC)
?? "generic"
EXIT
CASE (RESOURCEDISPLAYTYPE_DOMAIN)
?? "domain"
EXIT
CASE (RESOURCEDISPLAYTYPE_SERVER)
?? "server"
EXIT
CASE (RESOURCEDISPLAYTYPE_SHARE)
?? "share"
EXIT
CASE (RESOURCEDISPLAYTYPE_FILE)
?? "file"
EXIT
CASE (RESOURCEDISPLAYTYPE_GROUP)
?? "group"
EXIT
CASE (RESOURCEDISPLAYTYPE_NETWORK)
?? "network"
EXIT
CASE (RESOURCEDISPLAYTYPE_ROOT)
?? "root for the entire network"
EXIT
CASE (RESOURCEDISPLAYTYPE_SHAREADMIN)
?? "administrative share"
EXIT
CASE (RESOURCEDISPLAYTYPE_DIRECTORY)
?? "directory"
EXIT
CASE (RESOURCEDISPLAYTYPE_TREE)
?? "NetWare Directory Service (NDS) tree"
EXIT
CASE (RESOURCEDISPLAYTYPE_NDSCONTAINER)
?? "Netware Directory Service container"
EXIT
OTHERWISE
?? "unknown display type", aInfo[3]
EXIT
END
? "Usage: "
IF (aInfo[4] >= RESOURCEUSAGE_CONTAINER)
?? "container "
aInfo[4] -= RESOURCEUSAGE_CONTAINER
ENDIF
IF (aInfo[4] >= RESOURCEUSAGE_CONNECTABLE)
?? "connectable "
aInfo[4] -= RESOURCEUSAGE_CONNECTABLE
ENDIF
? 'Localname: "' + aInfo[5] + '"'
? 'Remotename:"' + aInfo[6] + '"'
? 'Comment: "' + aInfo[7] + '"'
? 'Provider: "' + aInfo[8] + '"'
?
RETURN
#pragma begindump
#define _WIN32_IE 0x0500
#define HB_OS_WIN_32_USED
#ifdef __POCC__
#define _WIN32_WINNT 0x0500
#else
#define _WIN32_WINNT 0x0400
#endif
#ifndef UNICODE
#define UNICODE
#endif
#include <windows.h>
#include <stdio.h>
#include <winnetwk.h>
#include "hbapi.h"
#include "hbapiitm.h"
#define BUFF_SIZE 512
typedef struct {
DWORD dwScope; // Scope of the enumeration
DWORD dwType; // Resource types to be enumerated
DWORD dwUsage; // Resource usage type to be enumerated
BOOL bAborted; // Abort process?
char Buffer[BUFF_SIZE+1]; // Buffer temporario para conversoes
PHB_ITEM pBlock;
} ENUM_INFO, * PENUM_INFO;
static void ConvToArrAsStdStr( PHB_ITEM pArray, ULONG ulIndex, PENUM_INFO pEnumInfo,
LPCWSTR Buffer )
{
pEnumInfo->Buffer[0] = '\0';
WideCharToMultiByte( CP_UTF8, 0, Buffer, -1,
pEnumInfo->Buffer, BUFF_SIZE, NULL, NULL );
hb_arraySetC( pArray, ulIndex, pEnumInfo->Buffer );
}
/*
*
*
* 03/03/2011 - 17:23:37 - [vailtom]
*/
static void ExecuteEnumCallBack(int i, PENUM_INFO pEnumInfo, LPNETRESOURCE lpnrLocal)
{
PHB_ITEM pArray = hb_itemArrayNew( 8 );
PHB_ITEM pRet;
int iFlags;
hb_arraySetNL( pArray, 1, (long) (lpnrLocal->dwScope) );
hb_arraySetNL( pArray, 2, (long) (lpnrLocal->dwType) );
hb_arraySetNL( pArray, 3, (long) (lpnrLocal->dwDisplayType) );
iFlags = 0;
if (lpnrLocal->dwUsage & RESOURCEUSAGE_CONNECTABLE)
iFlags += 1;
if (lpnrLocal->dwUsage & RESOURCEUSAGE_CONTAINER)
iFlags += 2;
hb_arraySetNI( pArray, 4, iFlags );
ConvToArrAsStdStr( pArray, 5, pEnumInfo, lpnrLocal->lpLocalName );
ConvToArrAsStdStr( pArray, 6, pEnumInfo, lpnrLocal->lpRemoteName );
ConvToArrAsStdStr( pArray, 7, pEnumInfo, lpnrLocal->lpComment );
ConvToArrAsStdStr( pArray, 8, pEnumInfo, lpnrLocal->lpProvider );
if( pEnumInfo->pBlock )
{
pRet = hb_itemDo( pEnumInfo->pBlock, 1, pArray );
if (pRet)
{
pEnumInfo->bAborted = !hb_itemGetL( pRet );
hb_itemRelease( pRet );
}
}
hb_itemRelease( pArray );
}
static DWORD WINAPI EnumerateFunc(LPNETRESOURCE lpnr, PENUM_INFO pEnumInfo )
{
DWORD dwResult, dwResultEnum;
HANDLE hEnum;
DWORD cbBuffer = 16384; // 16K is a good size
DWORD cEntries = -1; // enumerate all possible entries
LPNETRESOURCE lpnrLocal; // pointer to enumerated structures
DWORD i;
dwResult = WNetOpenEnum( pEnumInfo->dwScope, // all network resources
pEnumInfo->dwType , // all resources
pEnumInfo->dwUsage, // enumerate all resources
lpnr, // NULL first time the function is called
&hEnum); // handle to the resource
if (dwResult != NO_ERROR)
return dwResult;
lpnrLocal = (LPNETRESOURCE) GlobalAlloc(GPTR, cbBuffer);
if (!lpnrLocal)
return dwResult;
do {
ZeroMemory(lpnrLocal, cbBuffer);
dwResultEnum = WNetEnumResource( hEnum, // resource handle
&cEntries, // defined locally as -1
lpnrLocal, // LPNETRESOURCE
&cbBuffer); // buffer size
if (dwResultEnum == NO_ERROR)
{
for (i = 0; i < cEntries && !pEnumInfo->bAborted; i++)
{
ExecuteEnumCallBack(i, pEnumInfo, &lpnrLocal[i]);
if (!pEnumInfo->bAborted &&
( RESOURCEUSAGE_CONTAINER == (lpnrLocal[i].dwUsage
& RESOURCEUSAGE_CONTAINER) ))
EnumerateFunc(&lpnrLocal[i],pEnumInfo);
}
}
else if (dwResultEnum != ERROR_NO_MORE_ITEMS)
{
// printf("WNetEnumResource failed with error %d (ERROR_NO_MORE_ITEMS)\n", dwResultEnum);
break;
}
}
while (dwResultEnum != ERROR_NO_MORE_ITEMS);
GlobalFree((HGLOBAL) lpnrLocal);
return WNetCloseEnum(hEnum);
}
/*
* The WNetOpenEnum() starts an enumeration of network resources or existing
* connections. Use as:
*
* WNetOpenEnum( bEvalBlock, nScope, nType, nUsage )
*
* For more info, look:
* http://msdn.microsoft.com/en-us/library ... 78(v=vs.85).aspx
*
* 04/03/2011 - 10:26:04 - [vailtom]
*/
HB_FUNC( [b]WNETOPENENUM[/b] )
{
LPNETRESOURCE lpnr = NULL;
ENUM_INFO EnumInfo;
EnumInfo.pBlock = hb_param( 1, HB_IT_BLOCK );
EnumInfo.dwScope = (DWORD) hb_parnl(2);
EnumInfo.dwType = (DWORD) hb_parnl(3);
EnumInfo.dwUsage = (DWORD) hb_parnl(4);
EnumInfo.bAborted= FALSE;
if( EnumInfo.pBlock )
hb_retl( (( EnumerateFunc(lpnr,&EnumInfo) == NO_ERROR)) );
}
#pragma enddump