freeMXF.org
http://freemxf.org/forum/

c# dll trouble
http://freemxf.org/forum/viewtopic.php?f=2&t=112
Page 1 of 1

Author:  Pardus [ Mon Oct 22, 2007 2:16 pm ]
Post subject:  c# dll trouble

Hi,

I’m currently working on a project where I should write a dll that allows us to extract metadata from an MXF file. This dll should be accessed by an application written in c#.
I’ve written a wrapper around mxflib in c++ to retrieve the requested information and I’ve also provided a function that can be accessed from the c# application.
To test the library I’ve written a small application in c++ that calls this function and dumps the output to stdout. This application works as expected.
When I try to do the same from within c# I receive an error:

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.


I’ve traced it down ( it occurs in the ScanRIP() function) to the line

mxffile.h line 395

Code:
template<class TP, class T> /*inline*/ TP mxflib::MXFFile__ReadObjectBase(MXFFilePtr This, PrimerPtr UsePrimer /*=NULL*/)
{
   TP Ret;

   UInt64 Location = This->Tell();
   ULPtr Key = This->ReadKey();

   // If we couldn't read the key then bug out
   if(!Key) return Ret;

   // Build the object (it may come back as an "unknown")
395:   Ret = new T(Key);


Where T is a Partition. So it happens during the contruction of a Partition Object.

My code (simplified) is:

Code:
extern "C" __declspec(dllexport) _mxfdata Getmxfdata(char* filepath)
{
   MXFFilePtr mxfFile = new MXFFile();
   mxfdata_t mxfData;
   
#ifdef COMPILED_DICT
   LoadDictionary(DictData);
#else
   LoadDictionary("dict.xml");
#endif
   

   if (!mxfFile->Open(filepath, true))
   {
      perror(filepath);
      error("Unable to open file\n");
      exit(1);
   }

   mxfFile->GetRIP();

   …

   return mxfData;
}


Has anyone else tried the same?
Does someone have an idea on what could be the culprit of my problem?


Thanks,
P.

Author:  Pardus [ Mon Oct 22, 2007 3:19 pm ]
Post subject: 

I found the answer to my problem (took me the better part of a day to find it due to the clear error description :( ).
I retraced my steps an I found I forgot to copy the dict.xml file to my application directory.
My dll works like a charm now. :D
Thanks for providing us with this wonderfull library.

Author:  gino [ Thu Jul 28, 2011 12:32 pm ]
Post subject:  Re: c# dll trouble

Dear Sir,

Is it possible to receive your DLL and source code. :idea:

I want to do an MXF project but I don't know c++ :shock:

Many thanks,

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/