Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Mysterious C++ behaviour

Mysterious C++ behaviour

Scheduled Pinned Locked Moved C / C++ / MFC
c++databasexmlhelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RK_2000
    wrote on last edited by
    #1

    I have 4 DLLs as following: CFiles.dll CExceptions.dll CXML.Dll CDataFormat.dll CExceptions contains an Object factory that follows the Loki Object Factory model as following: It has a map containing function pointers with enteries such as following: void CExceptionFactory::InitializeMap() { AddToMethodMap(CExceptionFactory::DATABASE_EXCEPTIONS, CreateDatabaseExceptions); AddToMethodMap(CExceptionFactory::NULL_POINTER_EXCEPTIONS, CreateNullPointerExceptions); AddToMethodMap(CExceptionFactory::READER_EXCEPTIONS, CreateReadExceptions); } Now, within the DataFormat DLL, depending on the type of formatting, I load different DLLs. For instance, if the type is XML, I load the XML dll as following: case ID_XML: { //m_pDataFormat = new XML(); HMODULE hLibrary = 0; DataFormatProc pfnDataFormat = 0; GEA pfnGEA = 0; hLibrary = ::LoadLibrary("CXML.dll"); if(hLibrary != 0) { DWORD dw = 0; pfnDataFormat = (DataFormatProc) GetProcAddress (hLibrary, "CreateXMLSingletonInstance"); dw = GetLastError(); if(pfnDataFormat != 0) m_pDataFormat = pfnDataFormat(); m_pDataFormat->LoadFile(L"Stocks.xml"); ::FreeLibrary(hLibrary); } Now if the method LoadFile above fails, it throws an exception by calling CExcpetionFactory class above and CExceptionFactory will try to look inside its Loki map and retrieve the required method as shown below: CExceptionFactory::CExceptionFactory(int nTypeID, const string & strMessage) { InitializeMap(); CreateObject(nTypeID); if(m_pException != 0) { m_pException->Log(strMessage); delete m_pException; } else { throw CExceptionFactory(CExceptionFactory::NULL_POINTER_EXCEPTIONS,"Unknown Exception."); } } void CExceptionFactory::CreateObject(int nTypeID) { CallbackMap::const_iterator i = m_Callbacks.find(nTypeID); if( i != m_Callbacks.end()) { m_pException = (i->second)(); } else m_pException = 0; } Now, as soon as the code hits (i->second)(); , it leaves the exception dll all together and goes back to the beginning of that case statement above. I am quite puzzled with this behaviour. I am guessing I have a function pointer to begin with the loaded DLL and then I am getting a second function pointer and the compiler gets confused, but why should it? Your help would be highly appreciated. thanks:confused:

    M 1 Reply Last reply
    0
    • R RK_2000

      I have 4 DLLs as following: CFiles.dll CExceptions.dll CXML.Dll CDataFormat.dll CExceptions contains an Object factory that follows the Loki Object Factory model as following: It has a map containing function pointers with enteries such as following: void CExceptionFactory::InitializeMap() { AddToMethodMap(CExceptionFactory::DATABASE_EXCEPTIONS, CreateDatabaseExceptions); AddToMethodMap(CExceptionFactory::NULL_POINTER_EXCEPTIONS, CreateNullPointerExceptions); AddToMethodMap(CExceptionFactory::READER_EXCEPTIONS, CreateReadExceptions); } Now, within the DataFormat DLL, depending on the type of formatting, I load different DLLs. For instance, if the type is XML, I load the XML dll as following: case ID_XML: { //m_pDataFormat = new XML(); HMODULE hLibrary = 0; DataFormatProc pfnDataFormat = 0; GEA pfnGEA = 0; hLibrary = ::LoadLibrary("CXML.dll"); if(hLibrary != 0) { DWORD dw = 0; pfnDataFormat = (DataFormatProc) GetProcAddress (hLibrary, "CreateXMLSingletonInstance"); dw = GetLastError(); if(pfnDataFormat != 0) m_pDataFormat = pfnDataFormat(); m_pDataFormat->LoadFile(L"Stocks.xml"); ::FreeLibrary(hLibrary); } Now if the method LoadFile above fails, it throws an exception by calling CExcpetionFactory class above and CExceptionFactory will try to look inside its Loki map and retrieve the required method as shown below: CExceptionFactory::CExceptionFactory(int nTypeID, const string & strMessage) { InitializeMap(); CreateObject(nTypeID); if(m_pException != 0) { m_pException->Log(strMessage); delete m_pException; } else { throw CExceptionFactory(CExceptionFactory::NULL_POINTER_EXCEPTIONS,"Unknown Exception."); } } void CExceptionFactory::CreateObject(int nTypeID) { CallbackMap::const_iterator i = m_Callbacks.find(nTypeID); if( i != m_Callbacks.end()) { m_pException = (i->second)(); } else m_pException = 0; } Now, as soon as the code hits (i->second)(); , it leaves the exception dll all together and goes back to the beginning of that case statement above. I am quite puzzled with this behaviour. I am guessing I have a function pointer to begin with the loaded DLL and then I am getting a second function pointer and the compiler gets confused, but why should it? Your help would be highly appreciated. thanks:confused:

      M Offline
      M Offline
      Magnus Westin
      wrote on last edited by
      #2

      Well it sounds like you have corrupted your stack. Then you can end up any where in your code when calling function. Magnus

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups