Sign in to follow this  
jkleinecke

Problem linking unmanaged c++ to c#

Recommended Posts

I'm having a problem calling my unmanaged c++ library from my c# application. I've written some managed c++ wrappers around my unmanaged library, and most of the wrapper works. But on one call I get a read/write protected memory exception. Has anyone else seen this problem?? Is it a common problem or most likely related to my wrapping of unmanaged code?

Share this post


Link to post
Share on other sites
Quote:
Original post by jkleinecke
I'm having a problem calling my unmanaged c++ library from my c# application. I've written some managed c++ wrappers around my unmanaged library, and most of the wrapper works. But on one call I get a read/write protected memory exception.

Has anyone else seen this problem?? Is it a common problem or most likely related to my wrapping of unmanaged code?

It sounds like you tried to dereference a null pointer or something else equally evil. Did you write the library yourself?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Are you trying to write to arrays, etc that are supposed to be const? While I was porting an old C app from Windows 3.11 to Win32, similar problems happened, as the const keyword was used quite haphazardly. Arrays declared as const were sometimes placed in read-only memory in the new environment, and even though they were declared const, they were written to sometimes. Needless to say, this caused quite many headaches as the program crashed when writing to non-writeable memory. I don't know under what circumstances exactly C# would place data in non-writeable memory, but look out for this.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this