1 Replies Last post: Jun 5, 2006 6:00 PM by Serge Piletsky  
Rakesh Prajapati   1 posts since
Apr 24, 2006
Currently Being Moderated

Jun 1, 2006 1:39 PM

Exception c0000005, at 0308CC49

Hi,

 

I am getting following error while accessing C code from java using JNIWrapper.

 

Exception c0000005, at 0308CC49

Access violation: attempting to write memory at address 00000000

Native function stack data: 0,3451168,348a778,34d45e0,3000c,30e0167,83ec8b55,458d0cec,f4458908,51fc4d8d,52f8558d,9d996068,f4458b00,1170b950,d1ff1000,5010c483

Exception in thread "Thread-10002" com.jniwrapper.FunctionExecutionException: c0000005

     at com.jniwrapper.Function.invokeCFunc(Native Method)

     at com.jniwrapper.FunctionCall.a(SourceFile:100)

     at com.jniwrapper.FunctionCall.call(SourceFile:31)

     at com.jniwrapper.Function.invoke(SourceFile:160)

     at com.jniwrapper.Function.invoke(SourceFile:211)

     at com.coi.xfind.server.xtract.textExtractor.OIExtractor.extractToDir(OIExtractor.java:153)

     at com.coi.xfind.server.xtract.textExtractor.TextExtractor.oiExtractFile(TextExtractor.java:201)

     at com.coi.xfind.server.xtract.textExtractor.TextExtractor.extractFile(TextExtractor.java:153)

     at com.coi.xfind.server.xtract.textExtractor.TextExtractor.extract(TextExtractor.java:96)

     at com.coi.xfind.server.xtract.textExtractor.ExtractionWorkerImpl.extract(ExtractionWorkerImpl.java:206)

     at com.coi.xfind.server.xtract.textExtractor.ExtractionWorkerImpl.run(ExtractionWorkerImpl.java:124)

     at java.lang.Thread.run(Unknown Source)

 

C function is as follows:

 

OIEXTRACT_API long __stdcall extractToDirW(LPCWSTR source, LPCWSTR outDir, pcbFunc cbFunc)

{

     DWORD dwAttrs;

     dwAttrs = GetFileAttributes( source );

     if ( dwAttrs == INVALID_FILE_ATTRIBUTES ) {

          return FILENOTACCESSABLE;

     }

 

     OutsideIn* pOI = new OutsideIn( source, outDir, cbFunc );

     DAERR err = pOI->extract();

     delete pOI;

 

     return err;

}

---

and the java  code is :

 

import java.util.ResourceBundle;

 

import com.jniwrapper.Function;

import com.jniwrapper.Library;

import com.jniwrapper.LongInt;

import com.jniwrapper.Pointer;

import com.jniwrapper.ULongInt;

import com.jniwrapper.WideString;

 

 

public class OIExtractor extends ExtractorBase

{

 

     private static final int OITIMEOUT = 30;

     private static final String libName = "oiextract";

     private static final String oiCreateBaseDocPropsFunctionName = "createBaseDocPropsW";

     private static final String oiErrorStringFunctionName = "getOIErrorStringW";

     private static final String oiFileInfoFunctionName = "getFileInfoW";

     private static final String oiExtractToDirFunctionName = "extractToDirW";

 

     private static Library lib = null;

     private static Function createBaseDocProps = null;

     private static Function getOIErrorString = null;

     private static Function getFileInfo = null;

     private static Function extractToDir = null;

 

     private static boolean isInitinalized = false;

     private static ResourceBundle fileTypeNames = null;

 

     private static void initialize() {

          

          if ( !isInitinalized ) {

               lib = new Library( libName );

               createBaseDocProps = lib.getFunction( oiCreateBaseDocPropsFunctionName );

               getFileInfo = lib.getFunction( oiFileInfoFunctionName );

               getOIErrorString = lib.getFunction( oiErrorStringFunctionName );

               extractToDir = lib.getFunction( oiExtractToDirFunctionName );

               isInitinalized = true;

          }

     }

 

     public static void createBaseDocProps( String filePath, String outDir ) throws IOExtractionException, ExtractionException, MemoryAllocationException

     {

 

          if ( !isInitinalized )

               initialize();

 

          LongInt ret = new LongInt();

          WideString sourceFilePath = new WideString( filePath );

          WideString outDirPath = new WideString( outDir );

          createBaseDocProps.invoke( ret, sourceFilePath, outDirPath );

          long result = ret.getValue();

          if ( result < 0 ) {

               if ( result == FILENOTACCESSABLE )

                    throw new IOExtractionException(

                         "extractor componente could not access file: " + filePath );

               else if ( result == FILECREATEERROR )

                    throw new IOExtractionException(

                         "extractor componente could not create file in output dir: " + outDir );

               else

                    throw new ExtractionException( "unknown error while retrieving base properties for file: "

                         + filePath );

          }

 

          return;

     }

     

