May 07, 2024, 12:49:29 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Errors with Windows .inc files

Started by Hootie, October 18, 2008, 06:29:21 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Hootie

Hi,

I'm the latest noob here so please bear with me as I'm probably doing something wrong.

I'm trying to use the .inc files for the Windows libraries that are available as downloads on the site and I'm coming up with some errors as follows.

I added this line to the example code for a basic window from the docs.

$INCLUDE "d3d9.inc"

Did nothing else and just tried to compile.  Got the following errors:

Compiling...
main.eba
File: oaidl.inc (555) Duplicate interface declaration - IDispatch
File: oaidl.inc (556) STDMETHOD statement encountered outside of INTERFACE - HRESULT
File: oaidl.inc (557) STDMETHOD statement encountered outside of INTERFACE - ULONG
File: oaidl.inc (558) STDMETHOD statement encountered outside of INTERFACE - ULONG
File: oaidl.inc (560) STDMETHOD statement encountered outside of INTERFACE - HRESULT
File: oaidl.inc (561) STDMETHOD statement encountered outside of INTERFACE - HRESULT
File: oaidl.inc (562) STDMETHOD statement encountered outside of INTERFACE - HRESULT
File: oaidl.inc (563) STDMETHOD statement encountered outside of INTERFACE - HRESULT
File: oaidl.inc (564) ENDINTERFACE without matching INTERFACE - endinterface
File: d3d9types.inc (1720) invalid character '0x3b'
- ;
Error(s) in compiling "D:\DirectX 9 Test\main.eba"
Build Failed


Can anyone tell me what the problem might be?

I appreciate any help.  Thanks!

Ionic Wind Support Team

Ionic Wind Support Team

Hootie

Thanks Paul, that did the trick.  And a big thanks to Sapero for creating these.  Saves a ton of work!

Ionic Wind Support Team

I've replaced the file on the site with the newest one, so nobody else has the same problem.

Paul.
Ionic Wind Support Team

Hootie

OK, I've been messing with this for hours.  It crashes with the wonderful send to M$ window.  What am I doing wrong?


$main
$INCLUDE "d3d9.inc"
$INCLUDE "d3dx9.inc"
DEF gd3dDevice as IDirect3DDevice9
DEF md3dObject as IDirect3D9
DEF mFont as ID3DXFont
D3DDISPLAYMODE mode
D3DDEVTYPE mDevType
D3DCAPS9 caps
DWORD devBehaviorFlags = 0
DWORD mRequestedVP = 0
D3DPRESENT_PARAMETERS md3dPP
DEF w1 as WINDOW
D3DXFONT_DESC fontDesc
winrect formatRect


md3dObject = Direct3DCreate9(D3D_SDK_VERSION)
md3dObject->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &mode)
md3dObject->CheckDeviceType(D3DADAPTER_DEFAULT, mDevType, mode.Format, mode.Format, true)
md3dObject->CheckDeviceType(D3DADAPTER_DEFAULT, mDevType, D3DFMT_X8R8G8B8, D3DFMT_X8R8G8B8, false)
md3dObject->GetDeviceCaps(D3DADAPTER_DEFAULT, mDevType, &caps)

if caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT
devBehaviorFlags = devBehaviorFlags | mRequestedVP
else
devBehaviorFlags = devBehaviorFlags | D3DCREATE_SOFTWARE_VERTEXPROCESSING
endif

if (caps.DevCaps & D3DDEVCAPS_PUREDEVICE) and (devBehaviorFlags & D3DCREATE_HARDWARE_VERTEXPROCESSING) then
    devBehaviorFlags = devBehaviorFlags | D3DCREATE_PUREDEVICE
endif

OPENWINDOW w1,0,0,800,600,@MINBOX|@MAXBOX|@SIZE,NULL,"Hello Direct3D",&main
SETWINDOWCOLOR w1, RGB(255,255,255)
CENTERWINDOW w1



md3dPP.BackBufferWidth = 0
md3dPP.BackBufferHeight = 0
md3dPP.BackBufferFormat = D3DFMT_UNKNOWN
md3dPP.BackBufferCount = 1
md3dPP.MultiSampleType = D3DMULTISAMPLE_NONE
md3dPP.MultiSampleQuality = 0
md3dPP.SwapEffect = D3DSWAPEFFECT_DISCARD
md3dPP.hDeviceWindow = w1.hwnd
md3dPP.Windowed = true
md3dPP.EnableAutoDepthStencil = true
md3dPP.AutoDepthStencilFormat = D3DFMT_D24S8
md3dPP.Flags = 0
md3dPP.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT
md3dPP.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE

md3dObject->CreateDevice(D3DADAPTER_DEFAULT, mDevType, w1.hwnd, devBehaviorFlags, &md3dPP, &gd3dDevice)

