Click here to Skip to main content
15,909,656 members
Home / Discussions / C#
   

C#

 
AnswerRe: Uploading Excel sheet data into SQl problem Pin
sujithkumarsl30-Mar-07 19:30
sujithkumarsl30-Mar-07 19:30 
QuestionHow to find the Current Path, in Windows Application Pin
pashitech30-Mar-07 18:32
pashitech30-Mar-07 18:32 
AnswerRe: How to find the Current Path, in Windows Application Pin
Muammar©30-Mar-07 19:53
Muammar©30-Mar-07 19:53 
AnswerRe: How to find the Current Path, in Windows Application Pin
Stefan Troschuetz30-Mar-07 21:26
Stefan Troschuetz30-Mar-07 21:26 
GeneralRe: How to find the Current Path, in Windows Application Pin
Wayne Phipps31-Mar-07 0:25
Wayne Phipps31-Mar-07 0:25 
AnswerRe: How to find the Current Path, in Windows Application Pin
Noman Aftab31-Mar-07 0:41
Noman Aftab31-Mar-07 0:41 
GeneralRe: How to find the Current Path, in Windows Application Pin
Wayne Phipps31-Mar-07 1:14
Wayne Phipps31-Mar-07 1:14 
Question"Attempted to read or write protected memory." Pin
User 137680030-Mar-07 14:26
User 137680030-Mar-07 14:26 
Hi all,
I've asked this question before, but didn't receive a response, so I'm posting it again but with more info which should HOPEFULLY help someone tell me what I'm doing wrong.
I am trying to use a DLL that modifies a stream of bytes (basically it's an encryption/decryption DLL). This DLL comes from someone else and I have to use it "as is" (no way to modify it).
The DLL reads and writes to a byte array (reads encrypted data, writes decrypted data), and this is giving me the error "Attempted to read or write protected memory."
I think the problem is quite simply that I don't understand how C# handles this kind of thing, so was wondering if I could get a little help.
The code goes something like this:
[DllImport("ABCdecrypt.dll", EntryPoint = "ABCdecrypt", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
unsafe public static extern bool ABCdecrypt([MarshalAs(UnmanagedType.I4)] int type, byte* data, int datalength);

private void buttonGo_Click(object sender, EventArgs e)
{
  byte[] yData = File.ReadAllBytes(textBoxInput.Text);
  unsafe
  {
    fixed (byte* pBuf = &yData[0])
    {
    ABCdecrypt(100, pBuf, yData.Length); //This is where it fails
    File.WriteAllBytes(textBoxOutput.Text, yData);
    }
  }
  MessageBox.Show("Done");
  }

If it helps, the sample code I was given for C++ looks like:
BYTE data[] = {'1','2','3','4','5','6','7','8'};
int type = 100;
int bufsize = (sizeof(data)+8) & ~7;
PBYTE pBuf = new BYTE[bufsize];
memcpy(pBuf,(LPCSTR)data, sizeof(data));
ABCdecrypt(type, pBuf, &bufsize);
delete pBuf;

And the reference document says the call should be:
<br />
ABCDecrypt(int type, LPBYTE data, int* datalength);<br />


If I'm not being clear, please ask me to clarify. Essentially, all I want to do is use the library to decrypt the file referred to by textBoxInput.Text and save it out as the file referred to by textBoxOutput.Text
AnswerRe: "Attempted to read or write protected memory." Pin
Dewald31-Mar-07 0:03
Dewald31-Mar-07 0:03 
GeneralRe: "Attempted to read or write protected memory." Pin
User 137680031-Mar-07 5:55
User 137680031-Mar-07 5:55 
QuestionUser control without being in the GAC Pin
Esmo200030-Mar-07 12:36
Esmo200030-Mar-07 12:36 
AnswerRe: User control without being in the GAC Pin
J$30-Mar-07 13:32
J$30-Mar-07 13:32 
Questionhow to invisible a row of Datagridview ? Pin
hdv21230-Mar-07 11:27
hdv21230-Mar-07 11:27 
Questionhow can I get the lighter tone of color Pin
samreengr830-Mar-07 11:24
samreengr830-Mar-07 11:24 
AnswerRe: how can I get the lighter tone of color Pin
led mike30-Mar-07 12:00
led mike30-Mar-07 12:00 
AnswerRe: how can I get the lighter tone of color Pin
Kitchen_31-Mar-07 2:21
Kitchen_31-Mar-07 2:21 
AnswerRe: how can I get the lighter tone of color Pin
Thomas Stockwell1-Apr-07 4:36
professionalThomas Stockwell1-Apr-07 4:36 
QuestionMoving DataRows from one DataTable to another Pin
Pualee30-Mar-07 10:48
Pualee30-Mar-07 10:48 
AnswerRe: Moving DataRows from one DataTable to another Pin
gauthee30-Mar-07 20:18
gauthee30-Mar-07 20:18 
QuestionHow to make one column of ListView invisable? Pin
Khoramdin30-Mar-07 10:43
Khoramdin30-Mar-07 10:43 
AnswerRe: How to make one column of ListView invisable? Pin
led mike30-Mar-07 12:01
led mike30-Mar-07 12:01 
GeneralRe: How to make one column of ListView invisable? Pin
Khoramdin30-Mar-07 19:32
Khoramdin30-Mar-07 19:32 
GeneralRe: How to make one column of ListView invisable? Pin
led mike2-Apr-07 4:27
led mike2-Apr-07 4:27 
QuestionStreamreader and read file Pin
Saamir30-Mar-07 10:35
Saamir30-Mar-07 10:35 
AnswerRe: Streamreader and read file Pin
Dave Kreskowiak30-Mar-07 11:53
mveDave Kreskowiak30-Mar-07 11:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.