Click here to Skip to main content
15,888,527 members
Home / Discussions / C#
   

C#

 
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 
AnswerRe: "Attempted to read or write protected memory." Pin
Dewald31-Mar-07 0:03
Dewald31-Mar-07 0:03 
Hi YttriumOxide,

Hi didn't notice that you've made a newer post of the same question so I've answered on the previous one. However, I notice one thing in this post that seems to differ from your previous one and which may well be the source of your problem.

The final parameter of ABCDecrypt is int* datalength but when you import the function from the DLL you specify the parameter as int datalength. Then when you call it you pass yData.Length which is an int, not an int*. Also, I see you import the second parameter ae byte* data. I'm not sure if makes any difference in C# but it might just make better sense to import it as byte[] data.

So I would think that you should import the function from the DLL as:
unsafe public static extern bool ABCdecrypt([MarshalAs(UnmanagedType.I4)] int type, byte[] data, ref int datalength);

And then, when you call it, it should look something like:
ABCdecrypt(100, yData, yData.Length);

I assume this function takes a byte array (data) of length datalength and decrpyts it according to some algorithm specified by type. It then writes the result into data again and updates the datalength value also. This would suggest to me that the returned byte array may be of a different size than the input byte array. If this is the case, you need to make sure that the size of yData is big enough to hold the returned byte array.

If you know that the returned byte array will never be bigger than 256 bytes, you could do the following:

byte[] myBuffer = new byte[256];<br />
byte[] yData = File.ReadAllBytes(textBoxInput.Text);<br />
int DataLen = yData.Length;<br />
<br />
Array.Copy(yData, 0, myBuffer, 0, DataLen);<br />
ABCdecrypt(100, myBuffer, ref DataLen);


At this point, myBuffer should contain DataLen bytes which represents the returned byte array.

There may very well be more elegant sollutions but I am not very strong in C#. Most of what I wrote here came from the C++ programmer in me;)
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 
GeneralRe: Streamreader and read file Pin
Saamir30-Mar-07 12:00
Saamir30-Mar-07 12:00 

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.