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

C#

 
GeneralRe: How to pin List to unmanaged byte** Pin
Chesnokov Yuriy18-Jan-11 2:48
professionalChesnokov Yuriy18-Jan-11 2:48 
GeneralRe: How to pin List to unmanaged byte** Pin
DaveyM6918-Jan-11 2:57
professionalDaveyM6918-Jan-11 2:57 
QuestionRe: How to pin List to unmanaged byte** Pin
Chesnokov Yuriy18-Jan-11 3:03
professionalChesnokov Yuriy18-Jan-11 3:03 
GeneralRe: How to pin List to unmanaged byte** Pin
_Erik_18-Jan-11 3:01
_Erik_18-Jan-11 3:01 
AnswerRe: How to pin List to unmanaged byte** Pin
Chesnokov Yuriy18-Jan-11 3:06
professionalChesnokov Yuriy18-Jan-11 3:06 
GeneralRe: How to pin List to unmanaged byte** Pin
_Erik_18-Jan-11 3:17
_Erik_18-Jan-11 3:17 
AnswerRe: How to pin List to unmanaged byte** Pin
Chesnokov Yuriy18-Jan-11 3:20
professionalChesnokov Yuriy18-Jan-11 3:20 
GeneralRe: How to pin List to unmanaged byte** Pin
_Erik_18-Jan-11 3:47
_Erik_18-Jan-11 3:47 
Ok. Let's see.

Chesnokov Yuriy wrote:
It is not possible to pass managed byte[][] to unmanaged byte**.

This possibility depends on how you import the unmanaged function. When using P/Invoke the parameters in the managed version just need to have the same size of the target unmanaged version. Since byte** is a pointer, and byte[][] is a reference, both of them have the same size becouse both of them are pointers.

Chesnokov Yuriy wrote:
Even if it was possible managed memory is not fixed.

Yes, that's right, but when you make a P/Invoke call, the CLR automatically pins the references passed to the unmanaged function into the managed heap, so the references will not move until the call is finished so, if you use references (such as byte[]), there is no need to manually pin them.

Chesnokov Yuriy wrote:
I have List and I need to pass it to byte**.

Try importing the unmanaged function as I told you before, I mean, use byte[][] and not byte** as the type for the first parameter. Belive me, this is the easiest way, it's worth to try. We can try the tricky version later if this does not work.

Chesnokov Yuriy wrote:
byte[][] conversion is out of scope as arrays may be of different size.

And casting to byte** is a warranty for that?

Chesnokov Yuriy wrote:
It needs to allocate with static alloc array to hold pinned pointers. Then to pin them.

To pin references into the managed heap you have to use GCHandle struct.
GeneralRe: How to pin List to unmanaged byte** Pin
Chesnokov Yuriy18-Jan-11 8:07
professionalChesnokov Yuriy18-Jan-11 8:07 
GeneralRe: How to pin List to unmanaged byte** Pin
DaveyM6918-Jan-11 16:50
professionalDaveyM6918-Jan-11 16:50 
GeneralRe: How to pin List to unmanaged byte** Pin
Chesnokov Yuriy18-Jan-11 19:16
professionalChesnokov Yuriy18-Jan-11 19:16 
GeneralRe: How to pin List to unmanaged byte** Pin
DaveyM6919-Jan-11 1:01
professionalDaveyM6919-Jan-11 1:01 
QuestionRe: How to pin List to unmanaged byte** Pin
Chesnokov Yuriy19-Jan-11 1:25
professionalChesnokov Yuriy19-Jan-11 1:25 
AnswerRe: How to pin List to unmanaged byte** Pin
DaveyM6919-Jan-11 2:40
professionalDaveyM6919-Jan-11 2:40 
AnswerRe: How to pin List to unmanaged byte** Pin
Chesnokov Yuriy19-Jan-11 3:00
professionalChesnokov Yuriy19-Jan-11 3:00 
QuestionRe: How to pin List to unmanaged byte** Pin
Chesnokov Yuriy19-Jan-11 4:13
professionalChesnokov Yuriy19-Jan-11 4:13 
AnswerRe: How to pin List to unmanaged byte** Pin
DaveyM6919-Jan-11 5:43
professionalDaveyM6919-Jan-11 5:43 
AnswerRe: How to pin List to unmanaged byte** Pin
Chesnokov Yuriy19-Jan-11 9:28
professionalChesnokov Yuriy19-Jan-11 9:28 
GeneralRe: How to pin List to unmanaged byte** Pin
DaveyM6919-Jan-11 9:31
professionalDaveyM6919-Jan-11 9:31 
AnswerRe: How to pin List to unmanaged byte** [modified] Pin
DaveyM6919-Jan-11 8:48
professionalDaveyM6919-Jan-11 8:48 
AnswerRe: How to pin List to unmanaged byte** Pin
DaveyM6919-Jan-11 9:23
professionalDaveyM6919-Jan-11 9:23 
AnswerRe: How to pin List to unmanaged byte** Pin
Chesnokov Yuriy19-Jan-11 9:35
professionalChesnokov Yuriy19-Jan-11 9:35 
GeneralRe: How to pin List to unmanaged byte** Pin
DaveyM6919-Jan-11 9:41
professionalDaveyM6919-Jan-11 9:41 
AnswerRe: How to pin List to unmanaged byte** Pin
Chesnokov Yuriy19-Jan-11 10:04
professionalChesnokov Yuriy19-Jan-11 10:04 
GeneralRe: How to pin List to unmanaged byte** Pin
DaveyM6919-Jan-11 10:14
professionalDaveyM6919-Jan-11 10:14 

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.