API interfacing with a LPBYTE from C#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dave A

    #1

    API interfacing with a LPBYTE from C#

    Hi, I have the following function that I need to call from C#.

    HRESULT CamPreviewGetBG R16(HANDLE hCamera,LPBYTE pBuffer);

    but I am stuggling with the LPBYTE pBuffer. I have decalred it as

    [DllImport("mobi lecamapi.dll",E ntryPoint="CamP reviewGetBGR16" )]
    public static extern int CamPreviewGetBG R16(uint hCamera, byte[] pBuffer);

    and have called it via:

    byte[] buffer = new byte[width * height * 2];
    result = CamPreviewGetBG R16(cameraHandl e, buffer);

    It is returning with a missing method exception. I think the 'byte[]
    pBuffer' in the API definition needs to be a 'uint pBuffer' but then how do
    I convert the 'byte[] buffer' in the calling code to be a uint? (I am a bit
    of a novice at all of this Interop stuff)

    Any suggestions are greatly appreaciated.

    Thanks

    Dave A



  • Xedecimal

    #2
    RE: API interfacing with a LPBYTE from C#

    Dug around a bit for lpbyte and C# and found some information on it...

    System.Runtime. InteropServices .Marshal.CopyBy tesToManaged(In t32 source,
    Byte[] destination, Int32 startIndex, Int32 length)

    Not sure but it looks to be what will make you a managed lpbyte array, also
    if you have too much trouble with this dll, there's avicap32.dll that I
    always used to do webcam things with.

    "Dave A" wrote:
    [color=blue]
    > Hi, I have the following function that I need to call from C#.
    >
    > HRESULT CamPreviewGetBG R16(HANDLE hCamera,LPBYTE pBuffer);
    >
    > but I am stuggling with the LPBYTE pBuffer. I have decalred it as
    >
    > [DllImport("mobi lecamapi.dll",E ntryPoint="CamP reviewGetBGR16" )]
    > public static extern int CamPreviewGetBG R16(uint hCamera, byte[] pBuffer);
    >
    > and have called it via:
    >
    > byte[] buffer = new byte[width * height * 2];
    > result = CamPreviewGetBG R16(cameraHandl e, buffer);
    >
    > It is returning with a missing method exception. I think the 'byte[]
    > pBuffer' in the API definition needs to be a 'uint pBuffer' but then how do
    > I convert the 'byte[] buffer' in the calling code to be a uint? (I am a bit
    > of a novice at all of this Interop stuff)
    >
    > Any suggestions are greatly appreaciated.
    >
    > Thanks
    >
    > Dave A
    >
    >
    >
    >[/color]

    Comment

    • Dave A

      #3
      Re: API interfacing with a LPBYTE from C#

      Thanks! That looks like the answer.

      This is for the Pocket PC. I don't think avicap32.dll will work.

      Regards
      Dave

      "Xedecimal" <Xedecimal@disc ussions.microso ft.com> wrote in message
      news:1126A2DC-78EA-4A05-BE6D-42BA8E1EB385@mi crosoft.com...[color=blue]
      > Dug around a bit for lpbyte and C# and found some information on it...
      >
      > System.Runtime. InteropServices .Marshal.CopyBy tesToManaged(In t32 source,
      > Byte[] destination, Int32 startIndex, Int32 length)
      >
      > Not sure but it looks to be what will make you a managed lpbyte array,[/color]
      also[color=blue]
      > if you have too much trouble with this dll, there's avicap32.dll that I
      > always used to do webcam things with.
      >
      > "Dave A" wrote:
      >[color=green]
      > > Hi, I have the following function that I need to call from C#.
      > >
      > > HRESULT CamPreviewGetBG R16(HANDLE hCamera,LPBYTE pBuffer);
      > >
      > > but I am stuggling with the LPBYTE pBuffer. I have decalred it as
      > >
      > > [DllImport("mobi lecamapi.dll",E ntryPoint="CamP reviewGetBGR16" )]
      > > public static extern int CamPreviewGetBG R16(uint hCamera, byte[][/color][/color]
      pBuffer);[color=blue][color=green]
      > >
      > > and have called it via:
      > >
      > > byte[] buffer = new byte[width * height * 2];
      > > result = CamPreviewGetBG R16(cameraHandl e, buffer);
      > >
      > > It is returning with a missing method exception. I think the 'byte[]
      > > pBuffer' in the API definition needs to be a 'uint pBuffer' but then how[/color][/color]
      do[color=blue][color=green]
      > > I convert the 'byte[] buffer' in the calling code to be a uint? (I am a[/color][/color]
      bit[color=blue][color=green]
      > > of a novice at all of this Interop stuff)
      > >
      > > Any suggestions are greatly appreaciated.
      > >
      > > Thanks
      > >
      > > Dave A
      > >
      > >
      > >
      > >[/color][/color]


      Comment

      Working...