MagicFrisbee
Programmer
I have a very simple procedure which has worked for the last few versions of Delphi (2007, 2006, 2005, and 7). All it does is grab the user name of whoever is logged into the Novell Network on that computer. The sample was pretty much taken off the Novell web site (which is outdated, but the code still worked). Now, in Delphi 2009, it does not work and I suspect it has something to do with UnicodeStrings all over the product. The Novell API merely redeclares functions in Novell DLL's without wrapping them (you basically see a lot of "StdCall; external" lines in the source). However, I'm using Novell-defined types so I'm confused. Here is the code, which will only work in Delphi if you have the Novell Client installed and you've also downloaded and installed the Novell API for Delphi, which is at . Click novell-delphilib-devel-2006.06.14-1windows.zip to download it, then unzip it to the Imports folder of your Delphi product.
So, in Delphi 2007 and ealier, the result of the following function is my Novell username. In Delphi 2009 the result is weird characters.
GIS Programmer
City of Orem, UT
So, in Delphi 2007 and ealier, the result of the following function is my Novell username. In Delphi 2009 the result is weird characters.
Code:
uses
NetWin32; // NetWare Libraries (32 bit)
procedure TForm1.FormCreate(Sender: TObject);
procedure CallNetwareFunction( const ReturnCode: Integer; const FunctionName: String );
const
SUCCESS = 0;
begin
if ReturnCode <> SUCCESS then
raise Exception.Create( 'The following Netware function returned an error: ' +
FunctionName + ' (' + IntToStr( ReturnCode ) + ')' );
end;
var
NetwareContextHandle: NWDSContextHandle;
MyName: array[0..MAX_DN_CHARS] of nstr8;
pMyName: pnstr8;
ContextFlags: Integer;
begin
CallNetwareFunction( NWDSCreateContextHandle( NetwareContextHandle ),
'NWDSCreateContextHandle' );
try
//Without these next three function calls, NWDSWhoAmI will return a string that looks
//like this: CN=USERNAME.
CallNetwareFunction( NWDSGetContext( NetwareContextHandle, DCK_FLAGS, @ContextFlags ),
'NWDSGetContext' );
ContextFlags := ContextFlags or DCV_TYPELESS_NAMES;
CallNetwareFunction( NWDSSetContext( NetwareContextHandle, DCK_FLAGS, @ContextFlags ),
'NWDSSetContext' );
pMyName := @MyName;
CallNetwareFunction( NWDSWhoAmI( NetwareContextHandle, pMyName ),
'NWDSWhoAmI' );
Edit1.Text := MyName;
finally
NWDSFreeContext( NetwareContextHandle );
end;
GIS Programmer
City of Orem, UT