Page 3 of 6

Re: Migrando de FWH 32 a FWH 64 - windows.h

PostPosted: Fri Jan 02, 2015 10:10 pm
by Verhoven
Tienes razón.
Por equivocación estaba tratando de instalar la versión de MSVC++ Express 2013 para escritorio windows en vez de Community 2013 pensando que eran la misma cosa, pero está claro que no lo son.
Muchísimas gracias.
Intentaré con esto generar la aplicación en 64 bits.

Re: Migrando de FWH 32 a FWH 64 - windows.h

PostPosted: Sun Jan 04, 2015 1:04 pm
by Verhoven
Antonio, después de varios cambios en el orden de algunos ficheros de cabecera en la parte escrita en C de las aplicaciones hemos conseguido compilar en 64 bits.
Pero hemos tenido que eliminar la instrucción: ResAllFree() en el proceso de salida del programa que no sabemos por cual sustiruir.
Y el proceso de salida no va bien porque windows 7 se queda enviando el mensaje:
"Programa.exe dejó de funcionar
windows está buscando una solución al problema..."

Después sale otro mensaje para depurar. Al meterse dentro del depurador de VSC dice que el error está en la línea 5812 que en el prg contiene un sysrefresh(). Y el error es:
Unhandled exception at 0x0000000140118DA7 in wintpv.exe: 0xC0000005: Access violation writing location 0x00000000001E0000.

Además, al compilar nos arroja warnings relativos a funciones de C que copio porque nos deja un poco intranquilos para meterlo a funcionar:

Code: Select all  Expand view
wintpv.c
internet.prg(402) : warning C4244: 'function' : conversion from 'HB_SIZE' to 'DWORD', possible loss of data
internet.prg(443) : warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
        C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\stdio.h(211) : see declaration of 'fopen'
internet.prg(512) : warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
        C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\stdio.h(211) : see declaration of 'fopen'
internet.prg(574) : warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
        C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\stdio.h(211) : see declaration of 'fopen'
internet.prg(657) : warning C4996: 'gethostbyname': Use getaddrinfo() or GetAddrInfoW() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings
        C:\Program Files (x86)\Windows Kits\8.1\include\um\winsock2.h(2238) : see declaration of 'gethostbyname'
internet.prg(667) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
internet.prg(667) : warning C4996: 'inet_ntoa': Use inet_ntop() or InetNtop() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings
        C:\Program Files (x86)\Windows Kits\8.1\include\um\winsock2.h(1868) : see declaration of 'inet_ntoa'
internet.prg(719) : warning C4996: 'gethostbyname': Use getaddrinfo() or GetAddrInfoW() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings
        C:\Program Files (x86)\Windows Kits\8.1\include\um\winsock2.h(2238) : see declaration of 'gethostbyname'
internet.prg(730) : warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
internet.prg(730) : warning C4996: 'inet_ntoa': Use inet_ntop() or InetNtop() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings
        C:\Program Files (x86)\Windows Kits\8.1\include\um\winsock2.h(1868) : see declaration of 'inet_ntoa'
internet.prg(734) : warning C4996: 'inet_addr': Use inet_pton() or InetPton() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings
        C:\Program Files (x86)\Windows Kits\8.1\include\um\winsock2.h(1850) : see declaration of 'inet_addr'
internet.prg(750) : warning C4267: 'function' : conversion from 'size_t' to 'int', possible loss of data
tokh.prg(2907) : warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
        C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\stdio.h(356) : see declaration of 'sprintf'
tokh.prg(2938) : warning C4996: 'strtok': This function or variable may be unsafe. Consider using strtok_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
        C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\string.h(204) : see declaration of 'strtok'
tokh.prg(2952) : warning C4996: 'strtok': This function or variable may be unsafe. Consider using strtok_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
        C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\string.h(204) : see declaration of 'strtok'
tokh.prg(2993) : warning C4996: 'strtok': This function or variable may be unsafe. Consider using strtok_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
        C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\string.h(204) : see declaration of 'strtok'
tokh.prg(3007) : warning C4996: 'strtok': This function or variable may be unsafe. Consider using strtok_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
        C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\string.h(204) : see declaration of 'strtok'
tokh.prg(3086) : warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
        C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\stdio.h(211) : see declaration of 'fopen'
Microsoft (R) Windows (R) Resource Compiler Version 6.3.9600.17298

Copyright (C) Microsoft Corporation.  All rights reserved.


