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. please help

please help

Scheduled Pinned Locked Moved C / C++ / MFC
helpcss
11 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.
  • S swatgodjr

    can someone please help me with a problem i have with dll files. i can call functions from the dll files i make but i was wondering how i could use the returned variable from 1 function in another function inside my dll file. if anyone can help me i would appreciate it a lot. the more you learn the less you know, no one is truely a master. cause the more you seek to be the master the less of a master you become.

    D Offline
    D Offline
    David Crow
    wrote on last edited by
    #2

    Swatgod wrote: i can call functions from the dll files... Are they called from some other DLL or EXE, or are they called from within the DLL itself? Swatgod wrote: ...i was wondering how i could use the returned variable from 1 function in another function inside my dll file. Does the function return a value? If so, treat it just like any other function that returns a value. The fact that it resides in a DLL is irrelevant. In Prog.exe:

    int x = SomeFunc(); // SomeFunc() resides in a separate DLL

    In DLL:

    int SomeFunc( void )
    {
    return 123;
    }


    "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

    S 1 Reply Last reply
    0
    • D David Crow

      Swatgod wrote: i can call functions from the dll files... Are they called from some other DLL or EXE, or are they called from within the DLL itself? Swatgod wrote: ...i was wondering how i could use the returned variable from 1 function in another function inside my dll file. Does the function return a value? If so, treat it just like any other function that returns a value. The fact that it resides in a DLL is irrelevant. In Prog.exe:

      int x = SomeFunc(); // SomeFunc() resides in a separate DLL

      In DLL:

      int SomeFunc( void )
      {
      return 123;
      }


      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

      S Offline
      S Offline
      Swatgod
      wrote on last edited by
      #3

      well the functions are called from a dll i made and the way that i have seen done, wont let me do it like that, her ei show a small sample of how my functions are called in the exe from my dll file. ProcAdd=(MYPROC)GetProcAddress(hinstLib,"firstlast"); if(fRunTimeLinkSuccess = (ProcAdd != NULL)) (ProcAdd)("firstlast"); the more you learn the less you know, no one is truely a master. cause the more you seek to be the master the less of a master you become.

      D 1 Reply Last reply
      0
      • S swatgodjr

        can someone please help me with a problem i have with dll files. i can call functions from the dll files i make but i was wondering how i could use the returned variable from 1 function in another function inside my dll file. if anyone can help me i would appreciate it a lot. the more you learn the less you know, no one is truely a master. cause the more you seek to be the master the less of a master you become.

        S Offline
        S Offline
        swatgodjr
        wrote on last edited by
        #4

        if someone who is very good with dll files could help me i would appreciate it alot. i do not think it was clear what i was asking before so i guess i should restate it. i will use an example(very small and simple example) to explain what i need help with. say i wanted the program to gather a person's first and last name using 2 functions that return the variables that the first and last name are stored in and than another function uses those variables to output the person's first and last name to the screen. plz if someone could help me figure this out i would appreciate it alot(sorry for the example, only easy thing i could come up with). the more you learn the less you know, no one is truely a master. cause the more you seek to be the master the less of a master you become.

        1 Reply Last reply
        0
        • S Swatgod

          well the functions are called from a dll i made and the way that i have seen done, wont let me do it like that, her ei show a small sample of how my functions are called in the exe from my dll file. ProcAdd=(MYPROC)GetProcAddress(hinstLib,"firstlast"); if(fRunTimeLinkSuccess = (ProcAdd != NULL)) (ProcAdd)("firstlast"); the more you learn the less you know, no one is truely a master. cause the more you seek to be the master the less of a master you become.

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #5

          Are you getting compiler or runtime errors? Are any assertions firing, or exceptions thrown? Does hinstLib have a non-NULL value? Do you know the name of the exported function to be "firstlast?" What does the declaration of ProcAdd look like?


          "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

          S 1 Reply Last reply
          0
          • D David Crow

            Are you getting compiler or runtime errors? Are any assertions firing, or exceptions thrown? Does hinstLib have a non-NULL value? Do you know the name of the exported function to be "firstlast?" What does the declaration of ProcAdd look like?


            "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

            S Offline
            S Offline
            Swatgod
            wrote on last edited by
            #6

            here is the code of the main application. the first 2 functiosn that i have seen went through fine but when it loads the 3rd which is the one that needs input from other 2, it crashes. #include #include typedef void (*MYPROC)(LPTSTR); void main() { HINSTANCE hinstLib; MYPROC ProcAdd; BOOL fFreeResult, fRunTimeLinkSuccess = FALSE; hinstLib = LoadLibrary("name"); if(hinstLib != NULL) { ProcAdd = (MYPROC) GetProcAddress(hinstLib, "firstn"); if(fRunTimeLinkSuccess = (ProcAdd != NULL)) (ProcAdd)("firstn"); ProcAdd = (MYPROC) GetProcAddress(hinstLib, "lastn"); if(fRunTimeLinkSuccess = (ProcAdd != NULL)) (ProcAdd)("lastn"); ProcAdd = (MYPROC) GetProcAddress(hinstLib, "firstlast"); if(fRunTimeLinkSuccess = (ProcAdd != NULL)) (ProcAdd)("firstlast"); fFreeResult = FreeLibrary(hinstLib); } if(! fRunTimeLinkSuccess) printf("--loading of main dll failed--"); } the more you learn the less you know, no one is truely a master. cause the more you seek to be the master the less of a master you become.

            D 1 Reply Last reply
            0
            • S Swatgod

              here is the code of the main application. the first 2 functiosn that i have seen went through fine but when it loads the 3rd which is the one that needs input from other 2, it crashes. #include #include typedef void (*MYPROC)(LPTSTR); void main() { HINSTANCE hinstLib; MYPROC ProcAdd; BOOL fFreeResult, fRunTimeLinkSuccess = FALSE; hinstLib = LoadLibrary("name"); if(hinstLib != NULL) { ProcAdd = (MYPROC) GetProcAddress(hinstLib, "firstn"); if(fRunTimeLinkSuccess = (ProcAdd != NULL)) (ProcAdd)("firstn"); ProcAdd = (MYPROC) GetProcAddress(hinstLib, "lastn"); if(fRunTimeLinkSuccess = (ProcAdd != NULL)) (ProcAdd)("lastn"); ProcAdd = (MYPROC) GetProcAddress(hinstLib, "firstlast"); if(fRunTimeLinkSuccess = (ProcAdd != NULL)) (ProcAdd)("firstlast"); fFreeResult = FreeLibrary(hinstLib); } if(! fRunTimeLinkSuccess) printf("--loading of main dll failed--"); } the more you learn the less you know, no one is truely a master. cause the more you seek to be the master the less of a master you become.

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #7

              What is the signature of the first(), last(), and firstlast() functions within the DLL?


              "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

              S 1 Reply Last reply
              0
              • D David Crow

                What is the signature of the first(), last(), and firstlast() functions within the DLL?


                "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                S Offline
                S Offline
                Swatgod
                wrote on last edited by
                #8

                the main source of the dll file is: #include "stdafx.h" #include BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { return TRUE; } extern "C" __declspec(dllexport) firstn(); extern "C" __declspec(dllexport) lastn(); extern "C" __declspec(dllexport) firstlast(char first, char last); extern "C" __declspec(dllexport) firstn() { char first[10]; printf(" What is your first name: "); scanf(" %s", first); return (char)first; } extern "C" __declspec(dllexport) lastn() { char last[10]; printf(" What is your last name: "); scanf(" %s", last); return (char)last; } extern "C" __declspec(dllexport) firstlast(char first, char last) { printf(" your first and last name is %s %s.", first, last); return 0; } once again thank you for your help. the more you learn the less you know, no one is truely a master. cause the more you seek to be the master the less of a master you become.

                D 1 Reply Last reply
                0
                • S Swatgod

                  the main source of the dll file is: #include "stdafx.h" #include BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { return TRUE; } extern "C" __declspec(dllexport) firstn(); extern "C" __declspec(dllexport) lastn(); extern "C" __declspec(dllexport) firstlast(char first, char last); extern "C" __declspec(dllexport) firstn() { char first[10]; printf(" What is your first name: "); scanf(" %s", first); return (char)first; } extern "C" __declspec(dllexport) lastn() { char last[10]; printf(" What is your last name: "); scanf(" %s", last); return (char)last; } extern "C" __declspec(dllexport) firstlast(char first, char last) { printf(" your first and last name is %s %s.", first, last); return 0; } once again thank you for your help. the more you learn the less you know, no one is truely a master. cause the more you seek to be the master the less of a master you become.

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #9

                  Swatgod wrote: extern "C" __declspec(dllexport) firstn() { char first[10]; printf(" What is your first name: "); scanf(" %s", first); return (char)first; } The first variable goes away once firstn() loses scope. Therefore, the return statement, in its current form, is useless. Since no return type was specified, int is assumed. This conflicts with first being cast to a char. The same holds true for the lastn() function. Swatgod wrote: extern "C" __declspec(dllexport) firstlast(char first, char last) { printf(" your first and last name is %s %s.", first, last); return 0; } The first and last variables are of type char, but you are treating them as null-terminated strings in the call to printf(). This is a sure-fire recipe for stack corruption. Also, the prototypes near the top are not necessary.


                  "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                  S 1 Reply Last reply
                  0
                  • D David Crow

                    Swatgod wrote: extern "C" __declspec(dllexport) firstn() { char first[10]; printf(" What is your first name: "); scanf(" %s", first); return (char)first; } The first variable goes away once firstn() loses scope. Therefore, the return statement, in its current form, is useless. Since no return type was specified, int is assumed. This conflicts with first being cast to a char. The same holds true for the lastn() function. Swatgod wrote: extern "C" __declspec(dllexport) firstlast(char first, char last) { printf(" your first and last name is %s %s.", first, last); return 0; } The first and last variables are of type char, but you are treating them as null-terminated strings in the call to printf(). This is a sure-fire recipe for stack corruption. Also, the prototypes near the top are not necessary.


                    "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                    S Offline
                    S Offline
                    Swatgod
                    wrote on last edited by
                    #10

                    in the firstlast function i made it so it used a char array for both and made the other functions with return type char as before it was causing trouble with it going directly to int. but the program is still crashing between the end of the 2nd function and start of the 3rd but now it actually prints soemthign from the 3rd function. the more you learn the less you know, no one is truely a master. cause the more you seek to be the master the less of a master you become.

                    D 1 Reply Last reply
                    0
                    • S Swatgod

                      in the firstlast function i made it so it used a char array for both and made the other functions with return type char as before it was causing trouble with it going directly to int. but the program is still crashing between the end of the 2nd function and start of the 3rd but now it actually prints soemthign from the 3rd function. the more you learn the less you know, no one is truely a master. cause the more you seek to be the master the less of a master you become.

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #11

                      Whatever result you are seeing that happens to look correct is pure coincidence. The correct way to do this is:

                      extern "C" __declspec(dllexport) void firstn( LPSTR lpFirst )
                      {
                      printf("What is your first name: ");
                      scanf("%s", lpFirst); // could potentially overflow (exercise for reader)
                      }

                      extern "C" __declspec(dllexport) void firstlast( LPCSTR lpFirst, LPCSTR lpLast)
                      {
                      printf("Your first and last name is %s %s.", lpFirst, lpLast);
                      }


                      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                      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