RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

SafeHandle cannot be null

Shino90

Sorceror
SafeHandle cannot be null

Hey everyone!

I'm trying Ultima.dll for the first time, and every function gives me an ArgumentNullException. It says "SafeHandle cannot be null". (I'm calling "Ultima.Client.Calibrate();" at form load.)

Huge StackTrace:
StackTrace said:
bij Ultima.NativeMethods.IsWindow(SafeFileHandle window)
bij Ultima.Client.get_Handle()
bij Ultima.Client.get_Running()
bij Ultima.Client.get_ProcessStream()
bij Ultima.Client.Calibrate(CalibrationInfo[] info)
bij Ultima.Client.Calibrate()
bij Mappy.frm_main.btn_calibrate_Click(Object sender, EventArgs e) in C:\Documents and Settings\Shino\Mijn documenten\Visual Studio 2008\Projects\Mappy\Mappy\Form1.cs:regel 31
bij System.Windows.Forms.Control.OnClick(EventArgs e)
bij System.Windows.Forms.Button.OnClick(EventArgs e)
bij System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
bij System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
bij System.Windows.Forms.Control.WndProc(Message& m)
bij System.Windows.Forms.ButtonBase.WndProc(Message& m)
bij System.Windows.Forms.Button.WndProc(Message& m)
bij System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
bij System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
bij System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
bij System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
bij System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
bij System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
bij System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
bij System.Windows.Forms.Application.Run(Form mainForm)
bij Mappy.Program.Main() in C:\Documents and Settings\Shino\Mijn documenten\Visual Studio 2008\Projects\Mappy\Mappy\Program.cs:regel 18
bij System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
bij System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
bij Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
bij System.Threading.ThreadHelper.ThreadStart_Context(Object state)
bij System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
bij System.Threading.ThreadHelper.ThreadStart()

For some reason my compiler is Dutch. Anyway, "bij" means "at", "regel" means "line". :)

Does anyone know what I'm doing wrong?
 

arul

Sorceror
I'll ask Jeff why he replaced IntPtr with SafeFileHandle. Besides that, do you have the client running at the time of executing the method?
 

Dereckson

Sorceror
Here a use sample:

PHP:
            if (Client.Running) {
                int x = 0, y = 0, z = 0, facet = 0;

                //Calibrates to get correct coords
                Client.Calibrate();

                //Get location (if possible) and then [your code logic]
                if (Client.FindLocation(ref x, ref y, ref z, ref facet)) {
                   #...  
                   #Your instructions
                   #...
                }
            }

And the reason your compiler is in Dutch is absolutely not blur: it's you've installed the Dutch localization of .Net, that's absolutely normal as you've a Dutch Windows version...
 

Shino90

Sorceror
arul;781638 said:
I'll ask Jeff why he replaced IntPtr with SafeFileHandle. Besides that, do you have the client running at the time of executing the method?
Yes, the client is running and connected to UOGamers: Hybrid.

Dereckson;781639 said:
And the reason your compiler is in Dutch is absolutely not blur: it's you've installed the Dutch localization of .Net, that's absolutely normal as you've a Dutch Windows version...
Thanks for clearing that up. :p

I tried your exact code example, and "Client.Running" in the first if statement gives me the ArgumentNullException. (Same error as before, "SafeHandle cannot be null".) I get the same error whether or not the UO client is running.
 

Dereckson

Sorceror
Annoying. I'm going to add an extra try/catch block to the app I use it.

On the Ultima.dll I Use (build 1.0.3184.16056), I've, as Arul notes, an IntPt (*)r. so maybe you should try with an older version.


(*) e.g. the get accessor of the Running property is return Handle != IntPtr.Zero and the FindHandle method have IntPtr as return type, using user32.dll FindWindowA functon.
 

arul

Sorceror
I'd suggest replacing all the SafeFileHandle's with IntPtr and making appropriate code changes (there shouldn't be much of 'em) for the time being until we update the source in the repository.
 

Shino90

Sorceror
arul;781651 said:
I'd suggest replacing all the SafeFileHandle's with IntPtr and making appropriate code changes (there shouldn't be much of 'em) for the time being until we update the source in the repository.
I tried that, but I guess I'm not that good with C# yet. :D

I'll just use the good old dll from this topic, which seems to work fine.
 

Jeff

Lord
The ideal situation would be to replace those issues with SafeFileHandle.IsInvalid. I will try and update that soon.
 

arul

Sorceror
I have updated the CodePlex's repository and binary DLL's with slightly modified and working code.
 
Top