Re: C# - Interop causing AccessViolationException
- From: "Stephen Cawood" <cawood@xxxxxxxxxx>
- Date: Sun, 11 Jun 2006 16:13:20 GMT
thanks, but the result was the same.
in the function that works, one of the parameters is an empty byte array
that is passed by reference and populated with binary data in the C
function. that binary data is then used in the C# code to produce an image.
in this new function, a pointer to an existing byte array is passed to the
function the byte array is then used within the function - presumably
reading this byte array is causing the error. but I don't know why.
"Michael Phillips, Jr." <mphillips53@xxxxxxxxxxxxxxx> wrote in message
news:u7RX2WWjGHA.1276@xxxxxxxxxxxxxxxxxxxxxxx
Try this:
C++ Wrapper
-----------------------------------------------
WRAPPER_API void find_objects_wrapped(void* rgb_cam_image, char
rgb_greybar)
{
unsigned char* ptrImage = (unsigned char*)rgb_cam_image;
return find_objects(ptrImage, rgb_greybar);
}
C# code
-----------------------------------------------
[DllImport("Wrapper.dll", EntryPoint="find_objects_wrapped")]
public static extern void find_objects_wrapped([In] IntPtr rgb_cam_image,
char rgb_greybar);
unsafe
{
// Get pointer to frame - using SharperCV wrapped for OpenCV
IntPtr cam_image = ImageFrame.getPixelAddr(0, 0, 0);
char rgb_greybar = (char)1;
find_objects_wrapped(cam_image, rgb_greybar);
}
"Stephen Cawood" <cawood@xxxxxxxxxx> wrote in message
news:wZKig.31805$I61.25270@xxxxxxxxxxx
thanks in advance...
while trying to pass an IntPtr into a wrapper DLL, I'm getting an
AccessViolationException: "Attemped to read or write from protected
memory"
I'm using another function in a similar way (except that one passes in
the pointer by ref) and that one is working fine (thanks to this group,
of course).
any ideas?
from the C header file:
-----------------------------------------------
void find_objects(unsigned char *rgb_cam_image, char rgb_greybar);
C++ Wrapper
-----------------------------------------------
WRAPPER_API void find_objects_wrapped(unsigned char* rgb_cam_image, char
rgb_greybar)
{
unsigned char* ptrImage = NULL;
ptrImage = (unsigned char*)GlobalLock(rgb_cam_image);
return find_objects(ptrImage, rgb_greybar);
}
C# code
-----------------------------------------------
[DllImport("Wrapper.dll", EntryPoint="find_objects_wrapped")]
public static extern void find_objects_wrapped([In] IntPtr rgb_cam_image,
char rgb_greybar);
unsafe
{
// Get pointer to frame - using SharperCV wrapped for OpenCV
IntPtr cam_image = ImageFrame.getPixelAddr(0, 0, 0);
char rgb_greybar = (char)1;
find_objects_wrapped(cam_image, rgb_greybar);
}
.
- Follow-Ups:
- Re: C# - Interop causing AccessViolationException
- From: Michael Phillips, Jr.
- Re: C# - Interop causing AccessViolationException
- References:
- C# - Interop causing AccessViolationException
- From: Stephen Cawood
- Re: C# - Interop causing AccessViolationException
- From: Michael Phillips, Jr.
- C# - Interop causing AccessViolationException
- Prev by Date: Re: C# - Interop causing AccessViolationException
- Next by Date: Re: Using the DecryptFile API
- Previous by thread: Re: C# - Interop causing AccessViolationException
- Next by thread: Re: C# - Interop causing AccessViolationException
- Index(es):
Relevant Pages
|