I made a post yesterday and screwed it up a bit. I still got a great answer, I did some more work, but I remain having an issue. how do I get the "return_address" from mbstowcs_s into my main dir_path?
.h file:
void* get_absolute_path(char *directory, u16 *return_address, int len);
Function .c file:
void* get_absolute_path(char *directory, u16 *return_address, int len) {
u64 dest;
int errorDir = mbstowcs_s(&dest, return_address, len, directory, len);
return return_address;
}
main, function caller:
int main(void) {
char dir[] = "C:\\Windows\\";
u16 return_address[268];
u16 dir_path = get_absolute_path(dir, return_address, 268);
return true;
}
I get a clang error:
fatal error LNK1120: 1 unresolved externals
clang: error: linker command failed with exit code 1120 (use -v to see invocation)
make: *** [link] Error 1120
Error:2
BUT If I remove the "*" from the void's, I get a different error:
error: void function 'get_absolute_path' should not return a value
[-Wreturn-type]
return return_address;
But this thing is incredible unstable! If I remove the "*" from void, run it, and than re-type the * after the voids as posted, I get a different error this time:
warning: incompatible pointer to integer conversion
initializing 'u16' (aka 'unsigned short') with an expression of type 'void *'
[-Wint-conversion]
u16 dir_path = get_absolute_path(dir, return_address, 268);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Do I run it again a 2nd time, than I get the original error again: I restarted the pc, but this unstable error thing keeps happening.
u16 is unsigned short. u64 is unsigned long long.
Your help is greatly appreciated, thank you.
I'm new to C and I understand the point thing on paper, in practise I have some issues with it. So I played around with making pointers at different places and so on. I very much would like to make this work without allocating.
Adding a "*" before dir_path:
u16 dir_path = get_absolute_path(dir, return_address, 268);
to:
u16 *dir_path = get_absolute_path(dir, return_address, 268);
Gives the error:
fatal error LNK1120: 1 unresolved externals
clang: error: linker command failed with exit code 1120 (use -v to see invocation)
make: *** [link] Error 1120
u16
Changing void* tot u16, I get the error:
warning: incompatible pointer to integer conversion returning
'u16 *' (aka 'unsigned short *') from a function with result type 'u16'
(aka 'unsigned short'); dereference with * [-Wint-conversion]
return return_address;
^~~~~~~~~~~~~~
So adding the "*" at return,
return *return_address;
:
fatal error LNK1120: 1 unresolved externals
clang: error: linker command failed with exit code 1120 (use -v to see invocation)
make: *** [link] Error 1120
Error:2
u16*
Changing the void* tot u16*:
warning: incompatible pointer to integer conversion
initializing 'u16' (aka 'unsigned short') with an expression of type 'u16 *'
(aka 'unsigned short *'); dereference with * [-Wint-conversion]
u16 dir_path = get_absolute_path(dir, return_address, 268);
So as stated, now I add the "*" :
u16 dir_path = *get_absolute_path(dir, return_address, 268);
And from this I get:
fatal error LNK1120: 1 unresolved externals
clang: error: linker command failed with exit code 1120 (use -v to see invocation)
make: *** [link] Error 1120
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~