1

I am trying to implement watershed image segmentation as said by former programmer in :

Watershed using c# or c++

I tried adding FilterGrayToGray.cs code too but i got error of win32.memcpy

The error shows: "The name win32 doesn't exists in this context"

if we convert Win32.memcpy to Microsoft.Win32.memcpy then it says "memcpy doesn't exists in the namespace"

Community
  • 1
  • 1
KoolKabin
  • 17,157
  • 35
  • 107
  • 145
  • The reason this question received little attention is that it is difficult to find any references to `memcpy` in the question, or in the linked pages. Please add the code that does not compile and it will be very easy to fix. – David Heffernan Feb 26 '12 at 22:24

1 Answers1

2

memcpy isn't part of the .NET Framework - memcpy is an unmanaged native API that needs to have a p/Invoke definition created. The defination for memcpy must be in a different file.

See the example below:

/// <summary>
/// Windows API functions and structures.
/// </summary>
internal static class Win32
{
    /// <summary>
    /// Copy a block of memory.
    /// </summary>
    ///
    /// <param name="dst">Destination pointer.</param>
    /// <param name="src">Source pointer.</param>
    /// <param name="count">Memory block's length to copy.</param>
    ///
    /// <returns>Return's the value of <b>dst</b> - pointer to destination.</returns>
    ///
    [DllImport( "ntdll.dll", CallingConvention = CallingConvention.Cdecl )]
    public static extern IntPtr memcpy(
        IntPtr dst,
        IntPtr src,
        UIntPtr count );
    }
}
shf301
  • 31,086
  • 2
  • 52
  • 86
  • That's a terrible definition for `memcpy`. Since when could `int` represent a pointer? And since when was `int` reasonable for `size_t`? – David Heffernan Feb 26 '12 at 22:35
  • @David Heffernan: what is reasonable for size_t? uint? I would not say it's *terrible*. Can be improved? Sure. Btw this definition has an obvious advantage of being compatible *for sure* with the code that is using it - they come from the same project. – Andrew Savinykh Feb 26 '12 at 22:50
  • @DavidHeffernan - Updated - I just cut and pasted the example without looking at it closely assuming it was correct. – shf301 Feb 27 '12 at 02:38