Undefined (Win32) Externals

Loopback elliott.darfink at gmail.com
Sun Jun 12 18:54:20 PDT 2011


On 2011-06-13 01:53, Andrej Mitrovic wrote:
> Well most API functions stay the same for a long time on Windows.
> Examples compiled in 1998 for Windows 98 will compile in 2011 for
> Windows 7, and they will both run fine. At least the simple ones will.
> The bindings /might/ be missing some new vista/win7 function
> prototypes but I'm not sure if that's true or not. And if you use
> vista/win7 features exclusively, you can say goodbye to compatibility
> with pre-vista systems (if you care about that).
>
> I'm not sure why your example is not compiling for you, it does for me:
>
> import std.c.windows.windows;
>
> extern (Windows)
> {
>         int GWL_USERDATA;
>         LONG SetWindowLong(HWND, int, LONG);
>         LONG GetWindowLong(HWND, int);
> }
>
> void main()
> {
> }
>
> But try replacing the prototypes with this (notice the A at the end):
>         LONG SetWindowLongA(HWND, int, LONG);
>         LONG GetWindowLongA(HWND, int);
>
> Which DMD version are you running?
Replacing them with their ASCII variants worked flawlessly! Though 
GWL_USERDATA is apparently undefined (0). To solve this I had to declare 
the variable explicitly:

const int GWL_USERDATA = -21;

About the WindowsAPI binding, is it fully functional for D2, since it 
seems to have been inactive for so long?

Even though I've solved this error (Set-/GetWindowLong) I've got stuck 
with another error (this might be off topic, perhaps a new thread?) 
related to DirectX. At the moment I'm using the DDirectX9 binding (at 
dsource.org). So far it's been working perfectly fine, everything 
compiles and no linker errors, but I do have problems with creating the 
Direct3D9 Device.

The reason I am asking this here (and not in a forum related to DirectX) 
is because there are no debug outputs, even with the DirectX debug DLLs, 
I guess this is related to the D debugger or the wrapper?

To get to the problem, in my code, I set up a Win32 Window like this:

// Window Properties
WNDCLASSA wnd;
		
// Setup The Properties
wnd.style = CS_HREDRAW | CS_VREDRAW;
wnd.lpfnWndProc = &WindowProc;
wnd.hInstance = hInstance;
wnd.lpszClassName = "CWindow";

// Register Class
RegisterClassA(&wnd);
		
// Create Window
m_hWnd = CreateWindowA("CWindow", "Win32&DirectX Test", 
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, null, null, 
hInstance, null);
		
// Used for static WindowProc
SetWindowLongA(m_hWnd, GWL_USERDATA, cast(LONG)(cast(void*) this));

// Show & Update The Window
ShowWindow(m_hWnd, SW_SHOW);
UpdateWindow(m_hWnd);

After this, I set up the direct3d environment with this code:

// Create Direct3D Interface
m_d3d = Direct3DCreate9(D3D_SDK_VERSION); // <--- This is successful
		
// Present Parameters
D3DPRESENT_PARAMETERS d3dpp = {0};
	
// Setup the options
d3dpp.Windowed = true;
d3dpp.SwapEffect = D3DSWAPEFFECT.D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = m_hWnd;
		
// Create Direct3D Device
HRESULT hr = m_d3d.CreateDevice(D3DADAPTER_DEFAULT, 
D3DDEVTYPE.D3DDEVTYPE_HAL, m_hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, 
&d3dpp, &m_d3dDevice);

if(FAILED(hr)) MessageBoxA(null, "Failurreeeee", "Majs", MB_ICONERROR);

The HRESULT from CreateDevice always returns the following:

HRESULT: 0x8876086c (2289436780)
Name: D3DERR_INVALIDCALL
Description: Invalid call
Severity code: Failed
Facility Code: FACILITY_D3D (2166)
Error Code: 0x086c (2156)

I've googled this a lot with no avail, and since my code is so small, 
I'm afraid it's related to D or the DirectX Wrapper. I've tried to play 
a bit with the d3dpresent parameters without success...

Once again, I'm sorry if it's inconvenient to post this here, although 
this seems like the most appropriate place.

(if worth noticing, I'm using DMD Version 2.052 and the wrapper is D1)


More information about the Digitalmars-d mailing list