fontDesc.Height = 80
fontDesc.Width = 40
fontDesc.Weight = FW_BOLD
fontDesc.MipLevels = 0
fontDesc.Italic = true
fontDesc.CharSet = DEFAULT_CHARSET
fontDesc.OutputPrecision = OUT_DEFAULT_PRECIS
fontDesc.Quality = DEFAULT_QUALITY
fontDesc.PitchAndFamily = DEFAULT_PITCH | FF_DONTCARE
fontDesc.FaceName = "Times New Roman"

D3DXCreateFontIndirect(gd3dDevice, &fontDesc, &mFont)

gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(255, 255, 255), 1.0, 0)

GetClientRect(w1.hwnd, &formatRect)

gd3dDevice->BeginScene()

mFont->DrawTextA(0, "Hello Direct3D", -1, &formatRect, DT_CENTER | DT_VCENTER, D3DCOLOR_XRGB(0, 0, 0))

gd3dDevice->EndScene()
gd3dDevice->Present(0, 0, 0, 0)




REM define a window variable
REM open the window
REM print a message
rem PRINT w1,"Hello World"
REM when w1 = 0 the window has been closed
WAITUNTIL w1 = 0
END

REM every time there is a message for our window
REM the operating system will GOSUB here
SUB main
    IF @MESSAGE = @IDCLOSEWINDOW
mFont->Release()
md3dObject->Release()
gd3dDevice->Release()
        REM closes the window and sets w1 = 0
        CLOSEWINDOW w1
    ENDIF
RETURN
ENDSUB


I tried changing everything in the headers I was using that defined a pointer to an interface from pointer type to COMDEF type but that didn't help.  I had to change the return value from Direct3DCreate9 to COMDEF because I was getting a type mismatch error.  Any help is appreciated.  Thanks!

Ionic Wind Support Team

Build a debug executable, and run it to see what line it crashes at.  Then go from there.
Ionic Wind Support Team

Hootie

No joy.  Debug doesn't mention any line and nothing is highlighted.


Call stack:
DirectX_Test! ib_main + 1237
kernel32! RegisterWaitForInputIdle + 73


Debug Window:


Starting debug session...
Loading DLL: ntdll.dll
Loading DLL: C:\WINDOWS\system32\kernel32.dll
Loading DLL: C:\WINDOWS\system32\USER32.DLL
Loading DLL: C:\WINDOWS\system32\GDI32.dll
Loading DLL: C:\WINDOWS\system32\msvcrt.dll
Loading DLL: C:\WINDOWS\system32\ADVAPI32.dll
Loading DLL: C:\WINDOWS\system32\RPCRT4.dll
Loading DLL: C:\WINDOWS\system32\Secur32.dll
Loading DLL: C:\WINDOWS\system32\D3D9.DLL
Loading DLL: C:\WINDOWS\system32\d3d8thk.dll
Loading DLL: C:\WINDOWS\system32\VERSION.dll
Loading DLL: C:\WINDOWS\system32\WINMM.dll
Loading DLL: C:\WINDOWS\system32\COMCTL32.DLL
Loading DLL: C:\WINDOWS\system32\OLE32.DLL
Loading DLL: C:\WINDOWS\system32\IMM32.DLL
Loading DLL: C:\WINDOWS\system32\uxtheme.dll
Loading DLL: C:\WINDOWS\system32\MSCTF.dll
Loading DLL: C:\WINDOWS\system32\msctfime.ime
First chance exception: Address 0x0040C535 Access Violation.
Final chance exception: Address 0x0040C535 Access Violation.


I don't know how to interpret any of this since it doesn't tell me anything I can directly tie to a line in my program.

Ionic Wind Support Team

Doesn't look like you actually built a debug executable.  Checking the "debug build" checkbox in the project options or executable options dialog.  If you did that then I would want to know if that is the complete call stack, execution has to start from somewhere.

You can also use DebugPrint to show the contents of variables while the program is running.  Since you don't have any error checking in the program, such as checking md3dObject to see if its NULL.

Insert a STOP statement in various places to see how far the code get.

Other than that confer with Sapero, I'm pretty sure he had an example using his headers and accessing dx directly.

Paul.
Ionic Wind Support Team

Hootie

Yes, I checked the debug box and did a rebuild all.

I inserted stops after almost every line and commented out the d3dx9.inc and associated calls. 

The access violations are happening in the Clear call, so the CreateDevice call is failing or mangling the Device interface pointer in some way.  I will look into it.

I had to count each stop and follow along in the code.  It appears that Sapero's headers bork the debugger in some way as nothing is ever highlighted, no line numbers ever show in the callstack and no variables ever show in the variable window.

sapero

