PInvoke void * parameter

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jmcpeak
    New Member
    • Mar 2009
    • 4

    PInvoke void * parameter

    Here is the unmanged definition:
    Code:
    //============================================================================
    // DcamCapture()
    // Start to acquire one image from the camera.
    // ---------------------------------------------------------------------------
    // [Argument]
    // pImageBuff : /O: Specify the start address in the buffer where image
    // data is to be stored.
    // nBuffSize :I/ : Specify the buffer size (number of bytes).
    // [Return values]
    // If the function succeeds the return value is TRUE (1).
    // If the function fails the return value is FALSE (0).
    // To obtain detailed error information, use the DcamGetLastError function.
    // [Note]
    // 1. This function issues an instruction to start image acquisition.
    // Since image acquisition is not complete even when this function ends,
    // use the DcamWait function to check whether image acquisition is complete.
    // 2. The necessary buffer size can be obtained with the DcamGetFrameBytes function.
    //============================================================================
    _DCAMLIBEXPORT BOOL _DCAMLIBSTDCALL DcamCapture( LPVOID pImageBuff, INT nBuffSize );
    Here is my C# code which does not work:
    Code:
    class DCamLIB
    {
    private IntPtr ImageBuffer;
    
    public DCamLIB()
    {
    ImageBuffer = new IntPtr( 0 );
    }
    
    [DllImport( "DCamLIB.dll" )]
    private static extern bool DcamCapture( out IntPtr imageBuffer, Int32 bufferSize );
    
    public void Capture( Int32 bufferSize )
    {
    if ( !DcamCapture( out ImageBuffer, bufferSize ) )
    {
    throw new DCamLIBException( this );
    }
    }
    }
    No matter what ImageBuffer = 0.

    Ideas?
    Last edited by tlhintoq; Mar 14 '09, 04:48 PM. Reason: Please use [CODE] ... [/CODE] tags
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    // 2. The necessary buffer size can be obtained with the DcamGetFrameByt es function.
    Question 1: What kind of camera is this?
    Question 2: Are you receiving a buffersize from the above function that makes sense for the size of the image you are expecting?

    Comment

    • jmcpeak
      New Member
      • Mar 2009
      • 4

      #3
      > What kind of camera is this?
      X-Ray

      > Are you receiving a buffersize from the above function that makes sense for the size of the image you are expecting?
      Yes, it is is returning the correct width and height variables - 1000 x 1500

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        The function doesn't look like it would be turning H & W values, judging by its name: GetFrameBytes. It looks like it would be returning a single number that is the size of the buffer to hold the image data. You would then use your knowledge of the expected data to translate all those bytes to an image (height, width, color depth, header size)

        Comment

        • tlhintoq
          Recognized Expert Specialist
          • Mar 2008
          • 3532

          #5
          // 1. This function issues an instruction to start image acquisition.
          // Since image acquisition is not complete even when this function ends,
          // use the DcamWait function to check whether image acquisition is complete.
          I don't see where you are checking the DcamWait function.

          Comment

          • jmcpeak
            New Member
            • Mar 2009
            • 4

            #6
            Please use
            Code:
             ...
            tags

            The real issue I can't solve is how to pass a void * as a parameter to the dll.
            Code:
            [DllImport( "DCamLIB.dll" )]
            private unsafe static extern bool DcamCapture( int* imageBuffer, Int32 bufferSize );
            
            public unsafe void CaptureReverseX( Int32 bufferSize )
            {
            	fixed ( int* buf = new int[ bufferSize ] )
            	{
            		if ( !DcamCapture( ImageBuffer, bufferSize ) )
            		{
            			throw new DCamLIBException( this );
            		}
            		// Here the pointer buf is defined, but the value is still 0
            		// It's like the DcamCapture() method does not populate buf
            	}
            }
            Last edited by tlhintoq; Mar 14 '09, 07:22 PM. Reason: [CODE] ... [/CODE] tags

            Comment

            • tlhintoq
              Recognized Expert Specialist
              • Mar 2008
              • 3532

              #7
              The real issue I can't solve is how to pass a void * as a parameter to the dll.
              A void pointer ???

              Originally posted by tlhintoq
              I don't see where you are checking the DcamWait function.
              Are you checking the DcamWait function before you try to get the data out of the buffer?

              Comment

              • jmcpeak
                New Member
                • Mar 2009
                • 4

                #8
                I got it working, needed to change a setting - set the trigger mode to internal. Using fixed worked great.

                Comment

                • cooldj
                  New Member
                  • Dec 2011
                  • 1

                  #9
                  typedef struct tag_dcam* HDCAM

                  HDCAM is a typedef struct tag_dcam* HDCAM


                  In DCAM-API , HDCAM is one of the input arguments.

                  which is declare as...
                  // declaration of DCAM helper function
                  HDCAM dcamcon_init_op en();

                  In main function it can Initialize as...
                  HDCAM hdcam;

                  & call as...
                  // initialize DCAM-API and get HDCAM camera handle.
                  hdcam = dcamcon_init_op en();


                  How I can write code in c# if I want to access HDCAM?

                  Comment

                  Working...