ZFX
ZFX Neu
Home
Community
Neueste Posts
Chat
FAQ
IOTW
Tutorials
Bücher
zfxCON
ZFXCE
Mathlib
ASSIMP
NES
Wir über uns
Impressum
Regeln
Suchen
Mitgliederliste
Membername:
Passwort:
Besucher:
4419845
Jetzt (Chat):
15 (0)
Mitglieder:
5239
Themen:
24223
Nachrichten:
234554
Neuestes Mitglied:
-insane-

ZFX
Coding-Foren
Sourcecode-Probleme
Funktion in Dll aufrufen klappt nicht
Normal
AutorThema
exploid Bin Kaffee holen
ZFX'ler


Registriert seit:
21.08.2005

Deutschland
Funktion in Dll aufrufen klappt nichtNach oben.
Hallo

Ich versuche eine Funktion in einer Dll aufzurufen:
Code:
/*----------------------------------------------------------------*/
/*----------------------File: D3D.h-------------------------------*/ 
/*----------------------------------------------------------------*/
#ifndef D3D_H
#define D3D_H

#include 
#include            // ?????direct3d 9 interface
#include \"RenderDevice.h\"    // Interface Schablone


BOOL WINAPI DllEntryPoint( HINSTANCE hDll,
                           DWORD     fdwReason,
                           LPVOID    lpvRserved );

#define DLL extern \"C\" __declspec(dllexport)
DLL HRESULT CreateRenderDevice(HINSTANCE hDLL, RenderDevice **pInterface);  
DLL HRESULT ReleaseRenderDevice(RenderDevice **pInterface);

// D E F I N E S

#define MAXADAPTERS 20

// all adapter found
class D3DEnumAdapterInfo {
    public:
        D3DEnumAdapterInfo()        { m_dwNumAdapters = 0; }
       ~D3DEnumAdapterInfo(void)    { ;/* nothing to do */ }

        HRESULT EnumAdapters(void);

        IDXGIAdapter*                m_pAdapterInfo[MAXADAPTERS];    // more than 20 adapters are not owned by a normal pc user
        DWORD                        m_dwNumAdapters;                // number of found adapters

}; // class
/*----------------------------------------------------------------*/

// all devices capable to render
class D3DEnumDeviceInfo {
    public:
        D3DEnumDeviceInfo()        { ;/* nothing to do yet */ }
       ~D3DEnumDeviceInfo(void)    { ;/* nothing to do */ }
}; // class
/*----------------------------------------------------------------*/

// all Output Devices capable to display scene
class D3DEnumOutputInfo {
    public:
        D3DEnumOutputInfo()        { ;/* nothing to do yet */ }
       ~D3DEnumOutputInfo(void)    { ;/* nothing to do */ }
}; // class
/*----------------------------------------------------------------*/

// 
class D3DEnumDeviceCombo {
    public:
        D3DEnumDeviceCombo()        { ;/* nothing to do yet */ }
       ~D3DEnumDeviceCombo(void)    { ;/* nothing to do */ }
}; // class
/*----------------------------------------------------------------*/


// enumeration stuff
class D3DEnum {
    public:
        D3DEnum()  { ;/* nothing to do yet */ }
        ~D3DEnum(void) { ;/* nothing to do */ }
        
        // enumerate everything
        HRESULT Enum(/*    HWND hAdapter, HWND hMode,
                        HWND hDevice,  HWND hAdapterFmt,
                        HWND hBackFmt, HWND hWnd,
                        HWND hFull,    FILE *pLog*/);
    private:
        // handle to GUI items given from d3d dialog
        HWND m_hADAPTER;        // adapter combobox 
        HWND m_hMODE;            // mode combobox
        HWND m_hDEVICE;            // device combobox
        HWND m_hADAPTERFMT;        // adapter format combobox
        HWND m_hBACKFMT;        // backbuffer fmt combobox
        HWND m_hWND;            // radiobtn windowed
        HWND m_hFULL;            // radiobtn fullscreen

        //D3DEnumAdapterInfo EnumAdapterInfo;        // all found adapters

        FILE    *m_pLog;        // log file opened by d3d class
}; // class
/*----------------------------------------------------------------*/

/**
 * Class definition for a Direct3D render device, implementing the
 * interface RenderDevice
 */
class D3D : public RenderDevice {
    public:
        D3D(HINSTANCE hDLL);
        ~D3D(void);

        // initialize the engine stuff
        BOOL CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM);
        HRESULT   Init(HWND hWnd,  bool bSaveLog);

        // INTERFACE FUNCTIONS:
        // ====================

        // general stuff
        void      Release(void);

    private:
        D3DEnum                   *m_pEnum;                // enumerate d3d
        //LPDIRECT3D10            m_pD3D;                    // direct3d interface
        //ID3D10Device*            m_pd3dDevice = NULL;    // direct3d device

        UINT      m_nMinWidth;     // minimum screen with
        UINT      m_nMinHeight;    // minimum screen height
        UINT      m_nMinBits;      // minimum backbuffer bits

        
        // write to log file
        void Log(char *, ...);
}; // class
/*----------------------------------------------------------------*/