October 19, 2008, 01:36:39 PM #9 Last Edit: October 19, 2008, 01:46:54 PM by sapero
The problem is because the D3DCAPS9 structure is 8 bytes to small, so the GetDeviceCaps method did overwrite your devBehaviorFlags and the vext variable. Missing from D3DCAPS9, but still defined members: RasterCaps and LineCaps. Both are DWORD's.
These two are also defined as constants in wingdi.inc, but Emercence does not include them to D3DCAPS9.

/*do not include headers*/
$define LINECAPS      30
type mytype
int LineCaps
int temp
endtype

messagebox 0, str$(len(mytype)), ""    <- will show 4 instead 8 :)



Hootie, open the d3d9caps.inc header, find "RasterCaps", "LineCaps" and prepend a underscore: (in d3d8caps.inc too if you wish)
type D3DCAPS9
...
DWORD   _RasterCaps
...
DWORD   _LineCaps


Thats one. Second - you are using uninitialized variables: mDevType and devBehaviorFlags. To get it working, remove the two IF's above OPENWINDOW, and paste this just after or before Direct3DCreate9:
mDevType = D3DDEVTYPE_HAL
devBehaviorFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING


I'll upload new headers shortly.

Ionic Wind Support Team

[Edit] - I see Sapero beat me to it ;)

COM generally messes with debuggers.  Since the failure isn't in the native Emergence code.

It's been a while since I have had to deal with Dx9, and I was using C++ to write Emergence's 3D library.   But the CreateDevice call can fail for a variety of reasons.  It does return an hresult, which can be one of:

D3DERR_DEVICELOST The device has been lost but cannot be reset at this time. Therefore, rendering is not possible.
D3DERR_INVALIDCALL The method call is invalid. For example, a method's parameter may have an invalid value.
D3DERR_NOTAVAILABLE This device does not support the queried technique.
D3DERR_OUTOFVIDEOMEMORY Direct3D does not have enough display memory to perform the operation.

My guess is it is returning D3DERR_INVALIDCALL as that is what I would get 90% of the time when I had a parameter wrong.

One thing I didn't see is where you are setting the device type, to either D3DDEVTYPE_HAL or D3DDEVTYPE_REF

When creating devices I usually use this startup code, which works with most cards (note: C++ code, but you can get the idea):


    if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
                                      D3DCREATE_HARDWARE_VERTEXPROCESSING,
                                      &d3dpp, &pReturn->g_pd3dDevice ) ) )
    {

if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
                                      D3DCREATE_MIXED_VERTEXPROCESSING,
                                      &d3dpp, &pReturn->g_pd3dDevice ) ) )
{
if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
  D3DCREATE_SOFTWARE_VERTEXPROCESSING,
  &d3dpp, &pReturn->g_pd3dDevice ) ) )
{
if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, hWnd,
  D3DCREATE_SOFTWARE_VERTEXPROCESSING,
  &d3dpp, &pReturn->g_pd3dDevice ) ) )
{


OutputDebugString("Failed to create D3D device");
g_pD3D->Release();
g_pD3D = NULL;
delete(pReturn);
return NULL;
}
}
}
    }


Paul.

Ionic Wind Support Team

Hootie

Thank you very much guys!  It works fine now.   ;D

Sapero, are there any other gotcha's I need to know about with the headers?  ???

Paul, I know I left the error checks out but this was supposed to be just a quick and dirty little test app.  Unfortunately, it wasn't quick but it did help me learn a lot about Ebasic coding since I knew nothing about it Friday night when I bought it.  Don't worry about C++, I know both C and C++ and a number of other languages.  Been programming professionally for 27 years.  The reason I'm messing with Ebasic is because I want a higher level, greater productivity language that still allows a programmer to get down into the bits and bytes if needed.  I will be using Ebasic to build some pretty extensive commercial apps.  It's better than what I hoping for which is a rare statement when describing most software out there.

I would like to say that this is one of the best designed and thought out pieces of software I have ever purchased and your support is top notch.  (Do you ever sleep?)

Here is the final code if anyone cares.  Note: put Paul's error checks in if using it seriously.


$main
$INCLUDE "d3d9.inc"
$INCLUDE "d3dx9.inc"
DEF gd3dDevice as IDirect3DDevice9
DEF md3dObject as IDirect3D9
DEF mFont as ID3DXFont
D3DDISPLAYMODE mode
D3DDEVTYPE mDevType = D3DDEVTYPE_HAL
D3DCAPS9 caps
DWORD devBehaviorFlags = 0
DWORD mRequestedVP = D3DCREATE_HARDWARE_VERTEXPROCESSING
D3DPRESENT_PARAMETERS md3dPP
DEF w1 as WINDOW
D3DXFONT_DESC fontDesc
winrect formatRect


