views:

293

answers:

1

Hello, I don't know why but today myOpenID doesn't seem to work. Anyway ... I have this problem: I have a unmanaged C++ library (DLL) which I have to embed in an existing C# project. Now ... I have created a mini-wrapper (DLL) in managed C++ which calls the library so that I can load it from the C# code and, when I try it from a command-line C# project, it perfectly works, right results, right behavior ecc.

Now, when I load it in the real project, it starts giving me strange System.AccessViolationException coming from the mini-wrapper DLL. I am not experienced in C#, nor in general manged/unmanaged C++ development under Windows, and I just can't understand why should this work from a C# project, and not work from another.

More information: the original library uses OGRE3D rendering engine to do calculations, and the project in which I have to use this library uses OGRE under the hood, could this cause problems?

Any suggestions?

+1  A: 

Here are some ideas for you to try sir...

  1. It's hard to know whats going on exactly but the first thing I would try to do is remove this managed c++ dll from the mix. It might be confusing things. Somewhere here this feels like data is not being marshalled correctly between the managed and unmanaged world. Also, just because it doesn't crash from the console, doesn't necesarilly mean the code is working correctly, it could still be breaking, just not in a way thats triggering an access violation. The first thing I would look at is using p/invoke to call your unmanaged dll directly, if it breaks, you should know pretty quickly:

    Calling Win32 DLLs in C# with P/Invoke

  2. It could be that somewhere in the mix, this pointer is being moved to a different address space where that pointer makes no sense. Are there any process boundaries here?

Steve Sheldon