FiveH64.lib(TSOCKET.obj) : warning LNK4006: HB_FUN_SHOWIP already defined in wintpv.obj; second definition ignored
FiveHC64.lib(DC.obj) : warning LNK4006: HB_FUN_FWDISPBEGIN already defined in TWBRWX64_H.lib(wbrwline.obj); second definition ignored
FiveHC64.lib(DC.obj) : warning LNK4006: HB_FUN_FWDISPEND already defined in TWBRWX64_H.lib(wbrwline.obj); second definition ignored
wintpv.exe : warning LNK4088: image being generated due to /FORCE option; image may not run
* Application successfully built *

Re: Migrando de FWH 32 a FWH 64 - windows.h

PostPosted: Sun Jan 04, 2015 4:35 pm
by Antonio Linares
Paz,

Puedes mostrarme que código tienes en esta línea ?

internet.prg(402) : warning C4244: 'function' : conversion from 'HB_SIZE' to 'DWORD', possible loss of data

Reemplaza las llamadas a fopen() con hb_fsOpen() usando los mismos parámetros.

Puedes mostrarme como llamas a strtok() en: ?

tokh.prg(2938) : warning C4996: 'strtok'

Quita el flag /FORCE para enlazar. No es necesario y asi sabremos que funciones hay repetidas. En concreto elimina estas funciones que tienes repetidas aqui:

FWDISPBEGIN() y FWDISPEND() en TWBRWX64_H.lib(wbrwline.obj)

Borland admite funciones repetidas sin problemas, pero Microsoft es más estricto y correcto pues no deben existir funciones repetidas.

Re: Migrando de FWH 32 a FWH 64 - windows.h

PostPosted: Sun Jan 04, 2015 9:07 pm
by Verhoven
Aquí lo tienes:
Para internet.prg(402) : warning C4244: 'function' : conversion from 'HB_SIZE' to 'DWORD', possible loss of data
Code: Select all  Expand view
   BOOL lSuccess = InternetReadFile( ( HINTERNET ) hb_parnl( 1 ), ( LPVOID ) hb_parc( 2 ), hb_parclen( 2 ), &nBytesRead );
 


Para la llamada a strtok:
Code: Select all  Expand view
  elemento = strtok(cadena,"\n");  // "\n" es nueva línea=LF

Re: Migrando de FWH 32 a FWH 64 - windows.h

PostPosted: Sun Jan 04, 2015 9:25 pm
by Verhoven
Antonio,
Para poder usar hb_fsOpen en vez de fopen en el código C hace falta incluir algo más porque da el error:
warning C4013: 'hb_fsOpen' undefined; assuming extern returning int

Re: Migrando de FWH 32 a FWH 64 - windows.h

PostPosted: Sun Jan 04, 2015 10:45 pm
by Antonio Linares
Paz,

Para usar hb_fsOpen() tienes que añadir este include:

#include <hbapifs.h>

En el código en C (no en el PRG). Si usas una sección #pragma BEGINDUMP #pragma ENDDUMP, ese include tiene que ir dentro de esa sección

Re: Migrando de FWH 32 a FWH 64 - windows.h

PostPosted: Sun Jan 04, 2015 10:50 pm
by Antonio Linares
Este es el prototipo de InternetReadFile():

Code: Select all  Expand view
BOOL InternetReadFile(
  _In_   HINTERNET hFile,
  _Out_  LPVOID lpBuffer,
  _In_   DWORD dwNumberOfBytesToRead,
  _Out_  LPDWORD lpdwNumberOfBytesRead
);


http://msdn.microsoft.com/en-us/library/windows/desktop/aa385103%28v=vs.85%29.aspx

En tu código:
BOOL lSuccess = InternetReadFile( ( HINTERNET ) hb_parnl( 1 ), ( LPVOID ) hb_parc( 2 ), hb_parclen( 2 ), &nBytesRead );

Comprueba que nBytesRead este definido como un DWORD

Re: Migrando de FWH 32 a FWH 64 - windows.h

PostPosted: Sun Jan 04, 2015 10:52 pm
by Antonio Linares
En vez de strcpy() añade este prototipo al comienzo de tu fichero en C:

char * fw_strcpy( char * s1, const char * s2 );

y cambia strcpy() por fw_strcpy()

Re: Migrando de FWH 32 a FWH 64 - windows.h

