XNA Creators Club Online
Page 1 of 1 (6 items)
Sort Posts: Previous Next

How to render DirectX9 on my CLR customed control?

Last post 11/29/2009 8:26 AM by akira32. 5 replies.
  • 11/11/2009 11:05 AM

    How to render DirectX9 on my CLR customed control?

    My CLR project have many Split Containers, one Container has a customed user control.
    I want to Render a cylinder with DirectX9 on the user control.
    Could somebody tell how to get windows handle of user control or render with DirectX?
  • 11/12/2009 6:04 PM In reply to

    Re: How to render DirectX9 on my CLR customed control?

    It depends on how your "customized user control" is implemented.  However, it comes down to using the windows handle (HWND) and passing that to your DirectX device.

    If you're using MFC, everything derives from CWnd.  You'll want to use CWnd::m_hWnd.

    If you're using Windows Forms with C++/CLI, everything will derive from Control, and you can use Control.Handle.


    Reed Copsey, Jr. - http://reedcopsey.com

    reference:http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/71bfe0b7-7609-4c8b-b106-f901e8f379b1
  • 11/12/2009 6:05 PM In reply to

    Re: How to render DirectX9 on my CLR customed control?

    That is my partial source code:

    public ref class PreviewView : public System::Windows::Forms::UserControl
    {

    LPDIRECT3DDEVICE9 d3ddev;

     private: void initD3D(HWND hHandle)
        {
         d3d = Direct3DCreate9(D3D_SDK_VERSION);    // create the Direct3D interface

         ZeroMemory(pd3dpp, sizeof(*pd3dpp));    // clear out the struct for use
         pd3dpp->Windowed = true;    // program windowed, not fullscreen
         pd3dpp->SwapEffect = D3DSWAPEFFECT_DISCARD;    // discard old frames
         pd3dpp->hDeviceWindow = hHandle;    // set the window to be used by Direct3D

         LPDIRECT3DDEVICE9 d3ddevTmp;

         // create a device class using this information and information from the d3dpp stuct
         d3d->CreateDevice(D3DADAPTER_DEFAULT,
          D3DDEVTYPE_HAL,
          hHandle,
          D3DCREATE_SOFTWARE_VERTEXPROCESSING,
          pd3dpp,
          &d3ddevTmp);

         d3ddev=d3ddevTmp;
        }

    When I create device, I must use another variable d3ddevTmp to return the D3DDevice and then set to d3ddev member variable. If I use d3ddev to create device, it will appear the error message as below:

    Error 1 error C2664: 'IDirect3D9::CreateDevice' : cannot convert parameter 6 from 'cli::interior_ptr<Type>' to 'IDirect3DDevice9 **' d:\svn\......\PreviewView.h 121

    Could somebody tell me how to solve this problem?

  • 11/14/2009 6:36 AM In reply to

    Re: How to render DirectX9 on my CLR customed control?

    try do it IDirect3DDevice9** d3ddevTmp
  • 11/15/2009 1:09 PM In reply to

    Re: How to render DirectX9 on my CLR customed control?

    zzzzyu:
    try do it IDirect3DDevice9** d3ddevTmp


    use pointer pointer, compile no error, but it appears one message as below when it is running.
    An unhandled exception of type 'System.AccessViolationException' occurred in Operationview.dll
  • 11/29/2009 8:26 AM In reply to

    Re: How to render DirectX9 on my CLR customed control?

    Now I had solved this problem and put the article on my blog: http://tw.myblog.yahoo.com/akira32-akira32/article?mid=483&prev=-1&next=479
Page 1 of 1 (6 items) Previous Next