     private static String getOIErrorString( long errorCode ) throws MemoryAllocationException, OIExtractionException {

          

          if ( !isInitinalized )

               initialize();

 

          LongInt ret = new LongInt();

          LongInt daErr = new LongInt( errorCode );

          WideString errMsg = new WideString( 512 );

          getOIErrorString.invoke( ret, daErr, errMsg, new ULongInt( 512 ) );

          long result = ret.getValue();

          if ( result == MEMORYALLOCATIONERROR ) {

               throw new MemoryAllocationException(

                    "oiextractor componente could not allocate enough memory for retrieving detailed error message" );

          } else if ( result != 0 ) {

               throw new OIExtractionException( "error while receiving message form oiextraction component" );

          }

          

          return errMsg.getValue();

     }

 

     

     public static long getFileID( String filePath ) throws IOExtractionException, OIExtractionException, MemoryAllocationException {

          

          if ( !isInitinalized )

               initialize();

 

          LongInt ret = new LongInt();

          ULongInt fileID = new ULongInt();

          Pointer pFileID = new Pointer( fileID );

          WideString source = new WideString( filePath );

          getFileInfo.invoke( ret, source, pFileID);

          long result = ret.getValue();

          if ( result != 0 ) {

               if ( result < 0 ) {

                    if ( result == FILENOTACCESSABLE ) {

                         throw new IOExtractionException(

                              "oiextractor componente could not access file: " + filePath );

                    } else {

                         throw new OIExtractionException( "unknown error while retrieving file id for file: "

                                   + filePath );

                    }

               } else {

                    throw new OIExtractionException( "error while processing file: " + filePath + " error: "

                         + getOIErrorString( result ) );

               }

          }

 

          return fileID.getValue();

     }

     

     

     public static String getFileIDName( String fileID ) {

     

          if ( fileTypeNames == null ) {

               fileTypeNames = ResourceBundle.getBundle( "com.coi.xfind.server.textExtractor.oifiletypenames" );

          }

 

          return fileID + " (" + fileTypeNames.getString( fileID ) +")";

     }

     

     public static String getFileIDName( long fileID ) {

          

          String strID = String.valueOf( fileID );

          

          return getFileIDName( strID );

     }

 

     public static void extractToDir( String fileToExtract, String outDir, ExtractionCallBack ecb ) throws IOExtractionException, TimeoutException, OIExtractionException, MemoryAllocationException, CancelException

     {

          if ( !isInitinalized )

               initialize();

 

          LongInt ret = new LongInt();

          WideString source = new WideString( fileToExtract );

          WideString destination = new WideString( outDir );

          ecb.startTimeoutTask( OITIMEOUT );

          ExtractorBase.AbortCallBack abortCallback = new ExtractorBase.AbortCallBack( ecb );

          extractToDir.invoke( ret, source, destination, abortCallback );

          ecb.stopTimeoutTask();

          abortCallback.dispose();

          long result = ret.getValue();

          if ( result != 0 ) {

               if ( result < 0 ) {

                    if ( result == FILENOTACCESSABLE )

                         throw new IOExtractionException(

                              "extractor componente could not access file: " + fileToExtract );

                    else if ( result == FILECREATEERROR )

                         throw new IOExtractionException(

                              "extractor componente could not create output files for extracting file: " + fileToExtract );

                    else if ( result == MEMORYALLOCATIONERROR )

                         throw new MemoryAllocationException(

                              "extractor componente could not allocate enough memory for extraction file: "

                              + fileToExtract );

                    else if ( result == TIMEOUT )

                         throw new TimeoutException(

                              "extractor componente has reached timeout while extracting file: "

                              + fileToExtract );

                    else if ( result == CANCEL )

                         throw new CancelException(

                              "extraction was canceled while extracting file: "

                              + fileToExtract );

                    else

                         throw new OIExtractionException( "unknown error while processing file: "

                              + fileToExtract );

               } else {

                    throw new OIExtractionException( "error while processing file: " + fileToExtract + " error: "

                         + getOIErrorString( result ) );

               }

          }

 

          return;

     }

}

 

 

Thanks

Rakesh

 

Serge Piletsky TeamDev Ltd. 670 posts since
Apr 24, 2006
Currently Being Moderated
1. Jun 5, 2006 6:00 PM in response to: Rakesh Prajapati
Re: Exception c0000005, at 0308CC49

Hi Rakesh,

 

Since the sample Java code that you provided us with is incomplete (there are several missing classes, for example ExtractionCallBack, ExtractorBase.AbortCallBack etc.), I can only suppose where the problem is. The "Exception c0000005, at 0308CC49 Access violation: attempting to write memory at address 00000000" can indicate that you have specified incorrect or invalid parameters for this native function and it failed afterwards. Also, it is possible that either parameters of a callback (AbortCallBack) or its calling convention is incorrect.

 

Apparently, this exception indicates that an error has occurred in your native function, and since you have the C source of this function you can add additional logging into it to find out what can cause such error and in which line of the code it happens.

 

More Like This

  • Retrieving data ...