|
Hi,
I have variable FName & Str,
CString FName;
char str[100];
i want the FName to be stored in str i tryed using
str = FName;
i am getting error
error C2440: '=' : cannot convert from 'class CString' to 'char [100]'
Can anyone help me with this convershion or any related notes or links will be helpfull.
Regards,
Vinay Charan.
|
|
|
|
|
Some alternatives:
strcpy(str, (LPCTSTR) FName);
strcpy(str, FName.GetBuffer(0));
OR:
char * pStr = (LPCTSTR) FName;
-- modified at 1:52 Tuesday 23rd May, 2006
|
|
|
|
|
Vinay wrote:
Hi,I have variable FName & Str,
CString FName;
char str[100];
i want the FName to be stored in str i tryed using
str = FName;
i am getting error
error C2440: '=' : cannot convert from 'class CString' to 'char [100]'
Can anyone help me with this convershion or any related notes or links will be helpfull.
See the following code
strcpy(str,FName.GetBuffer(0));
FName.ReleaseBuffer();
Hope this helps you
Knock out 't' from can't,
You can if you think you can
|
|
|
|
|
Hi Laxman,
Do u remember yesterday i had asked u for changing the file path
C:\folder\folder\file.ext
to
c:/folder/folder/file.ext
now i have written a small program in which will change the input and get the output as
c:/folder/folder/file.ext
now i am facing one more problem file is not opening
ShellExecute(NULL, "open", str,NULL, NULL, SW_SHOWNORMAL)
is this the correct way to open the file is the code correct...
str is of char array
char str[100];
|
|
|
|
|
Can you show me the code how you changed the string path?
May be there was any bug i think code is correct.
Knock out 't' from can't,
You can if you think you can
|
|
|
|
|
Hi Laxman,
below code changes c:\folder\folder\file1.txt
to
c:/folder/folder/file1.txt
void CSearchDlg::OnDblclkSout()
{
// TODO: Add your control notification handler code here
// Code to open the selected file.
int d;
d=m_SOUT.GetCurSel();
CString FName;
m_SOUT.GetText(d,FName);
char str[100];
int i,l,k,j,m;
strcpy(str, FName);
for (i=0;str[i]!='\0';i++)
{
if (str[i]=='\\')
{
l=i; k=0;
char str1[100];
if (str[l+1]=='\0')
{
str[l]='/';
}
else
{
for (j=l+1;str[j]!='\0';j++)
{
str1[k]=str[j];
k++;
}
str1[k]='\0';
str[l]='/';
for (m=0;str1[m]!='\0';m++)
{
str[++l]=str1[m];
}
}
str[++l]='\0';
i=i++;
}
}
m_ctrlEDIT.SetWindowText(str);
ShellExecute(NULL, "open", str ,NULL, NULL, SW_SHOWNORMAL);
}
|
|
|
|
|
Try the following code as its tested and works fine.
CString str;
m_SOUT.GetText(m_SOUT.GetCurSel(),str);
ShellExecute(m_hWnd,NULL,str, NULL, NULL, SW_SHOWNORMAL);
m_ctrlEDIT.SetWindowText(str);
Hope this solve your problem.
Knock out 't' from can't,
You can if you think you can
|
|
|
|
|
Hi Laxman,
I tryed the above code it has no effect ..file does not open
m_ctrlEDIT.SetWindowText(str);
i have used this statment to just to check the value of str
str was value was like
C:\Box01/00000304/00000034.txt
as u said it cant open \ right ???
|
|
|
|
|
vinaycool wrote: C:\Box01/00000304/00000034.txt
How this is possible?
Your path in list box should be either
C:/Box01/00000304/00000034.txt
or
C:\Box01\00000304\00000034.txt
i think you are not inserting the data into list box correctly..
have you?
Knock out 't' from can't,
You can if you think you can
|
|
|
|
|
Hi,
In the list box items are like
C:\Box01/00000304/00000034.txt
C:\Box01/00000304/00000035.txt
C:\Box01/00000304/00000036.txt
but after the function i get the value in the str as
C:/Box01/00000304/00000034.txt
since the path is correct with file name it should open right ??
|
|
|
|
|
vinaycool wrote:
In the list box items are like
C:\Box01/00000304/00000034.txt
C:\Box01/00000304/00000035.txt
C:\Box01/00000304/00000036.txt
but after the function i get the value in the str as
C:/Box01/00000304/00000034.txt
since the path is correct with file name it should open right ??
Can you post the block for insertion of the data into list box ?
and Do you want to open only .txt files?
Knock out 't' from can't,
You can if you think you can
|
|
|
|
|
Hi,
code for inseting file names to list box & i have open only txt files only.
void CSearchDlg :: disp ()
{
int i = 0;
while (strlen (shWord[i].file_name) > 1)
{
m_SOUT.AddString(shWord[i].file_name);
int k = 0;
TCHAR buff[100];
strcpy(buff,"\0");
while (shWord[i].w_offset[k] != -1)
{
TCHAR buffer[50];
int f=shWord[i].w_offset[k];
_itoa(f,buffer,10);
strcat(buff,buffer);
strcat(buff,",");
k++;
}
buff[strlen(buff)-1]='\0';
m_SOUT.AddString(buff);
i++;
}
}
|
|
|
|
|
while (shWord[i].w_offset[k] != -1)
{
TCHAR buffer[50];
int f=shWord[i].w_offset[k];
_itoa(f,buffer,10);
strcat(buff,buffer);
strcat(buff,",");
k++;
} try this:
while (shWord[i].w_offset[k] != -1)
{
sprintf(buff,"%s%d,",buff,shWord[i].w_offset[k]);
k++;
} vinaycool wrote: m_SOUT.AddString(shWord[i].file_name);
what is datatype of file_name?
Knock out 't' from can't,
You can if you think you can
|
|
|
|
|
Hi Laxman,
I got the solution, the problem was some junk character was getting added to the file name,so it was not able to open file,i just altered the file name removed the last junk character str[i-1]='\0';now the file open properly...
Since its in the list box user keep on cliking on items and open any number of files but i want only file to be open at a time..
when the user clicks on the item i want the open file to closed(txt files) and slected file to opened is there any way to close and then open a file ??
please let know if there any way
|
|
|
|
|
vinaycool wrote: when the user clicks on the item i want the open file to closed(txt files) and slected file to opened is there any way to close and then open a file ??
You have to trace the running processes and get the Handle of the NOTEPAD.exe which is the default application of the .txt files and terminate that process before executing the ShellExecute.
Knock out 't' from can't,
You can if you think you can
|
|
|
|
|
use
CString FName123;
char str123[100];
FName123="test";
wsprintf(str123,"%s",FName123);
--------------------------
or
str123[0]='\0';
strcat(str123,FName123);
whitesky
|
|
|
|
|
Hi,
I have used this code its workin thank you very much
strcpy(str, (LPCTSTR) FName);
strcpy(str, FName.GetBuffer(100));
|
|
|
|
|
Just this will do:
strcpy(str, FName);
You don't need the (LPCTSTR) cast; it will be called automatically. Having a cast you don't need (especially c-style casts, which should never be used in a C++ program) is at best redundant and can even be dangerous.
Calling GetBuffer is not needed and should not be done without a matching call to ReleaseBuffer anyway.
Steve
|
|
|
|
|
Hi !!!
You can try to use this.
1.) str = FName.c_str();
2.) str = (char[])FName;
I hope, I helped you.
By.
-:KNOX:-
|
|
|
|
|
I get the emule source about 4.50 MB
But I do not know how to complie it ?
Who can help me ?
Thks
my email is
fisheryj # gmail.com
|
|
|
|
|
And what is the problem exactly ? Normally, you should have a projet file that you can open and then simply compile the project.
What version of visual studio are you using ? I think eMule was developped with VC2003.
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
I use vc 2005 to complie it
but it say no some header file
--------------------------------
fisheryj # gmail.com
jerry
|
|
|
|
|
Geez, when you have a question, at least take the time to explain CLEARLY the problem ("This doesn't work" is not a clear description of the problem). We are not gods and so we cannot see what happens on your computer.
I suppose you get a compile error ? Give the exact error message and give as much information as you can.
jerry11111 wrote: but it say no some header file
What I am supposed to understand from a sentence like that ?
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
I hear it need another library file.
--------------------------------
fisheryj # gmail.com
jerry
|
|
|
|
|
Hi,
Post your Q properly if u need a solution ...dont just leave the important information just give just & some on the message...
|
|
|
|