Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
HI
I am trying to print the path of file. i am getting this error
VB
Error   1   error C2664: 'GetModuleFileNameW' : cannot convert parameter 2 from 'char [1024]' to 'LPWCH'   


Here is the simple code ....how can i print file path on to console . i am using visual studio

#include "stdio.h"
void main()
{
char buf[1024];
	GetModuleFileName(NULL,buf,1024);
	
	printf("%s",buf);
	getch();
}
Posted

Try this,

C++
void main()
{
    TCHAR buf[1024];
	GetModuleFileName(NULL,buf,1024);
	wprintf(_T("%s\n"),buf);
    cout<<buf;
}

use are using Unicode Character Set :).

LPWCH is a pointer to a wide (two byte) character string.

char [1024] is an array of single byte characters
 
Share this answer
 
v2
Thank you ...for quick reply ... ti worked
 
Share this answer
 
Comments
Hey do not submit your comments as solution. you can use "Have a Question or Comment?" widget to give your reply.;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900