PostPosted: Mon Jan 05, 2015 7:51 pm
by Verhoven
Antonio,
Algo no va bien, con esas modificaciones arroja los siguientes errores:
Code: Select all  Expand view
Generating C source output to 'wintpv.c'... Done.
wintpv.c
internet.prg(458) : warning C4047: 'function' : 'HB_USHORT' differs in levels of indirection from 'char [2]'
internet.prg(458) : warning C4024: 'hb_fsOpen' : different types for formal and actual parameter 2
internet.prg(458) : warning C4047: '=' : 'FILE *' differs in levels of indirection from 'HB_FHANDLE'
internet.prg(529) : warning C4047: 'function' : 'HB_USHORT' differs in levels of indirection from 'char [2]'
internet.prg(529) : warning C4024: 'hb_fsOpen' : different types for formal and actual parameter 2
internet.prg(529) : warning C4047: '=' : 'FILE *' differs in levels of indirection from 'HB_FHANDLE'
internet.prg(591) : warning C4047: 'function' : 'HB_USHORT' differs in levels of indirection from 'char [2]'
internet.prg(591) : warning C4024: 'hb_fsOpen' : different types for formal and actual parameter 2
internet.prg(591) : warning C4047: '=' : 'FILE *' differs in levels of indirection from 'HB_FHANDLE'
internet.prg(773) : warning C4267: 'function' : conversion from 'size_t' to 'int', possible loss of data

tokh.prg(2907) : warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

tokh.prg(2952) : warning C4996: 'strtok': This function or variable may be unsafe. Consider using strtok_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

Copyright (C) Microsoft Corporation.  All rights reserved.

wintpv.obj : error LNK2001: unresolved external symbol HB_FUN_HB_FSOPEN
wintpv.obj : error LNK2019: unresolved external symbol fw_strcpy referenced in function HB_FUN_CHK_INTERNET
wintpv.exe : fatal error LNK1120: 2 unresolved externals
* Linking errors *
 


El código con las rectificaciones que me has dado ha quedado como sigue:
Code: Select all  Expand view
#define _WINSOCK_DEPRECATED_NO_WARNINGS  // Para evitar warnings relativos a WinSock. Fuente info:  Microsoft.
#include <hbapifs.h>
#include <stdio.h>
#include <ws2tcpip.h>    //Equivalente actualizado de #include <winsock2.h>

char * fw_strcpy( char * s1, const char * s2 );

HB_FUNC( CHK_INTERNET )
{
    WSADATA wsa;
    char *hostname = (char *) hb_parc(1); //char *hostname = hb_parc(1);
    char ip[100];
    struct hostent *he;
    struct in_addr **addr_list;
    int i;
     
    //printf("\nInitialising Winsock...");
    if (WSAStartup(MAKEWORD(2,2),&wsa) != 0)
        //printf("Failed. Error Code : %d",WSAGetLastError());
        hb_retni(1); //return 1;
      else {
        //printf("Initialised.\n");
        if ( (he = gethostbyname( hostname ) ) == NULL)
           //gethostbyname failed
           //printf("gethostbyname failed : %d" , WSAGetLastError());
           hb_retni(2); //return 1;
          else {
           //Cast the h_addr_list to in_addr , since h_addr_list also has the ip address in long format only
           addr_list = (struct in_addr **) he->h_addr_list;
     
           for(i = 0; addr_list[i] != NULL; i++)
              { //Return the first one;
                fw_strcpy(ip , inet_ntoa(*addr_list[i]) );
              }
              //printf("%s resolved to : %s\n" , hostname , ip);
              hb_retni(0); //return 0;
           }
        }
    WSACleanup();
}

Re: Migrando de FWH 32 a FWH 64 - windows.h

PostPosted: Mon Jan 05, 2015 8:41 pm
by Antonio Linares
Paz,

Puedes mostrarme el código en donde se llama a hb_fsOpen() ?

gracias

Re: Migrando de FWH 32 a FWH 64 - windows.h

PostPosted: Mon Jan 05, 2015 9:23 pm
by Verhoven
El código es el siguiente:
Code: Select all  Expand view
#include "ws2tcpip.h"  //For WinSock 2 library: ws2_32.lib
#include "wininet.h"
#include "windows.h"
#include <hbapifs.h>
#include "hbapi.h"
#include "stdio.h"
#include "WinBase.h"

