-
I have a follow-up question concerning my use of 'char' as the return type for my fcn1Wrapper() call:
my main code is similar to this, assuming that the function declaration was performed in the global workspace as discussed in previous posts above:
Code:
main(){
char fcn1_out;
dll = LoadLibrary("myLibrary.dll");
if (dll != NULL)
fcn1Wrapper = (fcn1WrapperPointer)GetProcAddress(dll, "fcn1Wrapper");
else
fcn1Wrapper = NULL;
fcn1_out = fcn1Wrapper(6, 6, "Setup_File.txt");
printf("fcn1_out = %c.\n", fcn1_out);
}
If I were working with a bool output type, I would expect my fcn1Wrapper() call to return 1 for success and 0 for failure. Here, when I print out the char return value it is '.' (i.e. a period). I've looked through documentation for converting characters to bools, but I haven't found anything that seems useful. i.e. I'm not even sure whether there *is* a correspondence between the '.' character that my function call is returning, and a 0/1-type boolean value that I can use to determine success/failure of my function call. Does this returned '.' value have any actual *meaning*? If e.g. I remove from my working directory the input file that my fcn1Wrapper() takes as an argument, I still get '.' as my return value...
Is my code above correct, and if so, is there any way for me to determine the success of my function call using the char return type? Thanks.
-
If you print out a char variable using the format specifier "%c" the value of the char is interpreted as a character according to your current character set (probably ASCII). Thus you print out the characters ASCII 0 or ASCII 1. You see the period because you literally print the period in your printf() (the period after "%c" in your format string).
You are only interested in the numerical value of your char variable. Hence you have to print it out with the format specifier "%d":
Code:
printf("fcn1_out = %d\n", fcn1_out);
Another problem is that you assign NULL to fcn1Wrapper when the loading of the dll fails. But later you call fcn1Wrapper regardless where fcn1Wrapper points to. In case it points to NULL your program will crash.
You should only use fcn1Wrapper when it doesn't point to NULL:
Code:
if (fcn1Wrapper)
fcn1_out = fcn1Wrapper(6, 6, "Setup_File.txt");
Bye, Andreas
-
That was very helpful, Andreas -- thanks!!