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. creating error or loading DLL error?

creating error or loading DLL error?

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++debuggingquestion
6 Posts 4 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.
  • H Offline
    H Offline
    homikaC
    wrote on last edited by
    #1

    Hello to all, I am using Visual C++ Express 2008, now I am trying to create an DLL and use it next. I think I do everything allright, compile the code. This code creates a DLL file. Next, I created code to use that DLL, after compile there is no errors. During debug, it appears this error: Unhandled exception at 0x00000000 in useDLL1.exe: 0xC0000005: Access violation reading location 0x00000000. In this moment, I don't know if the mistake is from the DLL file or from the following code( it is for loads DLL ). I need, and I appreciate some help to understand where is the problem. ---------------------------------------------------------------- #include #include using namespace std; typedef int (CALLBACK* DLLfunc)(int); #pragma once int main() { int i, result; HINSTANCE loadFcn = LoadLibrary("createDLL1.dll"); // Check to see if the library was loaded successfully if (loadFcn != 0) cout << "\n *LoadMe library loaded!\n"; else cout << "\n *LoadMe library failed to load!\n"; DLLfunc loadedFcn; loadedFcn = (DLLfunc)GetProcAddress(loadFcn,"functeste"); result=loadedFcn(30); //result = 10; cout << "hello DLL" << endl << endl; cout << loadedFcn; cout << endl << result; cin >> i; return 0; } ------------------------------------------------------------------------

    N F CPalliniC H 4 Replies Last reply
    0
    • H homikaC

      Hello to all, I am using Visual C++ Express 2008, now I am trying to create an DLL and use it next. I think I do everything allright, compile the code. This code creates a DLL file. Next, I created code to use that DLL, after compile there is no errors. During debug, it appears this error: Unhandled exception at 0x00000000 in useDLL1.exe: 0xC0000005: Access violation reading location 0x00000000. In this moment, I don't know if the mistake is from the DLL file or from the following code( it is for loads DLL ). I need, and I appreciate some help to understand where is the problem. ---------------------------------------------------------------- #include #include using namespace std; typedef int (CALLBACK* DLLfunc)(int); #pragma once int main() { int i, result; HINSTANCE loadFcn = LoadLibrary("createDLL1.dll"); // Check to see if the library was loaded successfully if (loadFcn != 0) cout << "\n *LoadMe library loaded!\n"; else cout << "\n *LoadMe library failed to load!\n"; DLLfunc loadedFcn; loadedFcn = (DLLfunc)GetProcAddress(loadFcn,"functeste"); result=loadedFcn(30); //result = 10; cout << "hello DLL" << endl << endl; cout << loadedFcn; cout << endl << result; cin >> i; return 0; } ------------------------------------------------------------------------

      N Offline
      N Offline
      Nishad S
      wrote on last edited by
      #2

      You may try step by step debug to check each line.

      - ns ami -

      1 Reply Last reply
      0
      • H homikaC

        Hello to all, I am using Visual C++ Express 2008, now I am trying to create an DLL and use it next. I think I do everything allright, compile the code. This code creates a DLL file. Next, I created code to use that DLL, after compile there is no errors. During debug, it appears this error: Unhandled exception at 0x00000000 in useDLL1.exe: 0xC0000005: Access violation reading location 0x00000000. In this moment, I don't know if the mistake is from the DLL file or from the following code( it is for loads DLL ). I need, and I appreciate some help to understand where is the problem. ---------------------------------------------------------------- #include #include using namespace std; typedef int (CALLBACK* DLLfunc)(int); #pragma once int main() { int i, result; HINSTANCE loadFcn = LoadLibrary("createDLL1.dll"); // Check to see if the library was loaded successfully if (loadFcn != 0) cout << "\n *LoadMe library loaded!\n"; else cout << "\n *LoadMe library failed to load!\n"; DLLfunc loadedFcn; loadedFcn = (DLLfunc)GetProcAddress(loadFcn,"functeste"); result=loadedFcn(30); //result = 10; cout << "hello DLL" << endl << endl; cout << loadedFcn; cout << endl << result; cin >> i; return 0; } ------------------------------------------------------------------------

        F Offline
        F Offline
        Frank K
        wrote on last edited by
        #3

        Hi, I think GetProcAddress can't resolve the function address at your DLL. Can you check your DLL if the function is exported from your DLL (e.g. with Depency Walker from VC, I'm not sure that it is included at the express version). Is your DLL-func exported like extern "C" __declspec(dllexport) int functeste(int i){....} Take also a look to this article and my comment. http://www.codeproject.com/KB/DLL/rsLoadtimeDLL.aspx?fid=29819&select=1269812&tid=1074998[^] HTH Frank

        modified on Friday, February 20, 2009 2:06 AM

        1 Reply Last reply
        0
        • H homikaC

          Hello to all, I am using Visual C++ Express 2008, now I am trying to create an DLL and use it next. I think I do everything allright, compile the code. This code creates a DLL file. Next, I created code to use that DLL, after compile there is no errors. During debug, it appears this error: Unhandled exception at 0x00000000 in useDLL1.exe: 0xC0000005: Access violation reading location 0x00000000. In this moment, I don't know if the mistake is from the DLL file or from the following code( it is for loads DLL ). I need, and I appreciate some help to understand where is the problem. ---------------------------------------------------------------- #include #include using namespace std; typedef int (CALLBACK* DLLfunc)(int); #pragma once int main() { int i, result; HINSTANCE loadFcn = LoadLibrary("createDLL1.dll"); // Check to see if the library was loaded successfully if (loadFcn != 0) cout << "\n *LoadMe library loaded!\n"; else cout << "\n *LoadMe library failed to load!\n"; DLLfunc loadedFcn; loadedFcn = (DLLfunc)GetProcAddress(loadFcn,"functeste"); result=loadedFcn(30); //result = 10; cout << "hello DLL" << endl << endl; cout << loadedFcn; cout << endl << result; cin >> i; return 0; } ------------------------------------------------------------------------

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          From GetProcAddress documentation [^]:

          Return Value If the function succeeds, the return value is the address of the exported function or variable. If the function fails, the return value is NULL. To get extended error information, call GetLastError.

          :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          In testa che avete, signor di Ceprano?

          1 Reply Last reply
          0
          • H homikaC

            Hello to all, I am using Visual C++ Express 2008, now I am trying to create an DLL and use it next. I think I do everything allright, compile the code. This code creates a DLL file. Next, I created code to use that DLL, after compile there is no errors. During debug, it appears this error: Unhandled exception at 0x00000000 in useDLL1.exe: 0xC0000005: Access violation reading location 0x00000000. In this moment, I don't know if the mistake is from the DLL file or from the following code( it is for loads DLL ). I need, and I appreciate some help to understand where is the problem. ---------------------------------------------------------------- #include #include using namespace std; typedef int (CALLBACK* DLLfunc)(int); #pragma once int main() { int i, result; HINSTANCE loadFcn = LoadLibrary("createDLL1.dll"); // Check to see if the library was loaded successfully if (loadFcn != 0) cout << "\n *LoadMe library loaded!\n"; else cout << "\n *LoadMe library failed to load!\n"; DLLfunc loadedFcn; loadedFcn = (DLLfunc)GetProcAddress(loadFcn,"functeste"); result=loadedFcn(30); //result = 10; cout << "hello DLL" << endl << endl; cout << loadedFcn; cout << endl << result; cin >> i; return 0; } ------------------------------------------------------------------------

            H Offline
            H Offline
            homikaC
            wrote on last edited by
            #5

            In first, I want to thank all help. - ns ami - : I already tryed that. Debug stops on line: "result=loadedFcn(30);" I think that is when this command tries to access to function into DLL. Frank: Your tip was very fine. I did that. "Depency Walker" didn´t get to read the DLL. The problem seems to me, that is in DLL. Now i'm trying to fix it. ...Another problem :). I made some alterations, and next I run "Depency Walker". This time get to read the DLL. But when I run debug, that code above,it occur the same error: First-chance exception at 0x00000000 in useDLL1.exe: 0xC0000005: Access violation reading location 0x00000000. Unhandled exception at 0x00000000 in useDLL1.exe: 0xC0000005: Access violation reading location 0x00000000. CPallini: I have tried your tip, and I added this line of code below DWORD err = GetLastError(); it appears err = 127 ?? ( this meants it can't find the file ?? why? ) Could you help me? Anyway, thanks for your concern.

            H 1 Reply Last reply
            0
            • H homikaC

              In first, I want to thank all help. - ns ami - : I already tryed that. Debug stops on line: "result=loadedFcn(30);" I think that is when this command tries to access to function into DLL. Frank: Your tip was very fine. I did that. "Depency Walker" didn´t get to read the DLL. The problem seems to me, that is in DLL. Now i'm trying to fix it. ...Another problem :). I made some alterations, and next I run "Depency Walker". This time get to read the DLL. But when I run debug, that code above,it occur the same error: First-chance exception at 0x00000000 in useDLL1.exe: 0xC0000005: Access violation reading location 0x00000000. Unhandled exception at 0x00000000 in useDLL1.exe: 0xC0000005: Access violation reading location 0x00000000. CPallini: I have tried your tip, and I added this line of code below DWORD err = GetLastError(); it appears err = 127 ?? ( this meants it can't find the file ?? why? ) Could you help me? Anyway, thanks for your concern.

              H Offline
              H Offline
              homikaC
              wrote on last edited by
              #6

              Thanks to all, again. I have reviewed all code and responses about this. And I added some lines of code. In the creation of DLL: ( extern "C" __declspec(dllexport) int functest(int i){....} ) And, using DLL: typedef int (*MYFUNC)(int); MYFUNC pnMyfunc = (MYFUNC)loadedFcn; cout << " value of dll func = " << pnMyfunc(36) << endl; FreeLibrary(loadFcn); Next all DLL code: #include #include using namespace std; typedef int (CALLBACK* DLLfunc)(int); typedef int (*MYFUNC)(int); // --------------------------------- new line #pragma once int main() { int i; DWORD err; HINSTANCE loadFcn = LoadLibrary("createDLL1.dll"); err = GetLastError(); // Check to see if the library was loaded successfully if (loadFcn != 0){ cout << "\n *LoadMe library loaded!\n"; DLLfunc loadedFcn; loadedFcn = (DLLfunc)GetProcAddress(loadFcn,"functest"); MYFUNC pnMyfunc = (MYFUNC)loadedFcn; // -------------- new line cout << endl << "hello DLL" << endl; cout << " value of dll func = " << pnMyfunc(36) << endl; cout << endl << " DLL func address " << *loadedFcn;} else if (err){ cout << " erro - " << err; cout << "\n *LoadMe library failed to load!\n";} FreeLibrary(loadFcn); cout << endl; cout << endl << " **Free memory** " << endl; cin >> i; return 0; }

              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