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.Collecti ons.Generic;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows. Forms;
using System.Runtime. InteropServices ;
using System.Globaliz ation;
//declaring my class
public class IcNovell
{
[DllImport("calw in32.dll", CharSet = CharSet.Auto)]
public static extern int NWCallsInit(Byt e reserved1, Byte
reserved2);
[DllImport("netw in32.dll", EntryPoint =
"NWDSCreateCont extHandle", CharSet = CharSet.Auto, CallingConventi on =
CallingConventi on.Winapi, SetLastError = true)]
public static extern int GetHandle(out long context);
[DllImport("netw in32.dll", EntryPoint = "NWDSWhoAmI ", CharSet =
CharSet.Auto, CallingConventi on = CallingConventi on.ThisCall,
SetLastError = true)]
public static extern int GetUser(long context, out string[]
NovellUserId);
}
//calling functions
// init
int cCode = IcNovell.NWCall sInit(0, 0);
long NovellContext = 0;
int RetCode0 = 0;
// get the context handle
RetCode0 = IcNovell.GetHan dle(out NovellContext);
MessageBox.Show ("RetCode0 is: " + RetCode0.ToStri ng());
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.GetUse r(NovellContext , out NovellUserId);
string hexValue = RetCode.ToStrin g("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 NWDSCreateConte xtHandle 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:
NWDSCreateConte xtHandle
(http://developer.novell.com/ndk/doc/...7.html#sdk2687)
Syntax
C
#include <nwnet.h>
or
#include <nwdsdc.h>
N_EXTERN_LIBRAR Y (NWDSCCODE) NWDSCreateConte xtHandle (
NWDSContextHand le N_FAR *newHandle);
NWDSWhoAmI
(http://developer.novell.com/ndk/doc/...7.html#sdk2687)
Syntax
C
#include <nwnet.h>
or
#include <nwdsdsa.h>
N_EXTERN_LIBRAR Y (NWDSCCODE) NWDSWhoAmI (
NWDSContextHand le context,
pnstr8 objectName);
Any help will be appreciated.
Best regards,
Przemek