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

C#

 
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 
AnswerRe: How to pin List to unmanaged byte** Pin
Chesnokov Yuriy19-Jan-11 19:02
professionalChesnokov Yuriy19-Jan-11 19:02 
GeneralRe: How to pin List to unmanaged byte** Pin
_Erik_19-Jan-11 3:06
_Erik_19-Jan-11 3:06 
GeneralRe: How to pin List to unmanaged byte** Pin
Chesnokov Yuriy19-Jan-11 4:18
professionalChesnokov Yuriy19-Jan-11 4:18 
GeneralRe: How to pin List to unmanaged byte** Pin
_Erik_19-Jan-11 5:10
_Erik_19-Jan-11 5:10 
Well, the msdn documentation for this is a little mess, but I remember some time ago, after some hours of research, I read that we had to pass a two dimensional array in these cases, I mean, we have to pass int[,] for an int** parameter in the unmanaged version, though I don't remember exactly if we could pass the reference itself. I still think there is a way to avoid copying data from one place to another. This time we should import the unmanaged function, setting IntPtr as the type for the fisrt parameter. The class I told you before would change as follows:

C#
public class ByteMatrix
{
    byte[,] _matrix;
    int _n;
    int _m;
    public ByteMatrix(int n, int m)
    {
        _matrix = new byte[n, m];
        _n = n;
        _m = m;
    }
    // Methods, indexers and properties to add, remove, etc, as needed
    // Import the unmanaged function here, as private
    [DllImport ... whatever]
    private static extern int unmanagedFunction(IntPtr array, int n, int m);
    // Wrap the unmanaged function whithin this class
    public int CallUnmanaged() // Here a good name, of course
    {
        // Pin the _matrix in managed heap first
        GCHandle handle = GCHandle.Alloc(_matrix, GCHandleType.Pinned);
        int ret = unmanagedFunction(handle.AddrOfPinnedObject(), _n, _m);
        // Release the handle
        handle.Free();

        return ret;
    }

AnswerRe: How to pin List to unmanaged byte** Pin
Chesnokov Yuriy19-Jan-11 9:45
professionalChesnokov Yuriy19-Jan-11 9:45 
GeneralRe: How to pin List to unmanaged byte** [modified] Pin
_Erik_19-Jan-11 10:55
_Erik_19-Jan-11 10:55 
AnswerRe: How to pin List to unmanaged byte** Pin
Chesnokov Yuriy19-Jan-11 19:12
professionalChesnokov Yuriy19-Jan-11 19:12 
GeneralRe: How to pin List to unmanaged byte** Pin
_Erik_20-Jan-11 2:37
_Erik_20-Jan-11 2:37 
AnswerRe: How to pin List to unmanaged byte** Pin
Chesnokov Yuriy19-Jan-11 4:27
professionalChesnokov Yuriy19-Jan-11 4:27 
AnswerRe: How to pin List<byte[]> to unmanaged byte** Pin
SledgeHammer0118-Jan-11 9:33
SledgeHammer0118-Jan-11 9:33 
AnswerRe: How to pin List to unmanaged byte** Pin
Chesnokov Yuriy18-Jan-11 19:08
professionalChesnokov Yuriy18-Jan-11 19:08 
GeneralRe: How to pin List to unmanaged byte** Pin
SledgeHammer0119-Jan-11 10:25
SledgeHammer0119-Jan-11 10:25 
AnswerRe: How to pin List to unmanaged byte** Pin
Chesnokov Yuriy19-Jan-11 19:03
professionalChesnokov Yuriy19-Jan-11 19:03 
GeneralRe: How to pin List to unmanaged byte** [modified] Pin
SledgeHammer0120-Jan-11 8:41
SledgeHammer0120-Jan-11 8:41 
QuestionOn Error Resume Next Pin
Anubhava Dimri17-Jan-11 18:24
Anubhava Dimri17-Jan-11 18:24 
AnswerRe: On Error Resume Next PinPopular
JF201517-Jan-11 18:31
JF201517-Jan-11 18:31 
GeneralRe: On Error Resume Next Pin
Anubhava Dimri17-Jan-11 19:09
Anubhava Dimri17-Jan-11 19:09 
GeneralRe: On Error Resume Next Pin
fjdiewornncalwe18-Jan-11 8:56
professionalfjdiewornncalwe18-Jan-11 8:56 
AnswerRe: On Error Resume Next Pin
Dave Kreskowiak17-Jan-11 18:59
mveDave Kreskowiak17-Jan-11 18:59 
AnswerRe: On Error Resume Next Pin
Abhinav S17-Jan-11 20:55
Abhinav S17-Jan-11 20:55 
AnswerRe: On Error Resume Next Pin
OriginalGriff17-Jan-11 21:20
mveOriginalGriff17-Jan-11 21:20 

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.