//Devuelve el nombre del último fichero modificado según una máscara en un directorio FTP.
HB_FUNC( FTPLASTFILEINDIR )  //Método por el último nombre en el listado obtenido.
{   
    WIN32_FIND_DATA ultdir;
    WIN32_FIND_DATA dirtemp;
    SYSTEMTIME stUTC;
    HINTERNET FtpHandle;
   
    FILE *fichero;
    //HB_FHANDLE fichero;
    char nombre[12] = "LISTFTP.DAT";
   
    fichero = hb_fsopen( nombre, "w" );

    //fichero = fopen( nombre, "w" );
   ...

Re: Migrando de FWH 32 a FWH 64 - windows.h

PostPosted: Mon Jan 05, 2015 9:42 pm
by Verhoven
Y otra cosa más que me gustaría dejar resañada es que para que el programa en 64 bits no se quede colgado al salir, tengo que comentar todas las líneas del siguiente código que venía usando para 32 bits sin problemas con BCC63 y BCC582:
Code: Select all  Expand view
// Esta función es llamada automáticamente por oWnd:end() o por la X de la ventana principal.
EXIT PROCEDURE KillApp()
  // Escribe en .INI lo que corresponda.
  // Decrementa el número de usuarios.
  // Cierra las DLL's.
     //freelibrary("nviewlib.dll")
     //freelibrary("avicap32.dll")
  // Cierra los recursos.
    // ResAllFree() Innecesario a partir de los 32 bits
  // Cierra las bases de datos.
     //CLOSE DATABASES
  // Libera la memoria.
     //CLEAR MEMORY
  //set RESOURCES TO  //Solo si se usan recursos en dll.
return

Re: Migrando de FWH 32 a FWH 64 - windows.h

PostPosted: Mon Jan 05, 2015 10:22 pm
by Antonio Linares
Paz,

Cambia esta línea:

fichero = hb_fsopen( nombre, "w" );

por

fichero = hb_fsopen( nombre, FO_WRITE );

tienes que añadir este fichero de cabecera:

#include <fileio.ch>

Re: Migrando de FWH 32 a FWH 64 - windows.h

PostPosted: Mon Jan 05, 2015 10:24 pm
by Antonio Linares
Paz,

Verhoven wrote:Y otra cosa más que me gustaría dejar resañada es que para que el programa en 64 bits no se quede colgado al salir, tengo que comentar todas las líneas del siguiente código que venía usando para 32 bits sin problemas con BCC63 y BCC582:
Code: Select all  Expand view
// Esta función es llamada automáticamente por oWnd:end() o por la X de la ventana principal.
EXIT PROCEDURE KillApp()
  // Escribe en .INI lo que corresponda.
  // Decrementa el número de usuarios.
  // Cierra las DLL's.
     //freelibrary("nviewlib.dll")
     //freelibrary("avicap32.dll")
  // Cierra los recursos.
    // ResAllFree() Innecesario a partir de los 32 bits
  // Cierra las bases de datos.
     //CLOSE DATABASES
  // Libera la memoria.
     //CLEAR MEMORY
  //set RESOURCES TO  //Solo si se usan recursos en dll.
return


Sería muy útil que descomentes una a una esas lineas y vayas probando hasta que localices cual de ellas exatamente es la que provoca el error.

Gracias! :-)

Re: Migrando de FWH 32 a FWH 64 - windows.h

PostPosted: Tue Jan 06, 2015 8:25 am
by Verhoven
Antonio,
Aunque incluyamos en la parte C ese <fileio.ch> como sigue
Code: Select all  Expand view
// Para VSC2013.
#include "warningsVSC2013.h"

#include "ws2tcpip.h"  //For WinSock 2 library: ws2_32.lib
#include "wininet.h"
#include "windows.h"

#include <hbapifs.h>
#include <fileio.ch>

#include "hbapi.h"
#include "stdio.h"
#include "WinBase.h"

//Devuelve el nombre del último fichero modificado según una máscara en un directorio FTP.
HB_FUNC( FTPLASTFILEINDIR )  //Método por el último nombre en el listado obtenido.
{   
    WIN32_FIND_DATA ultdir;
    WIN32_FIND_DATA dirtemp;
    SYSTEMTIME stUTC;
    HINTERNET FtpHandle;
   
    FILE *fichero;
    //HB_FHANDLE fichero;
    char nombre[12] = "LISTFTP.DAT";
   
    //fichero = fopen( nombre, "w" );
    fichero = hb_fsopen( nombre, FO_WRITE );


Continúa dando el error:
Code: Select all  Expand view
Generating C source output to 'wintpv.c'... Done.
wintpv.c
internet.prg(462) : warning C4013: 'hb_fsopen' undefined; assuming extern returning int
internet.prg(462) : warning C4047: '=' : 'FILE *' differs in levels of indirection from 'int'
internet.prg(778) : warning C4267: 'function' : conversion from 'size_t' to 'int', possible loss of data
Microsoft (R) Windows (R) Resource Compiler Version 6.3.9600.17298

Copyright (C) Microsoft Corporation.  All rights reserved.


wintpv.obj : error LNK2019: unresolved external symbol hb_fsopen referenced in function HB_FUN_FTPLASTFILEINDIR
wintpv.exe : fatal error LNK1120: 1 unresolved externals
* Linking errors *