开发者

Access Violation Exception

I am having some strange problem. I hav开发者_开发问答e written a small module in VC++ using OpenCV.

It works fine. The code aggregates feed from the CCTV camera connected to the USB port.

however, I had to write the rest of my application in C#, so I made a DLL of the VC++ code and called the VC++ method from C#.

Now, I have ended up getting an error

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

Can anyone please suggest me any solution to this. Is there any Access Violation while accessing it in a managed code?


If TrackBlob returns a string, you should be able to define your dllimport as such:

[DllImport("Tracking.dll", EntryPoint = "TrackIt")] 
public extern static string TrackBlob();

and skip trying to marshal it.

By returning it as an IntPtr, you're trying to get a pointer into memory owned by the unmanaged DLL... returning it as a string will return a copy of the string for you to work with.

Let me know if that works! James

* Edit *

Try one of these:

[DllImport("Tracking.dll", EntryPoint = "TrackIt")] 
public extern static [MarshalAs(UnmanagedType.BStr)] string TrackBlob();

or

[DllImport("Tracking.dll", EntryPoint = "TrackIt")] 
public extern static [MarshalAs(UnmanagedType.AnsiBStr)] string TrackBlob();

Check out this MSDN link on string marshalling:
http://msdn.microsoft.com/en-us/library/s9ts558h.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