Click here to Skip to main content
15,918,275 members
Home / Discussions / C#
   

C#

 
GeneralRe: how can I convert int[] to object[] ? Pin
michal.kreslik12-Sep-06 1:31
michal.kreslik12-Sep-06 1:31 
GeneralRe: how can I convert int[] to object[] ? Pin
Stefan Troschuetz12-Sep-06 2:48
Stefan Troschuetz12-Sep-06 2:48 
GeneralRe: how can I convert int[] to object[] ? [modified] Pin
michal.kreslik13-Sep-06 12:29
michal.kreslik13-Sep-06 12:29 
Questionhow to implement a drawer control? Pin
yu miao11-Sep-06 2:07
yu miao11-Sep-06 2:07 
AnswerRe: how to implement a drawer control? Pin
Niiiissssshhhhhuuuuu11-Sep-06 2:49
Niiiissssshhhhhuuuuu11-Sep-06 2:49 
QuestionHow to make the form non resizeble and non movable Pin
Hemant kulkarni11-Sep-06 1:53
Hemant kulkarni11-Sep-06 1:53 
AnswerRe: How to make the form non resizeble and non movable Pin
stancrm11-Sep-06 2:28
stancrm11-Sep-06 2:28 
Questionaccessing unmanaged memory [modified] Pin
a.mulay11-Sep-06 1:51
a.mulay11-Sep-06 1:51 
Hi,
I am trying to access unmanaged memory which allocated from a dll function.
The function signature that is exported is as follows

extern "C" __declspec( dllexport ) BOOL ResizeImage(LPVOID  pbySrcBytes,<br />
                                         LONG 	lnSrcSize,<br />
                                         LPVOID pbyDestBytes,<br />
                                         LPLONG	lnTgtSize<br />
                                        );


Through the parameter "pbySrcBytes" I pass memory to the unmanaged code using marshalling.
In return the unmanaged function returns memory through "pbyDestBytes" on unmanaged heap which is having dynamic size which I get through "lnTgtImgSize".

I am not able to copy the memory returned. I am getting an error as "Access Violation" & "the memory is corrupted".

I have imported the function as follows.

[DllImport("ImgProcessor.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]<br />
public static extern Int32 ResizeImage([Out] byte[]  pbySrcImgBytes,<br />
                                       Int32         lnSrcImgSize,<br />
                                       IntPtr	     ppbyDestImgBytes,<br />
                                       [Out] IntPtr  lnTgtImgSize<br />
                                    );



I have done the C# part as follows:-

byte []byInputArray = File.ReadAllBytes(txtInput.Text); // txtInput.Text contains the file name to read<br />
Int32 nTgtImgSize = new Int32();<br />
IntPtr ptrTargetImageBytes = Marshal.AllocHGlobal(4);<br />
IntPtr ptrTgtImgSize = Marshal.AllocHGlobal(4);<br />
IntPtr ptrSourceImageBytes = Marshal.AllocHGlobal(byInputArray.Length);<br />
Marshal.StructureToPtr(byInputArray[byInputArray.Length-1], ptrSourceImageBytes, false);<br />
ImageResizerClient.ResizeImage(byInputArray, (int)byInputArray.Length, 400, 300, ptrTargetImageBytes, ptrTgtImgSize);<br />
nTgtImgSize = Marshal.ReadInt32(ptrTgtImgSize);<br />
byte []byOutputArray = new byte[nTgtImgSize];<br />
Marshal.Copy(ptrTargetImageBytes, byOutputArray, 0, nTgtImgSize);



The Marshal.Copy method call is throwing the error.
Can anyone help me understand why this is happening?


Thank You,
Amit.



-- modified at 23:59 Monday 11th September, 2006
QuestionHow to make the form non resizeble and non movable? Pin
Hemant kulkarni11-Sep-06 1:49
Hemant kulkarni11-Sep-06 1:49 
AnswerRe: How to make the form non resizeble and non movable? Pin
Niiiissssshhhhhuuuuu11-Sep-06 2:05
Niiiissssshhhhhuuuuu11-Sep-06 2:05 
GeneralRe: How to make the form non resizeble and non movable? Pin
Hemant kulkarni11-Sep-06 2:17
Hemant kulkarni11-Sep-06 2:17 
GeneralRe: How to make the form non resizeble and non movable? Pin
Inikaa11-Sep-06 2:23
Inikaa11-Sep-06 2:23 
GeneralRe: How to make the form non resizeble and non movable? Pin
Niiiissssshhhhhuuuuu11-Sep-06 2:39
Niiiissssshhhhhuuuuu11-Sep-06 2:39 
QuestionADO.NET autokey Pin
Imtiaz Murtaza11-Sep-06 1:28
Imtiaz Murtaza11-Sep-06 1:28 
AnswerRe: ADO.NET autokey Pin
_AK_11-Sep-06 1:33
_AK_11-Sep-06 1:33 
AnswerRe: ADO.NET autokey Pin
saqib8211-Sep-06 4:02
saqib8211-Sep-06 4:02 
QuestionResource load problem Pin
gulucay11-Sep-06 1:24
gulucay11-Sep-06 1:24 
AnswerRe: Resource load problem Pin
Stefan Troschuetz11-Sep-06 1:46
Stefan Troschuetz11-Sep-06 1:46 
QuestionRemoting Pin
Acheive_it11-Sep-06 0:33
Acheive_it11-Sep-06 0:33 
QuestionDAAB Input parameter type confusion Pin
Brendan Vogt11-Sep-06 0:27
Brendan Vogt11-Sep-06 0:27 
AnswerRe: DAAB Input parameter type confusion Pin
playout11-Sep-06 2:56
playout11-Sep-06 2:56 
QuestionSemi modal dialog? Pin
mesmer11-Sep-06 0:21
mesmer11-Sep-06 0:21 
AnswerRe: Semi modal dialog? Pin
Amit Kumar Chikara11-Sep-06 1:01
Amit Kumar Chikara11-Sep-06 1:01 
AnswerRe: Semi modal dialog? Pin
Coding C#11-Sep-06 4:47
Coding C#11-Sep-06 4:47 
QuestionLoading and Image, Slows my Form...??? Pin
baajhan10-Sep-06 23:50
baajhan10-Sep-06 23:50 

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.