#endif

Code:
/*----------------------------------------------------------------*/
/*----------------------File: D3D.cpp------------------------*/ 
/*----------------------------------------------------------------*/

#include        // type definitions
#include            // show bmp's
#include \"resource.h\"      // control id's
#include \"errors.h\"        // return values and stuff
#include \"D3D.h\"
//#include \"D3D_skinman.h\" // texture manager
#include \"CPU.h\"


#pragma comment(lib, \"vfw32.lib\")
#pragma comment(lib, \"d3d10.lib\")
/*#pragma comment(lib, \"dxguid.lib\")
*/

bool g_bLF=false;

// we need this for dialog callback only
D3D *g_D3D=NULL;

//Bitmap for dialog
HBITMAP        g_hBMP;

// store result when dialog is closed
/*
DEVICEINFO   g_xDevice;
D3DDISPLAYMODE g_Dspmd;
D3DFORMAT      g_fmtA;
D3DFORMAT      g_fmtB;
HBITMAP        g_hBMP;
*/


/*-----------------------------------------------------------*/
/* DLL stuff implementation                                  *
/*-----------------------------------------------------------*/

/**
 * DLL Entry Point similar to WinMain()/main()
 */
BOOL WINAPI DllEntryPoint(HINSTANCE hDll,
                          DWORD     fdwReason,
                          LPVOID    lpvReserved) {
   switch(fdwReason) {
      // called when we attach to the DLL
      case DLL_PROCESS_ATTACH:
         /* dll init/setup stuff */
         break;
      case DLL_PROCESS_DETACH:
         /* dll shutdown/release stuff */
         break;
      default:
         break;
      };
   
   return TRUE;
   } // DllEntryPoint
/*----------------------------------------------------------------*/

/**
 * Exported create function: Creates a new RenderDevice object.
 */
extern \"C\" __declspec(dllexport) HRESULT CreateRenderDevice(HINSTANCE hDLL, RenderDevice **pDevice) {
   if(!*pDevice) {
      *pDevice = new D3D(hDLL);
      return S_OK;
      }
   return S_FALSE;
   }
/*----------------------------------------------------------------*/

/**
 * Exported release function: Realeses the given BKRenderDevice object.
 */
extern \"C\" __declspec(dllexport) HRESULT ReleaseRenderDevice(RenderDevice **pDevice) {
   if(!*pDevice) {
      return S_FALSE;
      }
   delete *pDevice;
   *pDevice = NULL;
   return S_OK;
   }
/*----------------------------------------------------------------*/



// give helping hand to class implementation of callback function
BOOL CALLBACK DlgProcWrap(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam)
   { return g_D3D->DlgProc(hDlg, message, wParam, lParam); }
/*----------------------------------------------------------------*/



/*-----------------------------------------------------------*/
/* BKD3D class implementation                               *
/*-----------------------------------------------------------*/

/**
 * Constructor
 */
