473,408 Members | 2,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

dll function exception - Attempted to read or write protected memory.

I am attempting to execute a function in a C dll (R.dll) as follows:

[DllImport("c:\\Program Files\\R\\R-2.10.1\\bin\\R.dll")]
public static unsafe extern int Rf_mkCharLenCE(string str, int len, uint ceType);

,,,


string test = "Hello";
int r=0;
try
{
r = Rf_mkCharLenCE(test, test.Length, (uint)cetype_t.CE_UTF8);
}
catch (Exception ex)
{
System.Console.WriteLine(ex.StackTrace);
}


which throws System.AccessViolationException - Attempted to read or write protedted memory.

The signature of Rf_mkCharLenCE in the c code is:

SEXP Rf_mkCharLenCE(const char *, int, cetype_t);

where SEXP is a pointer to a S-Expression struct and cetype_t is an uint.

It doesn't matter how the return type is specified. I have tried int, IntPtr, and void*.

Yes, allow unsafe code is checked.

What can I do to fix?

Russ
Apr 21 '10 #1
0 1205

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Pieter | last post by:
Hi, Since 10 days (the first time was the 10th of november) I have some weird exception happening in an application here: All (except 1 of the total of 5) users had this error now 1 of 2 times...
1
by: Lee | last post by:
Hi all, been playing with some code overriding WndProc to get information about mouse events. So far I've tried to capture when the left mouse button is pressed using the code below. Sometimes...
1
by: Bruce | last post by:
I am getting the following exception in the release build of my assembly. {"Attempted to read or write protected memory. This is often an indication that other memory is...
1
by: =?Utf-8?B?QmFkaXM=?= | last post by:
Hi, I'm using automation to produce word documents, and it's working fine in my machine that have vs.net 2005 and office xp in it. BUT when I move my application to another machine that have...
1
by: =?Utf-8?B?QmFkaXM=?= | last post by:
Hi, I'm using automation to produce word documents, and it's working fine in my machine that have vs.net 2005 and office xp in it. BUT when I move my application to another machine that have...
6
by: Sugandh Jain | last post by:
Hi, I am getting the error message Attempted to read or write protected memory. This is often an indication that other memory is corrupt. It was not coming until yet, for around 2 months. Now,...
0
by: Mike | last post by:
How can i handle "attempted to read or write protected memory. this is often an indication that other memory is corrupt" I use VS 2005 framework 2.0 On the server explorer window I try to open...
1
by: Sudhan | last post by:
hi i am trying to write excel using VB.net but when i open oExcel.Workbooks.Open the application error: Attempted to read or write protected memory. This is often an indication that other memory...
3
by: sriram347 | last post by:
Hi I am a newbie to ASP.NET. I developed a web page (project type is web application) and I keep getting this error. B]Error message : "System.AccessViolation Exception attempted to read or...
0
by: mikomty | last post by:
I get the following error message when trying to write/read to a Data Acquisition Switch Unit 34970A using IEEE. Attempted to read or write protected memory issue. This is often an indication that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.