C# - Calling Novell API function (solution)

Here's a quick C# sample on how to call a Novell API function (solution).

public class IcNovell
{
[
DllImport("calwin32.dll")] public static extern int NWCallsInit(byte reserved1, byte reserved2);
[
DllImport("netwin32.dll", EntryPoint = "NWDSCreateContextHandle")] public static extern int NWDSCreateContextHandle(ref int context);
[
DllImport("netwin32.dll", EntryPoint = "NWDSWhoAmI")] public static extern int NWDSWhoAmI(int context, StringBuilder NovellUserId);
[
DllImport("netwin32.dll", EntryPoint = "NWDSFreeContext")] public static extern int NWDSFreeContext(int context);
}

private void button1_Click(object sender, EventArgs e)
{
  int cCode = IcNovell.NWCallsInit(0, 0);
  if (cCode == 0)
  {
    int NovellContext = 0;
    cCode =
IcNovell.NWDSCreateContextHandle(ref NovellContext);
    if (cCode == 0)
    {
      StringBuilder NovellUserId = new StringBuilder(256);
      cCode =
IcNovell.NWDSWhoAmI(NovellContext, NovellUserId);
      if (cCode == 0)
      {
        label1.Text = NovellUserId.ToString();
      }
      cCode =
IcNovell.NWDSFreeContext(NovellContext);
    }
  }
}

By fero novar   Popularity  (1653 Views)