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. calling a DLL in Visual C++

calling a DLL in Visual C++

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorialquestion
6 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.
  • G Offline
    G Offline
    Geert Craessaerts
    wrote on last edited by
    #1

    Hello, I've written a program in VisualC++ to call a DLL file. I came to the DLL file by compiling a Matlab file with the function mcc. When I write a simple DLL file (output=input) my C++ program works very well and gets a good link with the DLL. But when I change the DLL file a little bit(output = 3* input), my program gets no good link with the DLL file. It seems that the main function can't call the other subfunctions of my dll file(the functions that are extra created when I changed my DLL file to "output=3*input" and are needed to perform the multiplication) Please, can you explain me what's wrong, what I have to change?? Is their something wrong with the settings of my program? Could you give me a good example of such a program? Is there maybe something wrong with the mcc compiler code? The code I used was "mcc -W lib:libFLOPS -t -h -T link:lib libmmfile.mlib FLOPS". This is a part of my C++ program: void CDLLTESTDlg::OnStartdllbutton() { typedef mxArray*(* LPFNDLLFUNC1)(mxArray* input); HINSTANCE hDLL; // Handle to DLL LPFNDLLFUNC1 lpfnDllFunc1; // Function pointer hDLL = LoadLibrary("libFLOPS.dll"); if (hDLL != NULL) { lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL,"mlfFLOPS"); if (!lpfnDllFunc1) { // handle the error FreeLibrary(hDLL); SetDlgItemText(IDC_RESULTDLLCALL,"ddl found, but no function"); } else { // call the function char szTemp[100]; mxArray *INPUT=NULL, *OUTPUT=NULL; INPUT=mxCreateScalarDouble(100); OUTPUT=(*lpfnDllFunc1)(INPUT); sprintf(szTemp,"%f",mxGetScalar(OUTPUT)); SetDlgItemText(IDC_RESULT,szTemp); SetDlgItemText(IDC_RESULTDLLCALL,"ddl en functie gevonden"); FreeLibrary(hDLL); } } } Thanx for your support , kind regards, Geert

    D 1 Reply Last reply
    0
    • G Geert Craessaerts

      Hello, I've written a program in VisualC++ to call a DLL file. I came to the DLL file by compiling a Matlab file with the function mcc. When I write a simple DLL file (output=input) my C++ program works very well and gets a good link with the DLL. But when I change the DLL file a little bit(output = 3* input), my program gets no good link with the DLL file. It seems that the main function can't call the other subfunctions of my dll file(the functions that are extra created when I changed my DLL file to "output=3*input" and are needed to perform the multiplication) Please, can you explain me what's wrong, what I have to change?? Is their something wrong with the settings of my program? Could you give me a good example of such a program? Is there maybe something wrong with the mcc compiler code? The code I used was "mcc -W lib:libFLOPS -t -h -T link:lib libmmfile.mlib FLOPS". This is a part of my C++ program: void CDLLTESTDlg::OnStartdllbutton() { typedef mxArray*(* LPFNDLLFUNC1)(mxArray* input); HINSTANCE hDLL; // Handle to DLL LPFNDLLFUNC1 lpfnDllFunc1; // Function pointer hDLL = LoadLibrary("libFLOPS.dll"); if (hDLL != NULL) { lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL,"mlfFLOPS"); if (!lpfnDllFunc1) { // handle the error FreeLibrary(hDLL); SetDlgItemText(IDC_RESULTDLLCALL,"ddl found, but no function"); } else { // call the function char szTemp[100]; mxArray *INPUT=NULL, *OUTPUT=NULL; INPUT=mxCreateScalarDouble(100); OUTPUT=(*lpfnDllFunc1)(INPUT); sprintf(szTemp,"%f",mxGetScalar(OUTPUT)); SetDlgItemText(IDC_RESULT,szTemp); SetDlgItemText(IDC_RESULTDLLCALL,"ddl en functie gevonden"); FreeLibrary(hDLL); } } } Thanx for your support , kind regards, Geert

      D Offline
      D Offline
      De Nardis Andrea
      wrote on last edited by
      #2

      Hi, the simplest reason could be a PATH problem. Probably Mathlab engine must be addressed to the OS: your DLL has the Mathlab Engine implicilty linked and so OS do load your DLL only if all the dependencies are loadad. Try to add the Mathlab engine path in the PATH env variable: use Dependency Walker to find the dependencies of your DLL and than search the file in HD.:)

      G 1 Reply Last reply
      0
      • D De Nardis Andrea

        Hi, the simplest reason could be a PATH problem. Probably Mathlab engine must be addressed to the OS: your DLL has the Mathlab Engine implicilty linked and so OS do load your DLL only if all the dependencies are loadad. Try to add the Mathlab engine path in the PATH env variable: use Dependency Walker to find the dependencies of your DLL and than search the file in HD.:)

        G Offline
        G Offline
        Geert Craessaerts
        wrote on last edited by
        #3

        Could you explain me what you mean with "try to add the Mathlab engine path in the PATH env variable: use Dependency Walker to find the dependencies of your DLL and than search the file in HD" Thanx, kind regards, Geert

        D 1 Reply Last reply
        0
        • G Geert Craessaerts

          Could you explain me what you mean with "try to add the Mathlab engine path in the PATH env variable: use Dependency Walker to find the dependencies of your DLL and than search the file in HD" Thanx, kind regards, Geert

          D Offline
          D Offline
          De Nardis Andrea
          wrote on last edited by
          #4

          In order to use Mathlab functionality you need some DLL for sure. You probably have linked your app with the enty point lib of these. There is a free utility called Dependency Walker that can help in identify the DLL your component need. All these DLLs must be present in one or more of the following path list: - your app path; - the %systemroot% path; - the %winnt%\system32 path; - one of the path specified by the PATH environment variable; If something gets wrong in loading any of these DLLs your primary DLL cannot be loaded and you experience the problem you have reported. More info in "Advanced Programming for Windows" by Richter

          G 1 Reply Last reply
          0
          • D De Nardis Andrea

            In order to use Mathlab functionality you need some DLL for sure. You probably have linked your app with the enty point lib of these. There is a free utility called Dependency Walker that can help in identify the DLL your component need. All these DLLs must be present in one or more of the following path list: - your app path; - the %systemroot% path; - the %winnt%\system32 path; - one of the path specified by the PATH environment variable; If something gets wrong in loading any of these DLLs your primary DLL cannot be loaded and you experience the problem you have reported. More info in "Advanced Programming for Windows" by Richter

            G Offline
            G Offline
            Geert Craessaerts
            wrote on last edited by
            #5

            What do you just mean with? - the %systemroot% path; - one of the path specified by the PATH environment variable; I'm not such an experienced programmaer:-) Kind regards, ciao, Geert

            D 1 Reply Last reply
            0
            • G Geert Craessaerts

              What do you just mean with? - the %systemroot% path; - one of the path specified by the PATH environment variable; I'm not such an experienced programmaer:-) Kind regards, ciao, Geert

              D Offline
              D Offline
              De Nardis Andrea
              wrote on last edited by
              #6

              %systemroot% : the directory of windows (if you are using XP it's probably c:\windows, if you are using NT/2000 it's probably c:\winnt). Check in the Windows online help "Environment Variables", type SET PATH on command prompt and get the content of the PATH env var. You'll see ";"-separated list of paths, append the path of the Mathlab DLL folder you found w/ the method I have explained earlier. Probably you 'll need a help by someone more expert in the dept you are working...

              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