|
I need to convert CString to char in my project
below is my code
<br />
CString str="Test";<br />
char ch[64]<br />
strcpy(ch,str);<br />
that code work in VC6 but now I use VS2005 it show error about
"cannot convert parameter 2 from 'CString' to 'const char *'"
Please help me to solve this problem
|
|
|
|
|
You've already done it!
<br />
TCHAR *ch=str.GetBuffer();<br />
|
|
|
|
|
Never ever use GetBuffer without knowing what it does !
Please read the documentation about this function in MSDN and you'll see that it is the worst thing to do...
|
|
|
|
|
Thanks for your warning! Like I was wrong!
Now, would U explain why please.
|
|
|
|
|
See here[^]
EDIT: apparently the full link doesn't work. On this page you have to go in the section called " CString to char */TCHAR * II: Using GetBuffer".
|
|
|
|
|
Thanks "Cedric Moonen" 4 Ur kind.
|
|
|
|
|
Usef Marzbani wrote: Now, would U explain why please.
Because it returns a pointer to the internal character buffer of the CString object, which is obviously not necessary. The returned LPTSTR is not const and thus direct modification of the CString contents are allowed. Why would you deem such potential modification as acceptable?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
That's because UNICODE is defined by default in VC2005. So, either remove UNICODE if you don't need it or use generic text mappings (like TCHAR).
For option 1: go in the project properties -> "C/C++" -> "Preprocessor" -> click on "Preprocessor Definitions" then click on the button that appeared on the right, there uncheck the "Inherit from parent or project default".
For option 2: that's the better because then your code will be able to support UNICODE. For that, use TCHAR instead of char. I suggest you search for articles on CP about UNICODE, there are some which really well written and you'll learn a lot about those things.
|
|
|
|
|
After I change the option I got the error link during build as
<br />
error LNK2019: unresolved external symbol _wWinMain@16 referenced in function ___tmainCRTStartup<br />
|
|
|
|
|
In the linker options -> "Advanced", the is an option "Entry Point". There you should have something like wWinMainCRTStartup. Remove the 'w' in front of the name.
|
|
|
|
|
Since Visual Studio 2005 makes by default UNICODE builds then your CString object maintains a UNICODE string, even if you're assigning it a ANSI one (CString constructor makes the conversion). To fix your code follow Cédric Moonen suggestions [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Max++ wrote: char ch[64]
strcpy(ch,str);
How about:
TCHAR ch[64];
_tcscpy_s(ch, str.GetLength(), str);
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
hi,
before I install the visual studio 2005, I use the vc 6.0 to debug, when I run the program, if finally there are some bug, the visual 6.0 will jump to the line that has bugs, but after i installed the vc 2005, for the same program(I run it in vc 6.0), if I run it, then the vc tells me I have not start the just-in-time debugger, but I can not find out where to set just-in-time debugger,
any ideas?
|
|
|
|
|
I had the Same Problem. Struggled with it for months, reinstalled VC6, No Avail. Ended up re-installing XP as a new installation. i.e. Scrap the entire Drive. re-installed VC, that solved it.
Bram van Kampen
|
|
|
|
|
Hi , sorry for a new thread. I needed to open it since I made some progress.
By the way , I implemented my callback function without buffering as below. So can you check it ?
Especially I am not sure about getting floats from BYTEs and , replacing new floats back after making some signal processing.
STDMETHODIMP BufferCB( double SampleTime, BYTE * pBuffer, long BufferSize )
{
unsigned int i,j ;
short nCurrentSampleValue = 0 ,temp = 0;
float fCurrentSampleValue = 0,fNewSampleValue =0 ;
long nSampleCount ;
short nRatioOfDataTypes ;
nRatioOfDataTypes = sizeof(short)/sizeof(BYTE) ;
nSampleCount = BufferSize / nRatioOfDataTypes;
for(i=0;i<nSampleCount;i++)
{
nCurrentSampleValue = 0 ;
fCurrentSampleValue = 0 ;
for(j=0;j<nRatioOfDataTypes ;j++)
{
temp = 0x0000 ;
temp = ((short)pBuffer[i*nRatioOfDataTypes+j]) ;
temp = temp << (8*(nRatioOfDataTypes-j-1)) ;
nCurrentSampleValue |= temp ;
fCurrentSampleValue = ((float)nCurrentSampleValue) / 32768 ;
}
fNewSampleValue = MAKE_SOME_SIGNAL_PROCESS(fCurrentSampleValue);
////////////////////////////////////////////
temp = (short) (fNewSampleValue*32768);
pBuffer[i*nRatioOfDataTypes] = (BYTE) (temp & 0xFF00) ;
pBuffer[i*nRatioOfDataTypes+1] = (BYTE) (temp & 0x00FF) ;
////////////////////////////////////////////
}
}
Finally can you send me any sample code for buffering or make any suggestion about that ?
Thank you very much...
Best Regards
|
|
|
|
|
Hello everyone,
Just want to confirm whether my understanding is correct.
The statement in source file,
#pragma comment(lib, "DLL1.lib")
has the same effect (as an alternative approach) of set DLL1.lib as implicit link library input in project link settings? So, we choose either one method to configure implicit linking input library?
thanks in advance,
George
|
|
|
|
|
Yes both methods have the same effect on the generated PE image. There is no difference. It should be noted that this particular pragma is not standard and Microsoft specific.
Best Wishes,
-David Delaune
|
|
|
|
|
Thanks David,
Question answered.
regards,
George
|
|
|
|
|
Hi,
I am running 32 bit code I just used depends on dbghelp.dll
and noticed a function StackWalk can I use this if so same parms
as StackWalk64
|
|
|
|
|
I just checked and both function prototypes have the same signature. So I would hazard a guess that they work the same. Looks like all of the 64 bit DBG functions have a postfix of '64' to distinguish them.
Best Wishes,
-David Delaune
|
|
|
|
|
So if I am running 32 bit windows this isn't going to work
|
|
|
|
|
I am beginning to question my comprehension of your original question.
*takes out his crystal ball*
If you were asking if you can call the 32 bit function on a 32 bit platform in the same way as the 64 bit function on a 64 bit platform then the answer appears to be 'Yes'.
If you were asking if you can call StackWalk on a 64 bit platform then the answer is 'No' and vice versa.
Hope this helps!
-David Delaune
|
|
|
|
|
Sorry I wasn't being clear
Anyway I found code demo called Stackwalk.cpp
Which loads imagehlp.dll gets the address of a number of
functions including Stackwalk and seems to work on my 32 bit windows
Thankx for yor help
|
|
|
|
|
Hex equivalent of character ‘ø’ is “f8”, but I’m getting the result “fffffff8” in szArr after execution of following statement.
sprintf(szArr, "%x", 'ø');
Can anyone please tell me what am I doing wrong?
This problem occurs with "Extended ASCII Codes"
Thanks,
Mushq
modified on Sunday, April 13, 2008 12:25 AM
|
|
|
|