title: C/C# - Marshal.PtrToStringAnsi
body: <p>What's the equivalent to Marshal.PtrToStringAnsi (C#) in C language ? <br /></p>
  
  <p>Because, I would like rewrite a function C# in C. <br />
  This is the C# function:</p>
  
  <pre><code>public int GetProcessName(uint processId, out string name)
          {
              IntPtr ptr = Marshal.AllocHGlobal((int)(0x211)); int result = -1;
              result = getProcessName(processId, ptr);
              name = String.Empty;
              if(SUCCESS(result))
                  name = Marshal.PtrToStringAnsi(ptr);
              Marshal.FreeHGlobal(ptr);
              return result;
          }
  </code></pre>
  
  <p>And actually my C function:</p>
  
  <pre><code>int
  GetProcessName(uint processId, char *name)
  {
      HINSTANCE   hLib = LoadLibrary("CCAPI.DLL");
       __cGetProcessName      getProcessName = (__cGetProcessName)GetProcAddress(hLib, "CCAPIGetProcessName");
      int     *ptr = malloc((int)(0x211));
      int     result = -1;
      result = getProcessName(processId, ptr);
  
      name = "";
      if (SUCCESS(result))
      {
          name = /* ?? */;
      }
  
      free(ptr);
      return (result);
  }
  </code></pre>