Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


either d3d, delphi or c++ problem... or none of the above...

This topic is 5871 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi everyone! i've been toying around with d3d and have created a vc++ dll which i want to use in delphi. okay, here's the dll function i want to call: extern "C" __declspec(dllexport) HRESULT initD3D(HWND hwnd, bool bFullscreen, UINT iWidth, UINT iHeight) { HRESULT hr; D3DPRESENT_PARAMETERS d3dpp; D3DDISPLAYMODE d3ddm; //creates Direct3D8 d3dmain = Direct3DCreate8( D3D_SDK_VERSION ); if(!d3dmain ) { //FatalError("Error getting Direct3D"); MessageBox(NULL, "Direct3DCreate8 Failed", "D3D", MB_OK); return(hr); } hr=d3dmain->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&d3ddm); if(FAILED(hr)) { //FatalError(hr,"Error getting display mode\n"); MessageBox(NULL, "GetAdapterDisplayMode Failed", "D3D", MB_OK); return(hr); } //clear the D3DPRESENT_PARAMETERS structure, always a good thing to do ZeroMemory(&d3dpp,sizeof(d3dpp)); d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.hDeviceWindow = hwnd; d3dpp.BackBufferCount= 1; d3dpp.EnableAutoDepthStencil = true; d3dpp.AutoDepthStencilFormat = D3DFMT_D16; d3dpp.BackBufferFormat = d3ddm.Format; //see if program should run in fullscreen or windowed if(bFullscreen) { d3dpp.Windowed = FALSE; d3dpp.BackBufferWidth = SCREENX; d3dpp.BackBufferHeight = SCREENY; } else { d3dpp.BackBufferWidth = iWidth; d3dpp.BackBufferHeight = iHeight; d3dpp.Windowed = TRUE; } if(!IsWindow(hwnd)) { MessageBox(NULL, "No legal window handle", "D3D", MB_OK); return(hr); } //finally we can create our main device hr=d3dmain->CreateDevice(D3DADAPTER_DEFAULT, //we're only using one monitor D3DDEVTYPE_HAL, //and of course the hardware accelerator hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev); if(FAILED(hr)) { //FatalError(hr,"Error creating device\n"); MessageBox(NULL, "CreateDevice Failed", "D3D", MB_OK); return(hr); } return(hr); } now, this function is a modified version of drunken hyena's first d3d-tut. calling it from inside another c++ function works just fine. but i get some 'access violation' message when calling it from delphi. here's the delphi call: var initD3D : function (hwnd : HWND ; full : Boolean) : HResult; stdcall; HD3DDLL : THandle; test : HResult; begin HD3DDLL := LoadLibrary('D3DDLL.dll'); if(HARFDLL <> 0) then begin @initD3D := GetProcAddress(HD3DDLL, 'initD3D'); test := initD3D(Form1.Handle, false); FreeLibrary(HD3DDLL); end; the way i call the dll and the functions itself works fine. the error happens somewhere around the createdevice-call. as you can see i also checked the window handle (hwnd) and it seems to be okay. so, i got this debugview-program i read about on the forum and it returns the following message: Direct3D8: (INFO) :Failed to create driver indexbuffer so, what am i doing wrong? and why does it work under c++ and not under delphi? thanks in advance! alex [edited by - denias75 on April 29, 2002 4:29:10 AM] [edited by - Denias75 on April 29, 2002 2:45:31 PM]

Share this post

Link to post
Share on other sites
You''re using 2 different methods of DLL linking. In Delphi you use static linking (.lib files) by declaring the function like this:

function InitD3D(Window: HWND; bFullScreen: Boolean): HRESULT; stdcall;


function InitD3D(Window: HWND; bFullScreen: Boolean): HRESULT; external ''D3DDLL.dll'';

Using static and dynamic DLL loading in the same program causes access violations. In VC++ you''re using .lib files to link D3D right? That''s the problem. Switch to static linking in Delphi.

void Signature(void* Pointer)
PObject(Pointer)->ShowMessage("Why do we need so many pointers?");

Share this post

Link to post
Share on other sites
well, i changed from dynamic to static linking. yet, the error still occurs.
with static linking i get the same access violation error as before, except, the address it wants to read from is NULL, while using dynamic linking it seems to want to read from some address.
i think it has something to do with the D3DPRESENT_PARAMETERS.

thanks anyway!


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!