Hello!
Can anyone help me with calling Novell function from dll?
I think my main problem is in translating C variable types to C# types.
Here is the code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Globalization;
//declaring my class
public class IcNovell
{
[DllImport("calwin32.dll", CharSet = CharSet.Auto)]
public static extern int NWCallsInit(Byte reserved1, Byte
reserved2);
[DllImport("netwin32.dll", EntryPoint =
"NWDSCreateContextHandle", CharSet = CharSet.Auto, CallingConvention =
CallingConvention.Winapi, SetLastError = true)]
public static extern int GetHandle(out long context);
[DllImport("netwin32.dll", EntryPoint = "NWDSWhoAmI", CharSet =
CharSet.Auto, CallingConvention = CallingConvention.ThisCall,
SetLastError = true)]
public static extern int GetUser(long context, out string[]
NovellUserId);
}
//calling functions
// init
int cCode = IcNovell.NWCallsInit(0, 0);
long NovellContext = 0;
int RetCode0 = 0;
// get the context handle
RetCode0 = IcNovell.GetHandle(out NovellContext);
MessageBox.Show("RetCode0 is: " + RetCode0.ToString());
MessageBox.Show("Context is: "+NovellContext.ToString());
// my NovellContext equals 1 (looks good)
//string variable for user name
string[] NovellUserId = new string[255];
for (int i = 0; i < 255; i++)
{
NovellUserId[i] = " ";
}
int RetCode = 0;
// get the user name
RetCode = IcNovell.GetUser(NovellContext, out NovellUserId);
string hexValue = RetCode.ToString("X");
MessageBox.Show("RetCode is:" + hexValue);
At this point my RetCode is "FFFFFED1", which means (from Novell
documentation) "Trying to pass a bad context parameter to a NDS
function. Call NWDSCreateContextHandle first and use its return value as
the context parameter."
I think that variable NovellContext has wrong type (i got: long
NovellContext, maybe it should be IntPtr?).
In Novell documentation function declarations look like this:
NWDSCreateContextHandle
(http://developer.novell.com/ndk/doc/...7.html#sdk2687)
Syntax
C
#include <nwnet.h>
or
#include <nwdsdc.h>
N_EXTERN_LIBRARY (NWDSCCODE) NWDSCreateContextHandle (
NWDSContextHandle N_FAR *newHandle);
NWDSWhoAmI
(http://developer.novell.com/ndk/doc/...7.html#sdk2687)
Syntax
C
#include <nwnet.h>
or
#include <nwdsdsa.h>
N_EXTERN_LIBRARY (NWDSCCODE) NWDSWhoAmI (
NWDSContextHandle context,
pnstr8 objectName);
Any help will be appreciated.
Best regards,
Przemek