md3dObject = Direct3DCreate9(D3D_SDK_VERSION)
md3dObject->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &mode)
md3dObject->CheckDeviceType(D3DADAPTER_DEFAULT, mDevType, mode.Format, mode.Format, true)
md3dObject->CheckDeviceType(D3DADAPTER_DEFAULT, mDevType, D3DFMT_X8R8G8B8, D3DFMT_X8R8G8B8, false)
md3dObject->GetDeviceCaps(D3DADAPTER_DEFAULT, mDevType, &caps)

if caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT
devBehaviorFlags = devBehaviorFlags | mRequestedVP
else
devBehaviorFlags = devBehaviorFlags | D3DCREATE_SOFTWARE_VERTEXPROCESSING
endif

if (caps.DevCaps & D3DDEVCAPS_PUREDEVICE) and (devBehaviorFlags & D3DCREATE_HARDWARE_VERTEXPROCESSING) then
    devBehaviorFlags = devBehaviorFlags | D3DCREATE_PUREDEVICE
endif

OPENWINDOW w1,0,0,800,600,@MINBOX|@MAXBOX|@SIZE,NULL,"Hello Direct3D",&main
SETWINDOWCOLOR w1, RGB(255,255,255)
CENTERWINDOW w1



md3dPP.BackBufferWidth = 0
md3dPP.BackBufferHeight = 0
md3dPP.BackBufferFormat = D3DFMT_UNKNOWN
md3dPP.BackBufferCount = 1
md3dPP.MultiSampleType = D3DMULTISAMPLE_NONE
md3dPP.MultiSampleQuality = 0
md3dPP.SwapEffect = D3DSWAPEFFECT_DISCARD
md3dPP.hDeviceWindow = w1.hwnd
md3dPP.Windowed = true
md3dPP.EnableAutoDepthStencil = true
md3dPP.AutoDepthStencilFormat = D3DFMT_D24S8
md3dPP.Flags = 0
md3dPP.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT
md3dPP.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE

md3dObject->CreateDevice(D3DADAPTER_DEFAULT, mDevType, w1.hwnd, devBehaviorFlags, &md3dPP, &gd3dDevice)

fontDesc.Height = 80
fontDesc.Width = 40
fontDesc.Weight = FW_BOLD
fontDesc.MipLevels = 0
fontDesc.Italic = true
fontDesc.CharSet = DEFAULT_CHARSET
fontDesc.OutputPrecision = OUT_DEFAULT_PRECIS
fontDesc.Quality = DEFAULT_QUALITY
fontDesc.PitchAndFamily = DEFAULT_PITCH | FF_DONTCARE
fontDesc.FaceName = "Times New Roman"

D3DXCreateFontIndirect(gd3dDevice, &fontDesc, &mFont)

gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(255, 255, 255), 1.0, 0)
GetClientRect(w1.hwnd, &formatRect)
gd3dDevice->BeginScene()

mFont->DrawTextA(0, "Hello Direct3D", -1, &formatRect, DT_CENTER | DT_VCENTER, D3DCOLOR_XRGB(0, 0, 0))

gd3dDevice->EndScene()
gd3dDevice->Present(0, 0, 0, 0)



REM define a window variable
REM open the window
REM print a message
rem PRINT w1,"Hello World"
REM when w1 = 0 the window has been closed
WAITUNTIL w1 = 0
stop
END

REM every time there is a message for our window
REM the operating system will GOSUB here
SUB main
    IF @MESSAGE = @IDCLOSEWINDOW
mFont->Release()
md3dObject->Release()
gd3dDevice->Release()
        REM closes the window and sets w1 = 0
        CLOSEWINDOW w1
    ENDIF
RETURN
ENDSUB

Ionic Wind Support Team

Quote
I would like to say that this is one of the best designed and thought out pieces of software I have ever purchased and your support is top notch.  (Do you ever sleep?)

Thanks.  And yes I do sleep once in a while ;).   I just keep very different hours than the average person, prefer to do most of my coding between 11PM and 4AM.

Paul.
Ionic Wind Support Team

LarryMc

Quote from: Hootie on October 19, 2008, 02:52:40 PM
I would like to say that this is one of the best designed and thought out pieces of software I have ever purchased and your support is top notch.
You've learned over the weekend what some of us have known for several years.

Glad you've joined us and looking forward to you posting lot's of neat coding tricks.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

I tried to smother my typing finger but I can't resist.

I've got to ask;

How's the Blowfish? ;D

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Hootie

Quote from: Larry McCaughn on October 19, 2008, 03:42:01 PM
I tried to smother my typing finger but I can't resist.

I've got to ask;

How's the Blowfish? ;D

Larry

Lol, someone always has to ask that.  Hootie is what my wife calls me because I'm a notorious night owl.  Kinda like Paul.