Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 735271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:28:11+00:00 2026-05-14T07:28:11+00:00

I have a working wrapper class for Dallmeier camera devices, It contains a callback

  • 0

I have a working wrapper class for Dallmeier camera devices, It contains a callback method to receive the current YUV image.
See details C# wrapper for array of three pointers.

I have a button on my form that gets the YUV Image. The callback returns ‘yuvData’ which is an array of three pointers to Y, U, and V part of image.
I then copy the three pointers into thier own pointer and then copy them into a byte array. The yuvCallback continues to run until I disconnect the camera.

Am I using Marshal.Copy correctly?

public class DLMSDK
{
    public delegate int YUVDataCallback(dlm_yuvdataParametersStructure pParameters);

    DllImport(@"DallmeiersDLL\davidapileolive.dll")]
        public extern static int dlm_setYUVDataCallback(int SessionHandle, YUVDataCallback dataCallback);

        [StructLayout(LayoutKind.Explicit, Size = 32)]
        public struct dlm_yuvdataParametersStructure
        {
            [FieldOffset(0)]
            public int IPlayerID;
            [FieldOffset(4), MarshalAs(UnmanagedType.ByValArray, SizeConst=3)]
            public IntPtr[] yuvData;
            [FieldOffset(8), MarshalAs(UnmanagedType.ByValArray, SizeConst=1)]
            public IntPtr[] pitch;
            [FieldOffset(12)]
            public int width;
            [FieldOffset(16)]
            public int height;
            [FieldOffset(18)]
            public long ts;
            [FieldOffset(28), MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
            public IntPtr[] extData;
        }
}

public partical class Form1 : Form
{
    int width; int height; 
    int yArraySize; int uvArraySize;
    byte[] yBytes; byte[] uBytes; byte[] vBytes;
    int sizeY; int sizeU; int sizeV;
    IntPtr ptrY; IntPtr ptrU; IntPtr ptrV;

    DLMSDK.YuvDataCallback yuvdataCallback;

    private void Form1_Load(object send, EventArgs e)
    {
        error = DLMSDK.dlm_initSDK();
        if (error == 0)
            registerEvents();
    }

    private void registerEVents()
    {
        yuvdataCallback = yuvdataHandler;
    }

    private void btnGetYUV_Click(object sender, EventArgs e)
    {
        try
        {
                error = DLMSDK.dlm_setYUVDataCallback(SessionHandle, yuvdataCallback);      
        }
        catch (Exception ex)
        {
                MessageBox.Show(ex.ToString());
        }
    }

    public int yuvdataHandler(DLMSDK.dlm_yuvdataParametersStructure pParameters)
    {
        width = pParameters.width;
        height = pParameters.height;
        yArraySize = width * height;
        uvArraySize = yArraySize/4;

        yBytes = new byte[yArraySize];
        uBytes = new byte[uvArraySize];
        vBytes = new byte[uvArraySize];

        sizeY = Marshal.SizeOf(yBytes[0]) * yBytes.Length;
        ptrY = Marshal.AllocHGlobal(sizeY);

        sizeU = Marshal.SizeOf(uBytes[0]) * uBytes.Length;
        ptrU = Marshal.AllocHGlobal(sizeU);

        sizeV = Marshal.SizeOf(vBytes[0]) * vBytes.Length;
        ptrV = Marshal.AllocHGlobal(sizeV);

        try
        {
            // Copy the three pointers to Y,U, & V pointers
            Marshal.Copy(pParameters.yuvData, 0, ptrY, 1);
            Marshal.Copy(pParameters.yuvData, 1, ptrU, 1);
            Marshal.Copy(pParameters.yuvData, 2, ptrV, 1);

            // Copy pointers to YUV byte arrays
            Marshal.Copy(ptrY, yBytes, 0, sizeY);
            Marshal.Copy(ptrU, uBytes, 0, sizeU);
            Marshal.Copy(ptrV, vBytes, 0, sizeV);

            // Convert Y (Luminance) to Greyscale and display
            Bitmap bmp = ImgConvert.ToGreyscale(yBytes, width, height);
            DisplayImage(bmp);
        }
        finally
        {
            if (ptrY != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(ptrY);
                ptrY = IntPtr.Zero;
            }
            if (ptrU != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(ptrU);
                ptrU = IntPtr.Zero;
            }
            if (ptrV != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(ptrV);
                ptrV = IntPtr.Zero;
            }
        }

        return 0;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T07:28:12+00:00Added an answer on May 14, 2026 at 7:28 am

    I see you posted a similar question over at the MSDN forums: http://social.msdn.microsoft.com/Forums/en-US/clr/thread/67d20c16-d58b-444d-9689-88fab2792ab1

    As I wrote over there, it’s not correct to pack the callback delegate’s parameters into a structure and pass it by value. So the first step is to correct the delegate signature.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working with a wrapper class for CFHTTPMessage , which contains a CFHTTPMessageRef
I'm writing a semi-simple database wrapper class and want to have a fetching method
I have been working on a wrapper for a COM object that can only
I have following wrapper to help me manage the wcf client lifetime: public class
I have been working on a web services related project for about the last
I have been working with Visual Studio (WinForm and ASP.NET applications using mostly C#)
I have been working with a string[] array in C# that gets returned from
We have been working with CVS for years, and frequently find it useful to
I have been working on some legacy C++ code that uses variable length structures
I have a working copy of my project, checked out using Subversion 1.5.1. When

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.