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. Dll function calls are not called right

Dll function calls are not called right

Scheduled Pinned Locked Moved C / C++ / MFC
help
4 Posts 3 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.
  • D Offline
    D Offline
    dj4400
    wrote on last edited by
    #1

    Hi, I have created a dll which exports a factory function that returns an object of the type of the dll class: class CMyDll { Z(); X(); Y(); } extern "c" { __declspec(dllexport) CMyDll* Factory(); } The program that utilize the dll loads the dll calls the factory function and get the dll object. from that object i call the dll functions. MyApp() { hmodule = AfxLoadLibrary(MyDll.dll); typedef CMyDll* (*FACTORY )(void); FACTORY pFunc; pFunc = (FACTORY)GetProcAddress(hmodule,"Factory"); CMyDll *dllObj = pFunc(); dllObj->X(); dllObj->Y(); dllObj->Z(); } But there is a problem , the functions are not called right, if i call functions X,Y and Z, it calls functions Z,Y and X in a certain order which i couldn't specify. If someone spotted the source of the error please let me know Thanks :confused: Simon

    T D 2 Replies Last reply
    0
    • D dj4400

      Hi, I have created a dll which exports a factory function that returns an object of the type of the dll class: class CMyDll { Z(); X(); Y(); } extern "c" { __declspec(dllexport) CMyDll* Factory(); } The program that utilize the dll loads the dll calls the factory function and get the dll object. from that object i call the dll functions. MyApp() { hmodule = AfxLoadLibrary(MyDll.dll); typedef CMyDll* (*FACTORY )(void); FACTORY pFunc; pFunc = (FACTORY)GetProcAddress(hmodule,"Factory"); CMyDll *dllObj = pFunc(); dllObj->X(); dllObj->Y(); dllObj->Z(); } But there is a problem , the functions are not called right, if i call functions X,Y and Z, it calls functions Z,Y and X in a certain order which i couldn't specify. If someone spotted the source of the error please let me know Thanks :confused: Simon

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      what about this :

      pFunc = (FACTORY)GetProcAddress(hmodule,"**_Factory**");

      BTW, your code is not very secure, as you don't test hmodule before using it...

      [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

      1 Reply Last reply
      0
      • D dj4400

        Hi, I have created a dll which exports a factory function that returns an object of the type of the dll class: class CMyDll { Z(); X(); Y(); } extern "c" { __declspec(dllexport) CMyDll* Factory(); } The program that utilize the dll loads the dll calls the factory function and get the dll object. from that object i call the dll functions. MyApp() { hmodule = AfxLoadLibrary(MyDll.dll); typedef CMyDll* (*FACTORY )(void); FACTORY pFunc; pFunc = (FACTORY)GetProcAddress(hmodule,"Factory"); CMyDll *dllObj = pFunc(); dllObj->X(); dllObj->Y(); dllObj->Z(); } But there is a problem , the functions are not called right, if i call functions X,Y and Z, it calls functions Z,Y and X in a certain order which i couldn't specify. If someone spotted the source of the error please let me know Thanks :confused: Simon

        D Offline
        D Offline
        Dan 0
        wrote on last edited by
        #3

        Where is the rest of the Factory() function, could be an allocation error.

        D 1 Reply Last reply
        0
        • D Dan 0

          Where is the rest of the Factory() function, could be an allocation error.

          D Offline
          D Offline
          dj4400
          wrote on last edited by
          #4

          Hi all, thanks for your answers. The problem was that i declared a function in the interface as an int, but the implementing class declared the same function with an enum. So when calling the function from the dll (which was the implementing class) the function was not found and another function was called. ______________ |Interface | |-x(int var);| -------------- | \/ ______________ |dll class | |-x(enum var)| -------------- ;)

          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