-
Direct X and VB.Net...
Has anyone tried to write a VB.Net game yet?
I'm getting this error:
"Cast from type 'IntPtr' to type 'Integer' is not valid"
Here is where the error is happening:
g_D3DDevice = g_D3D.CreateDevice(D3DADAPTER_DEFAULT, DevType, hWnd, DevBehaviorFlags, g_D3DWindow)
It's hWnd that's causing the problem. I am passing picturebox.Handle as the hWnd parameter. If I change hWnd to hWnd.ToInt32 within the function I get a similar type of error:
"Specified cast is not valid"
How does one use windows handles with Directx and .Net? I can't find any documentation on the MS sites.
-
If I'm not mistaken, the .Handle is equivalent to the .hDC of a control, not the .hWnd. Look for something like Window, Window Handle, etc.
-
.Handle returns a System.IntPtr . Which, I thought, was the same. I tried using hWnd.ToInt32 but then I get an "Invalid cast error". I'm still searching around for an answer but have been coming up short. I hoping that someone here has run into it and found a work around.
Thanks for your reply,
-
Well that's just the thing - I've never used VB.NET, so everything I say here is just out of my mind (which, I must add, you can't trust. Keep that in mind ;)).
Oh, looking at your first post it looks like you're trying to cast a pointer to an integer. What you'll need to do is read the value of the pointer, which is already an integer. In C++, we do it like this, but I don't know about VB.NET...
-
I believe that's what the .ToInt32 returns. In break mode it shows a number where as the hWnd by itself shows an object of system.IntPtr .
I must be out of my mind to try something like this LOL. I can't find any documentation on it anywhere. Kinda just feeling my way through it.
Thanks for your input.
-
Maybe try signed/unsigned integers, and if that doesn't work, try Int16, because Int32 = Long and Int16 = Integer.
-
Believe it or not I found the problem out while trying the same thing in VB6.
Calling hWnd.ToInt32 was correct, the problem was that I declared g_D3DDevice as DxVBLibA.Direct3D8 and not as DxVBLibA.Direct3DDevice8 like I should have...oops
Thanks again,