comp.lang.ada
 help / color / mirror / Atom feed
* Problem using DLLTOOL that comes with GNAT 3.10p for Windows NT
@ 1998-06-05  0:00 Fabrizio Castrotorres
  0 siblings, 0 replies; only message in thread
From: Fabrizio Castrotorres @ 1998-06-05  0:00 UTC (permalink / raw)



     I'm trying to produce an import library to use with GNAT 3.10p for 
     Windows NT from a DLL I created using the DLLTOOL that comes with 
     GNAT. I used the commandline
     
     dll2def nt_sequential_io.dll nt_sequential_io.def
     
     dlltool --dllname nt_sequential_io.dll --def nt_sequential_io.def 
     --output-lib libnt_sequential_io.a
     
     Everytime I specify these options it goes into an infinite loop when 
     it calls as.exe and a message saying something about a "exception 
     handler failed" keeps coming up until the "Dr Watson" program comes in 
     and stops it. I created the DLL using Borland C++ 5.02, and can use if 
     from other programs created by this compiler. I am enclosing the C 
     code to see if anyone sees anything wrong with the DLL code.
     
     Thanks for your help.
     
     
     ====================================================================== 
     nt_sequential_io.h
     ====================================================================== 
     #ifndef __NT_SEQUENTIAL_IO__
     #define __NT_SEQUENTIAL_IO__
     
     
     #define FILE_MODE_OUT_FILE     ((BYTE)0x01) 
     #define FILE_MODE_IN_FILE      ((BYTE)0x02) 
     #define FILE_MODE_APPEND_FILE  ((BYTE)0x04)
     
     const BYTE  FILE_ATTRIBUTE_OPEN   = 0x01; 
     const BYTE  FILE_ATTRIBUTE_SHARED = 0x02;
     
     
     const      WORD  EXCEPTION_STATUS_ERROR = 0x0001; 
     //IO_Exceptions.Status_Error;
     const WORD  EXCEPTION_MODE_ERROR   = 0x0002; 
     //IO_Exceptions.Mode_Error;
     const WORD  EXCEPTION_NAME_ERROR   = 0x0004; 
     //IO_Exceptions.Name_Error;
     const WORD  EXCEPTION_USE_ERROR    = 0x0008; 
     //IO_Exceptions.Use_Error;
     const WORD  EXCEPTION_DEVICE_ERROR = 0x0010; 
     //IO_Exceptions.Device_Error;
     const WORD  EXCEPTION_END_ERROR    = 0x0020; 
     //IO_Exceptions.End_Error;
     const WORD  EXCEPTION_DATA_ERROR   = 0x0040; 
     //IO_Exceptions.Data_Error;
     
     
     
     
     typedef struct
     {
        HANDLE Handle;
        DWORD  dwPosition;
        DWORD  dwSize;
        BYTE   bMode;
        BYTE   bAttributes;
        char   lpszPath[MAX_PATH];
        DWORD  nPathLength;
     } FILE_TYPE;
     
     WORD   NT__Open(   FILE_TYPE *hFile, BYTE uFileMode, const char 
     *szFileName );
     WORD   NT__Read(   FILE_TYPE *hFile, LPVOID lpData, DWORD nLength ); 
     WORD   NT__Write(  FILE_TYPE *hFile, LPVOID lpData, DWORD nLength ); 
     WORD   NT__Close(  FILE_TYPE *hFile );
     BYTE   NT__Mode(   FILE_TYPE *hFile ); 
     BOOL   NT__EOF(    FILE_TYPE *hFile );
     
     #endif
     ====================================================================== 
     nt_sequential_io.c
     ====================================================================== 
     //
     // DLL wrapper to access NT I/O
     //
     #include <windows.h>
     #include <string.h>
     #include <stdlib.h>
     #include <stdio.h>
     #include "nt_sequential_io.h"
     
     
     
     BOOL _cdecl _export  NT__Is_Open( FILE_TYPE *File )
     {  return ( File->bAttributes & FILE_ATTRIBUTE_OPEN ); 
     }
     
     WORD _cdecl _export NT__Close( FILE_TYPE *File ) 
     {
        File->dwPosition        = 0L;
        File->dwSize            = 0L;
        File->bMode             = 0;
        File->bAttributes = 0;
        File->nPathLength = 0;
        CloseHandle( File->Handle );
        return 0;
     }
     
     BOOL _cdecl _export NT__EOF( FILE_TYPE *File ) 
     {
     
        return( File->dwPosition == File->dwSize );
     }
     
     
     WORD _cdecl _export NT__Read( FILE_TYPE *File, LPVOID lpData, DWORD 
     nDataLen)
     {
        BOOL bStatus=FALSE;
        WORD wStatus=0;
        DWORD nBytesRead=0;
     
        if ( File->bMode & ( FILE_MODE_OUT_FILE | FILE_MODE_APPEND_FILE ) )
                return( wStatus = EXCEPTION_MODE_ERROR );
     
        bStatus = ReadFile(File->Handle, lpData, nDataLen, &nBytesRead, 
     NULL);
        File->dwPosition += nBytesRead;
     
        if (bStatus && nBytesRead==0) wStatus |= EXCEPTION_END_ERROR; 
        return wStatus;
     }
     
     
     WORD _cdecl _export NT__Write( FILE_TYPE *File, LPVOID lpData, DWORD 
     nDataLen)
     {
        WORD wStatus=0;
        BOOL bStatus=FALSE;
        DWORD nBytesWritten=0;
     
        if (File->bMode & FILE_MODE_IN_FILE)
                return( wStatus = EXCEPTION_MODE_ERROR );
     
        bStatus = WriteFile(File->Handle, lpData, nDataLen, &nBytesWritten, 
     NULL);
        File->dwPosition += nBytesWritten;
        File->dwSize = File->dwPosition;
     
        if (bStatus && nBytesWritten==0) wStatus |= EXCEPTION_END_ERROR; 
        return wStatus;
     }
     
     
     WORD _cdecl _export NT__Open( FILE_TYPE *File, BYTE uFileMode, const 
     char *lpszName)
     {
        WORD            wStatus=0;
        LPTSTR  lpPathFile;
     
        memset( File->lpszPath, 0, MAX_PATH); 
        memset( (void *)File, 0, sizeof(FILE_TYPE));
     
        switch( uFileMode )
        {
                case FILE_MODE_OUT_FILE:
                {
                        File->Handle = CreateFile(
                                lpszName, GENERIC_WRITE, 0, NULL, 
     CREATE_ALWAYS,
                        FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,
                    NULL);
              File->dwPosition = 0;
                File->dwSize     = 0;
                File->bMode      = FILE_MODE_OUT_FILE; 
                }
           break;
     
                case FILE_MODE_IN_FILE:
                        File->Handle = CreateFile(
                                lpszName, GENERIC_READ, 0, NULL, 
     OPEN_EXISTING,
                        FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,
                    NULL);
                        File->dwPosition = 0;
                File->dwSize     = GetFileSize( File->Handle, NULL ); 
                File->bMode      = FILE_MODE_IN_FILE;
           break;
     
                case FILE_MODE_APPEND_FILE:
     
                        File->Handle = CreateFile(
                                lpszName, GENERIC_WRITE, 0, NULL, 
     OPEN_EXISTING,
                        FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,
                    NULL);
     
                File->dwSize     = GetFileSize( File->Handle, NULL );
                        File->dwPosition = File->dwSize;
                File->bMode      = FILE_MODE_APPEND_FILE;
                        SetFilePointer( File->Handle, 0L, NULL, FILE_END);
           break;
        };// end of switch
     
        if ( File->Handle == INVALID_HANDLE_VALUE )
                wStatus |= EXCEPTION_NAME_ERROR;
        else
        {       File->nPathLength = GetFullPathName(
                lpszName, MAX_PATH, File->lpszPath, &lpPathFile);
           if( File->nPathLength > MAX_PATH ) wStatus |=    
     EXCEPTION_NAME_ERROR;
        }
        File->bAttributes |= FILE_ATTRIBUTE_OPEN; 
        return wStatus;
     }





^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1998-06-05  0:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-06-05  0:00 Problem using DLLTOOL that comes with GNAT 3.10p for Windows NT Fabrizio Castrotorres

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox