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. Help Accessing Functions in a Dll

Help Accessing Functions in a Dll

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++phpcomperformance
4 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.
  • N Offline
    N Offline
    Naturality
    wrote on last edited by
    #1

    Hi, I recently started my first project based around DLLs and have run into a little trouble. I followed this tutorial: http://www.codeguru.com/cpp/cpp/cpp\_mfc/tutorials/article.php/c9855 The code is split up into a header file and a source file. It consists of a namespace, which contains variables and a class. I am linking implicitly. In a test program I can access the variables fine, no problems there, but when I use a function from the class, I get linker errors, eg:

    1>ELQTest.obj : error LNK2019: unresolved external symbol "public: static bool __cdecl ELQ::Functions::CreateRot(void)" (?CreateRot@Functions@ELQ@@SA_NXZ) referenced in function _SDL_main

    = sin((x-360)*0.017); } } } #include "stdafx.h" #include "ELQDLL.h" #include SDL_Surface *screen; int main(int argc, char *argv[]){ if(ELQ::Functions::CreateRot()) system("PAUSE"); return 0; } Any idea what could be wrong? I've played around with all sorts of combinations of class definitions, export/import symbols etc, yet cannot get this to work. Look forward to your input, Thanks, Nat. PS: Oh, I should say that when I compile the DLL, I get a stream of inconsistency messages, could this be related? "Sir, I protest. I am NOT a merry man!"

    S 1 Reply Last reply
    0
    • N Naturality

      Hi, I recently started my first project based around DLLs and have run into a little trouble. I followed this tutorial: http://www.codeguru.com/cpp/cpp/cpp\_mfc/tutorials/article.php/c9855 The code is split up into a header file and a source file. It consists of a namespace, which contains variables and a class. I am linking implicitly. In a test program I can access the variables fine, no problems there, but when I use a function from the class, I get linker errors, eg:

      1>ELQTest.obj : error LNK2019: unresolved external symbol "public: static bool __cdecl ELQ::Functions::CreateRot(void)" (?CreateRot@Functions@ELQ@@SA_NXZ) referenced in function _SDL_main

      = sin((x-360)*0.017); } } } #include "stdafx.h" #include "ELQDLL.h" #include SDL_Surface *screen; int main(int argc, char *argv[]){ if(ELQ::Functions::CreateRot()) system("PAUSE"); return 0; } Any idea what could be wrong? I've played around with all sorts of combinations of class definitions, export/import symbols etc, yet cannot get this to work. Look forward to your input, Thanks, Nat. PS: Oh, I should say that when I compile the DLL, I get a stream of inconsistency messages, could this be related? "Sir, I protest. I am NOT a merry man!"

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      Those extern "C" statements look wrong - especially as a) you're using namespaces and b) you're enclosing class definitions in them. Now, namespaces and classes are C++ features - they really aren't compatible with extern "C", which specifies that the names enclosed by the extern "C" are exported as undecorated, C names rather than decorated C++ names. BTW - a decorated C++ name is something like ?CreateRot@Functions@ELQ@@SA_NXZ, your missing symbol... So - try removing all extern "C" things. The only reason for extern "C" is to export functions compiled with a C++ compiler in a form compatible with C. You're exporting namespaced functions and classes - they will never be compatible with C...

      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

      N 1 Reply Last reply
      0
      • S Stuart Dootson

        Those extern "C" statements look wrong - especially as a) you're using namespaces and b) you're enclosing class definitions in them. Now, namespaces and classes are C++ features - they really aren't compatible with extern "C", which specifies that the names enclosed by the extern "C" are exported as undecorated, C names rather than decorated C++ names. BTW - a decorated C++ name is something like ?CreateRot@Functions@ELQ@@SA_NXZ, your missing symbol... So - try removing all extern "C" things. The only reason for extern "C" is to export functions compiled with a C++ compiler in a form compatible with C. You're exporting namespaced functions and classes - they will never be compatible with C...

        Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

        N Offline
        N Offline
        Naturality
        wrote on last edited by
        #3

        Thank you very much! I feel like a total fool now, though. Classes in C?! They should revoke my C++ licence for that. :laugh:

        "Sir, I protest. I am NOT a merry man!"

        S 1 Reply Last reply
        0
        • N Naturality

          Thank you very much! I feel like a total fool now, though. Classes in C?! They should revoke my C++ licence for that. :laugh:

          "Sir, I protest. I am NOT a merry man!"

          S Offline
          S Offline
          Stuart Dootson
          wrote on last edited by
          #4

          Don't sweat it man - we've all done it one time or another!

          Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

          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