please help
-
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.
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
-
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
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.
-
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.
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.
-
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.
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 ofProcAdd
look like?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - 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 ofProcAdd
look like?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
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.
-
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.
What is the signature of the
first()
,last()
, andfirstlast()
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
-
What is the signature of the
first()
,last()
, andfirstlast()
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
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.
-
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.
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 oncefirstn()
loses scope. Therefore, thereturn
statement, in its current form, is useless. Since no return type was specified,int
is assumed. This conflicts withfirst
being cast to achar
. The same holds true for thelastn()
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; } Thefirst
andlast
variables are of typechar
, but you are treating them as null-terminated strings in the call toprintf()
. 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
-
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 oncefirstn()
loses scope. Therefore, thereturn
statement, in its current form, is useless. Since no return type was specified,int
is assumed. This conflicts withfirst
being cast to achar
. The same holds true for thelastn()
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; } Thefirst
andlast
variables are of typechar
, but you are treating them as null-terminated strings in the call toprintf()
. 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
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.
-
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.
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