Using C++ library in C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • GigaKatowice
    New Member
    • Jun 2012
    • 4

    Using C++ library in C#

    Hi.

    I need help with my code.
    I'm trying to run unmanaged code from my C# code.


    C++ Code
    Code:
    Result_t oemGetImage(PBYTE pImageBuffer,
                         PDWORD pdwSize, WORD nTop,
                         WORD nLeft, WORD nRight,
                         WORD nBottom, WORD nSkip,
                         WORD nBits, FileFormat_t nFormat,
                         WORD nWhiteValue,
                         WORD nExposeAttempts, WORD nGap,
                         BOOL Invert, void (*fpProgress) (WORD));
    I don't know what to do with pImageBuffer, pdwSize or void (*fpProgress) (WORD)).

    In C++ I execute this function like this:
    Code:
    BYTE *pBufor;
    pBufor = new BYTE[MAX_IMAGE_SIZE];
    
    DWORD *pSize; 
    	pSize = new DWORD; 
    
    oemGetImage (pBufor,pSize, 0, 0, 200, 200, 1, 8, FF_RAW_GRAY, 200, 100, 55, false, NULL);
    FF_RAW_GRAY is an enum with value of 1.

    How can I declare pBufor which is a pointer to byte array?
    And what to do with void (*fpProgress) (WORD))??

    Thank you, for all your help.
  • GigaKatowice
    New Member
    • Jun 2012
    • 4

    #2
    I managed to run this function with help from other forum.
    My definition for this function looks like this:

    Code:
      private extern static int oemGetImage([In, Out]byte[] pImageBuffer,
      ref uint pdwSize, uint nTop,
      uint nLeft, uint nRight,
      uint nBottom, uint nSkip,
      uint nBits, uint nFormat,
      uint nWhiteValue,
      uint nExposeAttempts, uint nGap,
      bool Invert, [MarshalAs(UnmanagedType.FunctionPtr)]Progress fpProgress);
    
      public delegate void Progress(ushort us);
    and execution

    Code:
     byte[] pBufor = new byte[width * height];
     uint pSize = 0;
     oemGetImage(pBufor, ref pSize, 0, 0, _width, _height, 1, 8, 1, 220, 50, 35, false, null);

    Comment

    Working...