D3D::D3D(HINSTANCE hDLL) {
 
    m_hDLL              = hDLL;
    m_pEnum             = NULL;
//    m_pD3D              = NULL;
//    m_pDevice           = NULL;
    m_pLog              = NULL;
/*    m_ClearColor        = D3DCOLOR_COLORVALUE(0.0f,0.0f,0.0f,1.0f);
   m_bRunning          = false;
   m_bIsSceneRunning   = false;
   m_bUseShaders       = false;
   m_bCanDoShaders     = false;
   m_bAdditive         = false;
   m_bColorBuffer      = true;
   m_bTextures         = true;
   m_pSkinMan          = NULL;
   m_pVertexMan        = NULL;

   m_pDeclVertex       = NULL;
   m_pDeclPVertex      = NULL;
   m_pDeclLVertex      = NULL;
   m_pDeclCVertex      = NULL;
   m_pDecl3TVertex     = NULL;
   m_pDeclTVertex      = NULL;

   m_pFont             = NULL;

   // dont use swapchain at first
   m_nActivehWnd       = 0;
   m_nNumVShaders      = 0;
   m_nNumPShaders      = 0;
   m_nNumFonts         = 0;

   g_D3D = this;
*/
   fopen_s(&m_pLog, \"Log_RenderDevice.txt\", \"w\");
   Log(\"[D3D::D3D]: online (waiting for initialization call)\n\");
   }
/*----------------------------------------------------------------*/


/**
 * Destructor
 */ 
D3D::~D3D() {
   Release();
   }
/*----------------------------------------------------------------*/


/**
 * Release all the Direct3D COM stuff.
 */
void D3D::Release() {
    // our own stuff

    Log(\"[D3D::Release]: offline (ok)\n\");
    fclose(m_pLog);
}
/*----------------------------------------------------------------*/


/**
 * Initialize dialogbox to select device and format. Dialog must
 * have ID using -\"- signs and must have combobox \"IDC_ADAPTER\",
 * listbox \"IDC_MODES\", radiobuttons \"IDC_FULL\" and \"IDC_WND\",
 * and Buttons \"IDOK\" and \"IDCANCEL\".
 
 */
HRESULT D3D::Init(HWND hWnd,  bool bSaveLog) {
   int nResult;

   m_hWndMain = hWnd;

//   if (nMinStencil > 0)
//      m_bStencil = true;

   // create enum object
   m_pEnum = new D3DEnum();

   Log(\"[D3D::Init]: calling dialog\n\");

   // call device selection dialog
   nResult = DialogBox(m_hDLL, L\"dlgChangeDevice\", hWnd, DlgProcWrap);

   Log(\"[D3D::Init]: dialog finished\n\");

   // dialog failed somehow
   if (nResult == -1) {
      Log(\"[D3D::Init]: error: selection dialog error\n\");
      return _FAIL;
      }
   // dialog was canceled by user
   else if (nResult == 0) {
      Log(\"[D3D::Init]: warning: selection dialog canceled by user\n\");
      return _CANCELED;
      }
   else if (nResult == -2) {
      Log(\"[D3D::Init]: error: no compatible graphics adapter\n\");
      return _NOTCOMPATIBLE;
      }
   // dialog ended with ok button
   else {
      Log(\"[D3D::Init]: firing up MS Direct3D\n\");
      //return Go();
      }

   return nResult;
}
/*----------------------------------------------------------------*/

/**
 * write outputstring to attribut outputstream if exists
 * -> IN: FILE - pointer to logfile stream or NULL
 */
void D3D::Log(char *chString, ...) {

   char ch[256];
   char *pArgs;
   
   pArgs = (char*) &chString + sizeof(chString);
   vsprintf_s(ch, sizeof(ch), chString, pArgs) ;
   fprintf(m_pLog, ch);
   
   #ifdef _DEBUGFLUSH_
   fflush(m_pLog);
   #endif
   }
/*----------------------------------------------------------------*/

/**
 * Callback function to handle the device/mode selection dialog
 */
BOOL CALLBACK D3D::DlgProc(HWND hDlg, UINT message, 
                           WPARAM wParam, LPARAM lParam) {
   DIBSECTION dibSection;
   BOOL       bWnd=FALSE;
   HRESULT    hr=_OK;
   
   // get handles
   HWND hFULL       = GetDlgItem(hDlg, IDC_FULL);
   HWND hWND        = GetDlgItem(hDlg, IDC_WND);
   HWND hADAPTER    = GetDlgItem(hDlg, IDC_ADAPTER);
   HWND hMODE       = GetDlgItem(hDlg, IDC_MODE);
   HWND hADAPTERFMT = GetDlgItem(hDlg, IDC_ADAPTERFMT);
   HWND hBACKFMT    = GetDlgItem(hDlg, IDC_BACKFMT);
   HWND hDEVICE     = GetDlgItem(hDlg, IDC_DEVICE);
   
   switch (message) {
      
      // preselect windowed
      case WM_INITDIALOG: {
         SendMessage(hWND, BM_SETCHECK, BST_CHECKED, 0);
         hr = m_pEnum->Enum(/*hADAPTER, hMODE,  hDEVICE, 
                             hADAPTERFMT, hBACKFMT,
                             hWND, hFULL, m_pLog*/); // <- AUFRUF SCHLÄGT FEHL MIT FEHLERMELDUNG
         
         if (hr == _NOTCOMPATIBLE)
            EndDialog(hDlg, -2);
         else if (hr == _FAIL)
            EndDialog(hDlg, -1);

         //CPUinfo holen und Checkboxes checken
/*         CPUINFO info;
         info = CheckCPU();         
         if(info.bSSE)        CheckDlgButton(hDlg, IDC_SSE, BST_CHECKED);
         if(info.bSSE2)        CheckDlgButton(hDlg, IDC_SSE2, BST_CHECKED);
         if(info.bSSE3)        CheckDlgButton(hDlg, IDC_SSE3, BST_CHECKED);
         if(info.b3DNOW)    CheckDlgButton(hDlg, IDC_3DNOW, BST_CHECKED);
         if(info.b3DNOWEX)    CheckDlgButton(hDlg, IDC_3DNOWEX, BST_CHECKED);
         if(info.bMMX)        CheckDlgButton(hDlg, IDC_MMX, BST_CHECKED);
         if(info.bMMXEX)    CheckDlgButton(hDlg, IDC_MMXEX, BST_CHECKED);
         if(info.bEXT)        CheckDlgButton(hDlg, IDC_EXT, BST_CHECKED);

         SetDlgItemText(hDlg, IDC_Vendor, info.vendor);    
         SetDlgItemText(hDlg, IDC_Processorname, info.name);
*/
         return TRUE;
         }
         
      // draw  logo
      case WM_PAINT: {
         if (g_hBMP) {
            GetObject(g_hBMP, sizeof(DIBSECTION), &dibSection);
            HDC      hdc = GetDC(hDlg);
            HDRAWDIB hdd = DrawDibOpen();
            DrawDibDraw(hdd, hdc, 50, 10, 95, 99, 
                        &dibSection.dsBmih,
                        dibSection.dsBm.bmBits, 0, 0, 
                        dibSection.dsBmih.biWidth, 
                        dibSection.dsBmih.biHeight, 0);
            DrawDibClose(hdd);
            ReleaseDC(hDlg, hdc);
            }
         } break;

      // control changed
      case WM_COMMAND: {
         switch (LOWORD(wParam)) {
            
            // okay button => read selections
            case IDOK: {
    //           m_bWindowed = !SendMessage(hFULL, BM_GETCHECK, 0, 0);
    //           m_pEnum->GetSelections(&g_xDevice, &g_Dspmd, &g_fmtA, &g_fmtB);
    //           GetWindowText(hADAPTER, (LPWSTR)m_chAdapter, 256);
               EndDialog(hDlg, 1);
               return TRUE;
               } break;
               
            // cancel button
            case IDCANCEL: {
               EndDialog(hDlg, 0);
               return TRUE;
               } break;

               
            case IDC_ADAPTER: {
               if(HIWORD(wParam)==CBN_SELCHANGE)
      //            m_pEnum->ChangedAdapter();
                    ;
               } break;


            case IDC_DEVICE: {
               if(HIWORD(wParam)==CBN_SELCHANGE) {
        //          m_pEnum->ChangedDevice();
                  }
               } break;

            case IDC_ADAPTERFMT: {
               if(HIWORD(wParam)==CBN_SELCHANGE)
          //        m_pEnum->ChangedAdapterFmt();
                    ;
               } break;


            case IDC_FULL: case IDC_WND: {
            //   m_pEnum->ChangedWindowMode();
               } break;
             
            } // switch [CMD]
         } break; // case [CMD]
      } // switch [MSG]
   return FALSE;
   }
/*----------------------------------------------------------------*/


Code:
/*----------------------------------------------------------------*/
/*----------------------File: D3D_enum.cpp------------------------*/ 
/*----------------------------------------------------------------*/
#include \"d3d.h\"

// L I B R A R I E S
#pragma comment(lib, \"DXGI.lib\")

// F U N C T I O N S ///////////////////////////////////////////////

/**
 * Enumerates all available display modes and fills the given combo
 * boxes with corresponding values.
 * -> IN: HWND - combobox to receive available adapters
 *        HWND - combobox used for display modes
 *        HWND - combobox used for device types
 *        HWND - combobox used for adapter formats
 *        HWND - combobox used for backbuffer formats
 *        HWND - radiobutton windowed
 *        HWND - radiobutton fullscreen
 *        FILE - already open log file
 */
HRESULT D3DEnum::Enum() {
                          
    HRESULT hr;
/*    
    if (pLog) m_pLog = pLog;

    // save handles to comboboxes
    m_hADAPTER    = hAdapter;
    m_hMODE       = hMode;
    m_hDEVICE     = hDevice;
    m_hADAPTERFMT = hAdapterFmt;
    m_hBACKFMT    = hBackFmt;
    m_hWND        = hWnd;
    m_hFULL       = hFull;

    // enumerate available adapters
    hr = EnumAdapterInfo.EnumAdapters();
*/
    return S_OK;
}
/*----------------------------------------------------------------*/

HRESULT D3DEnumAdapterInfo::EnumAdapters(void) {
    return S_OK;
}
/*----------------------------------------------------------------*/


Das ist die dll

Der Dialog wird aufgerufen über eine Applikation welche die dll lädt.
Code:
// FILE: main.cpp

#define WIN32_MEAN_AND_LEAN

#include \"Renderer.h\"  // our render interface
//#include \"bkerrors.h\"          // return values and stuff
#include \"main.h\"         // prototypes and stuff

//include our library
#pragma comment(lib, \"Renderer_01.lib\")


// windows stuff
HWND      g_hWnd  = NULL;
HINSTANCE g_hInst = NULL;
TCHAR     g_szAppClass[] = TEXT(\"FrameWorktest\");

// application stuff
BOOL g_bIsActive = FALSE;
bool g_bDone     = false;
UINT g_nFontID=0;

FILE *pLog=NULL;


// renderer object
LPRenderer     g_pRenderer = NULL;
LPRenderDevice g_pDevice   = NULL;


/**
 * WinMain function to get the thing started.
 */
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, 
                   LPSTR lpCmdLine, int nCmdShow) {
    WNDCLASSEX    wndclass;
    HRESULT     hr;
    HWND        hWnd;
    MSG            msg;
   
   // Set up window attributes
   wndclass.cbSize         = sizeof(wndclass);
   wndclass.style          = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS;
   wndclass.lpfnWndProc    = MsgProc;
   wndclass.cbClsExtra     = 0;
   wndclass.cbWndExtra     = 0;
   wndclass.hInstance      = hInst;
   wndclass.hIcon          = LoadIcon(NULL, IDI_APPLICATION);
   wndclass.hCursor        = LoadCursor(NULL, IDC_ARROW);
   wndclass.hbrBackground  = (HBRUSH)(COLOR_WINDOW);
   wndclass.lpszMenuName   = NULL;
   wndclass.lpszClassName  = g_szAppClass;
   wndclass.hIconSm        = LoadIcon(NULL, IDI_APPLICATION);
    
   if(RegisterClassEx(&wndclass) == 0)
      return 0;

   // create window
   if (!(hWnd = CreateWindowEx(NULL, g_szAppClass,
                                  L\"3d bibos klappen o.O ...\",
                               WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                                GetSystemMetrics(SM_CXSCREEN)/2 -190,
                               GetSystemMetrics(SM_CYSCREEN)/2 -140,
                               380, 280, NULL, NULL, hInst, NULL)))
      return 0;
     
   g_hWnd  = hWnd;
   g_hInst = hInst;

   pLog = fopen(\"log_applikation_main.txt\", \"w\");

   // try to start the engine
   if (FAILED( hr = ProgramStartup(\"Direct3D\"))) {
      fprintf(pLog, \"error: ProgramStartup() failed\n\");
      g_bDone = true;
      }
   else if (hr == S_FALSE) {
      fprintf(pLog, \"error: ProgramStartup() canceled by user \n\");
      g_bDone = true;
      }
   else 
        ;//g_pDevice->SetClearColor(0.0f, 0.0f, 1.0f);
        

   
   while (!g_bDone)
      {
      while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
          {
             TranslateMessage(&msg);
            DispatchMessage(&msg);
         }

      if (g_bIsActive)
         { /* 
         if (g_pDevice->IsRunning()) {
            //g_pDevice->BeginRendering(true,true,true);
            //g_pDevice->UseShaders(false);
            //g_pDevice->DrawText(g_nFontID, 20, 10, 255, 255, 0, 
            //           \"Testtext\");
            //g_pDevice->EndRendering();
            }*/
         }
      }
   
   // cleanup stuff
   ProgramCleanup();

   UnregisterClass(g_szAppClass, hInst);
   
   // return back to windows
   return S_OK;//msg.wParam;
   } // WinMain
/*----------------------------------------------------------------*/

/**
 * MsgProc to deal with incoming windows messages.
 */
LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
   switch(msg) {
      // our app has the focus
      case WM_ACTIVATE: {
         g_bIsActive = (BOOL)wParam;
         } break;
         
      // key was pressed
      case WM_KEYDOWN: {
         switch (wParam) {
            case VK_ESCAPE: {
               g_bDone = true;
               PostMessage(hWnd, WM_CLOSE, 0, 0);
               return 0;
               } break;
            }
         } break;

      // we are ordered to suicide
      case WM_DESTROY: {
             g_bDone = true;
             PostQuitMessage(0);
             return 1;
         } break;

      default: break;
      }
   
   return DefWindowProc(hWnd, msg, wParam, lParam);
   }
/*----------------------------------------------------------------*/
 
/**
 * Create a render device and stuff. 
 */
HRESULT ProgramStartup(char *chAPI) {
   HWND hWnd3D[4];
   RECT rcWnd;
   int  x=0,y=0;
   HRESULT hr;
   
   // no opengl render device yet...
   if (strcmp(chAPI, \"OpenGL\")==0) return S_OK;

   // create a render objekt
   g_pRenderer = new Renderer(g_hInst);
   
   // create a device for the chosen api
   if (FAILED( g_pRenderer->CreateDevice(chAPI) )) return E_FAIL;
   
   // get a pointer on that device
   g_pDevice = g_pRenderer->GetDevice();
   if(g_pDevice == NULL) return E_FAIL;

   // build for child windows
   GetClientRect(g_hWnd, &rcWnd);

/*   for (int i=0; i<4; i++) {
      if ( (i==0) || (i==2) ) x = 10;
      else x = rcWnd.right/2 + 10;

      if ( (i==0) || (i==1) ) y = 10;
      else y = rcWnd.bottom/2 + 10;

      hWnd3D[i] = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT(\"static\"), 
                           NULL, WS_CHILD | SS_BLACKRECT | WS_VISIBLE,
                           x, y, rcWnd.right/2-20, rcWnd.bottom/2-20, 
                           g_hWnd, NULL, g_hInst, NULL);
      }
*/
   // init render device
   hr = g_pDevice->Init(g_hWnd,/* hWnd3D, 4, 16, 0,*/ false); //<- DLL Funktion wird hier aufgerufen
   
   POINT ptRes; int fs=0;
//   g_pDevice->GetResolution(&ptRes);

   // font size
   fs  = 80;
   
 /*  if (FAILED( g_pDevice->CreateFont(\"Arial\", 0, false, false,
                                     false, fs, &g_nFontID) )) {
      fprintf(pLog, \"error: ZFXRenderDevice::CreateFont failed\n\");
      return BK_FAIL;
      }*/
   return hr;
   } // ProgramStartup
/*----------------------------------------------------------------*/

/**
 * Release the render device and stuff.
 */
HRESULT ProgramCleanup(void) {
   if (g_pRenderer) {
      delete g_pRenderer;
      g_pRenderer = NULL;
      }

   if (pLog)
      fclose(pLog);

   return S_OK;
   } // ProgramCleanup
/*----------------------------------------------------------------*/

Applikation

Die Applikation lädt eine normale Library welche Funktionen besitzen um ein Interface aus der dll zu liefern. Halt genauso wie im Buch 3d Spiele Programmierung. Das klappt auch reibungsfrei.

Doch die Applikation stürzt ab und es konnte mit dem Debugger die markierte Stelle in der Applikation als Absturzort zurückverfolgt werden.

hr = g_pDevice->Init(g_hWnd,/* hWnd3D, 4, 16, 0,*/ false);

da wird dann die Enumeration gestartet =>

hr = m_pEnum->Enum(/*hADAPTER, hMODE, hDEVICE,
hADAPTERFMT, hBACKFMT,
hWND, hFULL, m_pLog*/); // <- AUFRUF SCHLÄGT FEHL MIT FEHLERMELDUNG




Fehlermeldung:

Unhandled exception at 0x6e431f64 (Graphics_01.dll) in applikation.exe: 0xC0000005: Access violation reading location 0x00000010.

Offensichtlich wird da innerhalb der dll die Falsche Adresse angesprungen.

Hat jemand eine Idee warum?

Wäre dankbar für Hilfe.

4 Mal gendert, zuletzt am 07.02.2009, 16:36:39 Uhr von exploid.
07.02.2009, 16:17:57 Uhr
rave3d Offline
ZFX'ler


Registriert seit:
29.10.2005

Bayern
279915923 matthias.gubisch@gmx.de
Re: Funktion in Dll aufrufen klappt nichtNach oben.
Hallo kann sein dass ich das grad überlesen habe
aber wo hohlst du dir denn die Addressen der Funktionen CreateRenderDevice und ReleaseRenderDevice aus der Dll?

Ansonsten sieht der Code der Engine aus dem Kompendium von Stefan Zerbst recht ähnlich
Wenn du das hast schau dir mal die statische Lib an die dazu noch entwickelt wird vielleicht findest du da die Lösung

Ich hab leider keine Zeit jezt Code zu posten

Grüße
Matthias
07.02.2009, 16:30:41 Uhr
exploid Bin Kaffee holen
ZFX'ler


Registriert seit:
21.08.2005

Deutschland
Re: Funktion in Dll aufrufen klappt nichtNach oben.
hallo

@rave3d aber wo hohlst du dir denn die Addressen der Funktionen CreateRenderDevice und ReleaseRenderDevice aus der Dll?

Die beiden Funktionen stehen in der Library welche die Applikation verwendet um die Dll zu öffnen.

@rave3d Ansonsten sieht der Code der Engine aus dem Kompendium von Stefan Zerbst recht ähnlich

Ja das ist aus dem Buch abgeguckt.
07.02.2009, 16:44:07 Uhr
exploid Bin Kaffee holen
ZFX'ler


Registriert seit:
21.08.2005

Deutschland
Re: Funktion in Dll aufrufen klappt nichtNach oben.
Der Vollständigkeit wegen nochmal die Funktionen der Library welche die Dll lädt.

Code:
/*----------------------------------------------------------------*/
/*----------------------File: Renderdevice.h----------------------*/ 
/*----------------------------------------------------------------*/
#ifndef RENDERDEVICE_H
#define RENDERDEVICE_H

// I N C L U D E S /////////////////////////////////////////////////

#include 
#include 
#include      // direct3d 10 interface
//#include \"bktypes.h\"


/**
 * RenderDevice is an abstract class which provides an interface
 * from which render dll's can inherit. This secures availability
 * of the necessary render functions.
 */
class RenderDevice {
    protected:
    //Alle Membervariablen
        HWND            m_hWndMain;          // application main window
        HINSTANCE       m_hDLL;              // dll module handle
        FILE           *m_pLog;              // log file
    public:
    RenderDevice(void) {};
    virtual ~RenderDevice(void) {};
            
    // INIT/RELEASE STUFF:
    // ===================
    
    // initialize engine, should first display dialog to select
    // graphics adapter and mode, and then start the 3D API
    virtual HRESULT Init(HWND, bool)=0;
    
}; // class

typedef class RenderDevice *LPRenderDevice;
/*----------------------------------------------------------------*/


extern \"C\" {
 //  HRESULT CreateRenderDevice(HINSTANCE hDLL, RenderDevice **pInterface);
   typedef HRESULT (*CREATERENDERDEVICE)(HINSTANCE hDLL, RenderDevice **pInterface);
   
 //  HRESULT ReleaseRenderDevice(RenderDevice **pInterface);
   typedef HRESULT (*RELEASERENDERDEVICE)(RenderDevice **pInterface);
   }
/*----------------------------------------------------------------*/

#endif


Code:
/*----------------------------------------------------------------*/
/*----------------------File: Renderer.h--------------------------*/ 
/*----------------------------------------------------------------*/
#ifndef CRENDERER_H
#define CRENDERER_H


// I N C L U D E S /////////////////////////////////////////////////

#include \"RenderDevice.h\"

#pragma warning(disable : 4996)
// D E F I N E S ///////////////////////////////////////////////////


// S T R U C T S ///////////////////////////////////////////////////

/**
 * Just used to create, get a pointer to, and release a render device,
 * wether this is d3d or opengl or whatelse depends on dll which is 
 * selected in the CreateDevice() call.
 */
class Renderer {
   public:
      Renderer(HINSTANCE hInst);
      ~Renderer(void);
      
      HRESULT           CreateDevice(const char *chAPI);
      LPRenderDevice    GetDevice(void) { return m_pDevice; }
      HINSTANCE         GetModule(void) { return m_hDLL;    }
      void              Release(void);
      
   private:
      RenderDevice        *m_pDevice;
      HINSTANCE         m_hInst;
      HMODULE           m_hDLL;
   }; // class

typedef class Renderer *LPRenderer;
/*----------------------------------------------------------------*/

#endif


Code:
/*----------------------------------------------------------------*/
/*----------------------File: Renderer.cpp------------------------*/ 
/*----------------------------------------------------------------*/

#include \"Renderer.h\"

/**
 * Constructor: Nothing spectacular.
 */
Renderer::Renderer(HINSTANCE hInst) {
   m_hInst   = hInst;
   m_pDevice = NULL;
   m_hDLL    = NULL;
   }
/*----------------------------------------------------------------*/

/**
 * Destructor: Just call the Release method
 */
Renderer::~Renderer(void) { 
   Release(); 
   }
/*----------------------------------------------------------------*/

/**
 * Create the dll objects. This functions loads the appropriate dll.
 */
HRESULT Renderer::CreateDevice(const char *chAPI) {
   char buffer[300];
   
   // decide which API should be used
   if (strcmp(chAPI, \"Direct3D\") == 0) {
      m_hDLL = LoadLibraryEx(L\"graphics_01.dll\",NULL,0);
      if(!m_hDLL) {
         MessageBox(NULL,
            L\"Loading graphics_01.dll from lib failed.\",
            L\"Engine - error\", MB_OK | MB_ICONERROR);
         return E_FAIL;
         }
      }
   else {
      sprintf(buffer, \"API '%s' not yet supported.\", chAPI);
      MessageBox(NULL, (LPCWSTR)buffer, L\"Engine - error\", MB_OK |
                 MB_ICONERROR);
      return E_FAIL;
      }
   
   CREATERENDERDEVICE _CreateRenderDevice = 0;
   HRESULT hr;
   
   // function pointer to dll's 'CreateRenderDevice' function
   _CreateRenderDevice = (CREATERENDERDEVICE)
                          GetProcAddress(m_hDLL,
                                 \"CreateRenderDevice\");
   // call dll's create function
   hr = _CreateRenderDevice(m_hDLL, &m_pDevice);
   if(FAILED(hr)){
      MessageBox(NULL,
         L\"CreateRenderDevice() from lib failed.\",
         L\"Engine - error\", MB_OK | MB_ICONERROR);
      m_pDevice = NULL;
      return E_FAIL;
      }
   
   return S_OK;
   } // CreateDevice
/*----------------------------------------------------------------*/

/**
 * Cleanup the dll objects.
 */
void Renderer::Release(void) {
   RELEASERENDERDEVICE _ReleaseRenderDevice = 0;
   HRESULT hr;
   
   if (m_hDLL) {
      // function pointer to dll 'ReleaseRenderDevice' function
      _ReleaseRenderDevice = (RELEASERENDERDEVICE)
         GetProcAddress(m_hDLL, \"ReleaseRenderDevice\");
      }
   // call dll's release function
   if (m_pDevice) {
      hr = _ReleaseRenderDevice(&m_pDevice);
      if(FAILED(hr)){
         m_pDevice = NULL;
         }
      }
   } // Release
/*----------------------------------------------------------------*/


Das ist Renderer_01.lib und wird von der Applikation verwendet um ein Interface zur graphics_01.dll herzustellen.

07.02.2009, 17:03:42 Uhr
exploid Bin Kaffee holen
ZFX'ler


Registriert seit:
21.08.2005

Deutschland
Re: Funktion in Dll aufrufen klappt nichtNach oben.
hallo

hab jetzt mal an der stelle

...
Code:
/**
 * Callback function to handle the device/mode selection dialog
 */
BOOL CALLBACK D3D::DlgProc(HWND hDlg, UINT message, 
                           WPARAM wParam, LPARAM lParam) {
   DIBSECTION dibSection;
   BOOL       bWnd=FALSE;
   HRESULT    hr=_OK;
   
   // get handles
   HWND hFULL       = GetDlgItem(hDlg, IDC_FULL);
   HWND hWND        = GetDlgItem(hDlg, IDC_WND);
   HWND hADAPTER    = GetDlgItem(hDlg, IDC_ADAPTER);
   HWND hMODE       = GetDlgItem(hDlg, IDC_MODE);
   HWND hADAPTERFMT = GetDlgItem(hDlg, IDC_ADAPTERFMT);
   HWND hBACKFMT    = GetDlgItem(hDlg, IDC_BACKFMT);
   HWND hDEVICE     = GetDlgItem(hDlg, IDC_DEVICE);
   
   switch (message) {
      
      // preselect windowed
      case WM_INITDIALOG: {
         SendMessage(hWND, BM_SETCHECK, BST_CHECKED, 0);
         //hr = m_pEnum->Enum(/*hADAPTER, hMODE, hDEVICE, 
           //                  hADAPTERFMT, hBACKFMT,
             //                hWND, hFULL, m_pLog*/);
         wchar_t buffer[40];
         wcscpy(buffer, L\"m_pEnum :\");
         wcscat(buffer, (_itow((int)m_pEnum, buffer, 10))); // <- Fehlermeldung hier
         MessageBox(NULL, buffer, NULL, MB_OK);
         
         if (hr == _NOTCOMPATIBLE)
            EndDialog(hDlg, -2);
         else if (hr == _FAIL)
            EndDialog(hDlg, -1);

...

den Code eingebaut um mir m_pEnum in einer Messagebox auszugeben das führt zur gleichen Fehlermeldung:

Unhandled exception at 0x6de61fc7 (Graphics_01.dll) in applikation.exe: 0xC0000005: Access violation reading location 0x00000010.

Da stimmt was nicht mit dem Pointer.



1 Mal gendert, zuletzt am 07.02.2009, 17:38:31 Uhr von exploid.
07.02.2009, 17:36:12 Uhr
exploid Bin Kaffee holen
ZFX'ler


Registriert seit:
21.08.2005

Deutschland
Re:[gelöst] Funktion in Dll aufrufen klappt nichtNach oben.
hallo

hab den Fehler gefunden wenn interesse besteht sag ich wo der Fehler ist

1 Mal gendert, zuletzt am 07.02.2009, 18:20:23 Uhr von exploid.
07.02.2009, 18:11:44 Uhr
exploid Bin Kaffee holen
ZFX'ler


Registriert seit:
21.08.2005

Deutschland
Re: Funktion in Dll aufrufen klappt nichtNach oben.
Hallo

Lösung meines Problems:
Code:
/**
 * Constructor
 */
D3D::D3D(HINSTANCE hDLL) {
 
    m_hDLL              = hDLL;
    m_pEnum             = NULL;
//    m_pD3D              = NULL;
//    m_pDevice           = NULL;
    m_pLog              = NULL;
/*    m_ClearColor        = D3DCOLOR_COLORVALUE(0.0f,0.0f,0.0f,1.0f);
   m_bRunning          = false;
   m_bIsSceneRunning   = false;
   m_bUseShaders       = false;
   m_bCanDoShaders     = false;
   m_bAdditive         = false;
   m_bColorBuffer      = true;
   m_bTextures         = true;
   m_pSkinMan          = NULL;
   m_pVertexMan        = NULL;

   m_pDeclVertex       = NULL;
   m_pDeclPVertex      = NULL;
   m_pDeclLVertex      = NULL;
   m_pDeclCVertex      = NULL;
   m_pDecl3TVertex     = NULL;
   m_pDeclTVertex      = NULL;

   m_pFont             = NULL;

   // dont use swapchain at first
   m_nActivehWnd       = 0;
   m_nNumVShaders      = 0;
   m_nNumPShaders      = 0;
   m_nNumFonts         = 0;

   g_D3D = this; //<--- AAaargh
*/
   fopen_s(&m_pLog, \"Log_RenderDevice.txt\", \"w\");
   Log(\"[D3D::D3D]: online (waiting for initialization call)\n\");
   }
/*----------------------------------------------------------------*/

g_D3D = this;
Da wird die Klasse global bekannt gegeben welches der Dialog Callback Process braucht. Ohne die Bekanntgabe ist der Pointer NULL was zum Absturz führt logischerweise.
08.02.2009, 13:40:31 Uhr
Normal


ZFX Community Software, Version 0.9.1
Copyright 2002-2003 by Steffen Engel