Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Making a DLL that handles the graphics

Im currently writing a 3D-engine and i want it to be Graphics API-
independent so i want to put all the code for graphics-drawning in a DLL. I try to CreateWindow() inside the DLL (i pass pointer to HWND,
WndProc etc.) but i get alot of invalid conversion errors.
I don't have my code with
me (ill post it tommorow) but are there any good tutorials on the
topic? There are alot of information about OpenGL, Windows GDI etc but
i havent seen any on how to do it inside a DLL.

Futhermore i found a great tutorial on flipcode.org
on how to load objects without .def-files so now i can load entire
objects and not just plain C-stuff :) .

Comments

  • lostsoullostsoul Member Posts: 6
    Here is the source for the DLL:

    // dll2.cpp

    #include "dll2.h"

    char szClassName[ ] = "WindowsApp";

    bool WIN_OBJ::create_window(UINT width,
    UINT height,
    LRESULT CALLBACK (*WindowProcPointer)(HWND *hwnd,
    UINT *msg,
    WPARAM *wparam,
    LPARAM *lparam),
    HWND *hwnd,
    UINT *msg,
    WPARAM *wparam,
    LPARAM *lparam,
    HINSTANCE *hThisInstance,
    HINSTANCE *hPrevInstance,
    LPSTR *lpszArgument,
    int *nFunsterStil,
    MSG *messages,
    WNDCLASSEX *wincl)
    {
    wincl->hInstance = hThisInstance;
    wincl->lpszClassName = szClassName;
    wincl->lpfnWndProc = (LRESULT CALLBACK (*)(HWND__*, UINT, WPARAM,LPARAM))WindowProcPointer; /* This function is called by windows */
    wincl->style = CS_DBLCLKS; /* Catch double-clicks */
    wincl->cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl->hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl->hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl->hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl->lpszMenuName = NULL; /* No menu */
    wincl->cbClsExtra = 0; /* No extra bytes after the window class */
    wincl->cbWndExtra = 0; /* structure or the window instance */
    /* Use Windows's default color as the background of the window */
    wincl->hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
    return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
    0, /* Extended possibilites for variation */
    szClassName, /* Classname */
    "Windows App", /* Title Text */
    WS_OVERLAPPEDWINDOW, /* default window */
    CW_USEDEFAULT, /* Windows decides the position */
    CW_USEDEFAULT, /* where the window ends up on the screen */
    544, /* The programs width */
    375, /* and height in pixels */
    HWND_DESKTOP, /* The window is a child-window to desktop */
    NULL, /* No menu */
    hThisInstance, /* Program Instance handler */
    NULL /* No Window Creation data */
    );

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nFunsterStil);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
    {
    /* Translate virtual-key messages into character messages */
    TranslateMessage(&messages);
    /* Send message to WindowProcedure */
    DispatchMessage(&messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
    } // end bool WIN_OBJ::create_window(UINT width, ... )


    // dll2.h

    #ifndef _DLL2_H_
    #define _DLL2_H_

    #include
    #include

    #include "dll.h"

    class WIN_OBJ : public base
    {
    public:
    virtual bool create_window(UINT width,
    UINT height,
    LRESULT CALLBACK (*WindowProcPointer)(HWND *hwnd,
    UINT *msg,
    WPARAM *wparam,
    LPARAM *lparam,
    HINSTANCE *hThisInstance,
    HINSTANCE *hPrevInstance,
    LPSTR *lpszArgument,
    int *nFunsterStil,
    MSG *messages,
    WNDCLASSEX *wincl));
    }; // end class WIN_OBJ : public base

    #endif // _DLL2_H_


    // dll.h

    #ifndef _DLL_H_
    #define _DLL_H_

    #include
    #include

    class base
    {
    public:
    virtual bool create_window(UINT width,
    UINT height,
    LRESULT CALLBACK (*WindowProcPointer)(HWND *hwnd,
    UINT *msg,
    WPARAM *wparam,
    LPARAM *lparam,
    HINSTANCE *hThisInstance,
    HINSTANCE *hPrevInstance,
    LPSTR *lpszArgument,
    int *nFunsterStil,
    MSG *messages,
    WNDCLASSEX *wincl)) = 0;


    }; // end class base

    #endif // _DLL_H_



Sign In or Register to comment.