Click here to Skip to main content
15,912,021 members
Home / Discussions / C#
   

C#

 
QuestionXML File processing Pin
satsumatable28-Mar-07 17:27
satsumatable28-Mar-07 17:27 
QuestionHow to add Restart Dialog to Installer Pin
remex_1980_junyongwu28-Mar-07 17:13
remex_1980_junyongwu28-Mar-07 17:13 
QuestionSnippets Pin
Mike Hankey28-Mar-07 17:07
mveMike Hankey28-Mar-07 17:07 
QuestionHow to reconnect to the server when the ethernet cable unplugged and replugged using Socket Pin
engsrini28-Mar-07 16:34
engsrini28-Mar-07 16:34 
Questionhow to use the a interface declared in a dll Pin
goldli28-Mar-07 16:21
goldli28-Mar-07 16:21 
AnswerRe: how to use the a interface declared in a dll Pin
wulixu28-Mar-07 17:31
wulixu28-Mar-07 17:31 
GeneralRe: how to use the a interface declared in a dll [modified] Pin
goldli28-Mar-07 19:15
goldli28-Mar-07 19:15 
Question"Attempted to read or write protected memory." Pin
User 137680028-Mar-07 14:58
User 137680028-Mar-07 14:58 
Hi all,
I am trying to use a DLL that modifies a stream of bytes (basically it's an encryption/decryption DLL). This DLL comes from a third party and I have to use it "as is". It wasn't designed for C#, but I really don't see any reason I shouldn't be able to use 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:
<br />
[DllImport("ABCdecrypt.dll", EntryPoint = "ABCdecrypt", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]<br />
unsafe public static extern bool ABCdecrypt([MarshalAs(UnmanagedType.I4)] int type, byte* data, int datalength);<br />
<br />
private void buttonGo_Click(object sender, EventArgs e)<br />
{<br />
    byte[] yData = File.ReadAllBytes(textBoxInput.Text); //This is a filename<br />
    unsafe<br />
    {<br />
        fixed (byte* pBuf = &yData[0])<br />
        {<br />
            ABCdecrypt(100, pBuf, yData.Length); //This is where it fails<br />
            File.WriteAllBytes(textBoxOutput.Text, yData); //This is a filename<br />
        }<br />
    }<br />
    MessageBox.Show("Done");<br />
}<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
Dewald30-Mar-07 23:25
Dewald30-Mar-07 23:25 
QuestionWindows Forms book suggestions? Pin
Mark J. Miller28-Mar-07 12:11
Mark J. Miller28-Mar-07 12:11 
AnswerRe: Windows Forms book suggestions? Pin
J$28-Mar-07 12:54
J$28-Mar-07 12:54 
GeneralRe: Windows Forms book suggestions? Pin
Mark J. Miller28-Mar-07 13:30
Mark J. Miller28-Mar-07 13:30 
AnswerRe: Windows Forms book suggestions? Pin
Mike Hankey28-Mar-07 13:32
mveMike Hankey28-Mar-07 13:32 
AnswerRe: Windows Forms book suggestions? Pin
Scott Dorman28-Mar-07 13:36
professionalScott Dorman28-Mar-07 13:36 
AnswerRe: Windows Forms book suggestions? Pin
Rudolf Jan29-Mar-07 0:41
Rudolf Jan29-Mar-07 0:41 
Questionaccessing a remote gateway/box Pin
mfmaneef28-Mar-07 10:42
mfmaneef28-Mar-07 10:42 
QuestionUsing NotifyIcon Pin
gantww28-Mar-07 10:21
gantww28-Mar-07 10:21 
AnswerRe: Using NotifyIcon Pin
kubben28-Mar-07 11:02
kubben28-Mar-07 11:02 
QuestionC# / C++ interop - Functions returning pointers Pin
User 58261928-Mar-07 10:17
User 58261928-Mar-07 10:17 
AnswerRe: C# / C++ interop - Functions returning pointers Pin
led mike28-Mar-07 11:12
led mike28-Mar-07 11:12 
AnswerRe: C# / C++ interop - Functions returning pointers Pin
Leslie Sanford28-Mar-07 11:40
Leslie Sanford28-Mar-07 11:40 
QuestionDataColumn Expressions [modified] Pin
Farm Developer28-Mar-07 10:05
Farm Developer28-Mar-07 10:05 
AnswerRe: DataColumn Expressions Pin
J$28-Mar-07 14:33
J$28-Mar-07 14:33 
QuestionXmlwiter anyone can help Pin
Tkml23628-Mar-07 8:53
Tkml23628-Mar-07 8:53 
AnswerRe: Xmlwiter anyone can help Pin
J$28-Mar-07 9:18
J$28-Mar-07 9:18 

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.