Here is Minimal example :-
#include <stdio.h>
#include <Windows.h>
using namespace std;
void myFunc(TCHAR Path)
{
printf("pathLen : %lu\n", sizeof(Path));
printf("character size : %lu\n", sizeof(*Path));
printf("pathLenInBytes : %lu\n", sizeof(Path) * sizeof(*Path));
}
int main()
{
TCHAR selfPath[MAX_PATH];
if (GetModuleFileName(NULL, selfPath, MAX_PATH) == 0) // Getting exe File Location
printf("Error : %lu\n", GetLastError());
printf("Self Path : %s\n", selfPath);
myFunc(selfPath);
return 0;
}
Here is Error Output from MinGW-W64 Compiler :-
g++ -Os -s -o goga.exe tesst.cpp
tesst.cpp: In function 'void myFunc(LPCSTR, TCHAR)':
tesst.cpp:9:43: error: invalid type argument of unary '*' (have 'TCHAR' {aka 'char'})
9 | printf("character size : %lu\n", sizeof(*Path));
| ^~~~
tesst.cpp:10:35: error: 'pathLen' was not declared in this scope
10 | printf("pathLenInBytes : %lu\n", pathLen * sizeof(*Path));
| ^~~~~~~
tesst.cpp:10:53: error: invalid type argument of unary '*' (have 'TCHAR' {aka 'char'})
10 | printf("pathLenInBytes : %lu\n", pathLen * sizeof(*Path));
| ^~~~
tesst.cpp: In function 'int main()':
tesst.cpp:23:22: error: invalid conversion from 'TCHAR*' {aka 'char*'} to 'TCHAR' {aka 'char'} [-fpermissive]
23 | myFunc("AppBroker", selfPath);
| ^~~~~~~~
| |
| TCHAR* {aka char*}
tesst.cpp:6:32: note: initializing argument 2 of 'void myFunc(LPCSTR, TCHAR)'
6 | void myFunc(LPCSTR Name, TCHAR Path)
| ~~~~~~^~~~
But If I put the GetModuleFineName() directy inside myFunc() then it works :-
#include <stdio.h>
#include <Windows.h>
using namespace std;
void myFunc()
{
TCHAR selfPath[MAX_PATH];
if (GetModuleFileName(NULL, selfPath, MAX_PATH) == 0) // Getting exe File Location
printf("Error : %lu\n", GetLastError());
printf("Self Path : %s\n", selfPath);
printf("pathLen : %lu\n", sizeof(selfPath));
printf("character size : %lu\n", sizeof(*selfPath));
printf("pathLenInBytes : %lu\n", sizeof(selfPath) * sizeof(*selfPath));
}
int main()
{
myFunc();
return 0;
}
But I dont need it this way. How can i solve this error ?
EDIT : Tried replacing myFunc(TCHAR Path)
with myFunc(TCHAR *Path)
& also with myFunc(TCHAR Path[])
. Both Work and program compiles successfully but the output is different that expected output now !
Expected Output :-
Self Path : C:\Users\username\Desktop\Coding\PETS\muse\goga.exe
pathLen : 260
character size : 1
pathLenInBytes : 260
Output that I Get:-
Self Path : C:\Users\username\Desktop\Coding\PETS\muse\goga.exe
pathLen : 8
character size : 1
pathLenInBytes : 8