|
Thanks Alain,
I have tried but it does not work. Here is all the compiler options I used. Could you help to take a look to see if there are any other options trigger /GS please? If you need any further information to find the root cause, please feel free to let me know.
/Od /Os /I "..\include" /I /D "_DEBUG" /D "_WIN32_WCE=0x420" /D "UNDER_CE" /D "WIN32_PLATFORM_PSPC" /D "WINCE" /D "DEBUG" /D "_WINDOWS" /D "ARM" /D "_ARM_" /Gm /EHsc /MTd /GS- /fp:fast /GR- /Fo"Pocket PC 2003 (ARMV4)\Debug/" /Fd"Pocket PC 2003 (ARMV4)\Debug/vc80.pdb" /W3 /nologo /c /Zi /TP
regards,
George
|
|
|
|
|
Hello everyone,
If I change the entry point to main in linker --> advanced (default is empty). Then there will be an error box,
can not find MSVCR80D.dll. What is wrong with my code? (if I change the entry point of application from main to empty, there is no such error)
<br />
static int i = 100;<br />
<br />
int main(int argc, char** argv)<br />
{<br />
int j;<br />
<br />
return 0;<br />
}<br />
I am using Visual Studio 2005 console application project.
thanks in advance,
George
|
|
|
|
|
If you initialize j whats result?
|
|
|
|
|
Hi Hamid,
The same result. Can you reproduce?
regards,
George
|
|
|
|
|
And if you change if to other words you get this error(like Winmain) error LNK2001: unresolved external symbol __main
|
|
|
|
|
Thanks Hamid,
Could you post your code please?
regards,
George
|
|
|
|
|
Im using your code and I was using if main that you told and I got this error.
|
|
|
|
|
|
If I add any thing to entry point I cant compile your code else it doesnt any problem.(Visual sutdio2008)
|
|
|
|
|
Thanks Hamid,
If I add main to entry point, I can build, but when run it has errors.
regards,
George
|
|
|
|
|
But I get a linker error and I cant comnpile it.
|
|
|
|
|
Sorry, Hamid!
There is no link error for me and I can not reproduce it. I only have runtime error.
regards,
George
|
|
|
|
|
It was interest for me your question.
|
|
|
|
|
Thanks Hamid,
I like to discuss with you. But for this case, we'd better be able to reproduce the situation by others, right?
regards,
George
|
|
|
|
|
I never tested this problem previous I think I must tell you thanks for your help.
|
|
|
|
|
It is ok, Hamid!
We are helping each other.
regards,
George
|
|
|
|
|
By the way I have a different question did you study in psychology?
|
|
|
|
|
Hi,
I'm seeing a strange problem; I learned to program in C and compiled with gcc, and back when I used to use character arrays all the time, I always needed to free memory. For instance:
char *a = new char(100);
Before the function was out, I would need to free it:
free(a);
Now I'm working on an MFC app (using VC++ .NET 2005) and it seems to crash when I try to free the memory (in this same situation; where I've created a character array, used it, then need to delete it a few lines later). Is allocation handled differently with the newer C++ compilers?
Thanks!
KR
|
|
|
|
|
One point I can say is when using new , you use delete . And when using malloc , use free . What was the message when the application crashed?
|
|
|
|
|
It does the same thing whether I use delete or free, and there's no message, it just crashes somewhere in free.c. If I set the char array to a static size then I see no issues, it's only when I allocate memory for it. Then, regardless of whether I delete or don't delete, my program starts showing very odd behavior.
Here's the actual code:
#ifdef _UNICODE
CString strText = (This piece of code returns a CStringA from the back-end of my program)
if (strText.GetLength() <= 0)
return false;
char *convertThis = new char(strText.GetLength());
sprintf(convertThis, "%s", strText);
int nLen = lstrlenA(convertThis);
BSTR unicodeStr = SysAllocStringLen(NULL, nLen);
MultiByteToWideChar(CP_ACP, 0, convertThis, nLen, unicodeStr, nLen);
m_EditControl.SetWindowText(unicodeStr);
SysFreeString(unicodeStr);
delete convertThis;
#else
Everything works fine if I set convertThis to a static size. If I allocate, everything goes haywire whether I free memory or not, but especially quickly if I free memory.
KR
|
|
|
|
|
I see a few problems here...
#ifdef _UNICODE
CString strText = (This piece of code returns a CStringA from the back-end of my program) <font color="Red"><-- assigning a CStringA to a CString shouldn't compile - mismatched types</font>
if (strText.GetLength() <= 0)
return false;
char *convertThis = new char(strText.GetLength()); <font color="Red"><-- what about +1 for the null terminator?</font>
sprintf(convertThis, "%s", strText); <font color="Red"><-- _UNICODE is defined, so strText is a wchar_t type string - this copy to char is invalid</font>
int nLen = lstrlenA(convertThis);
BSTR unicodeStr = SysAllocStringLen(NULL, nLen); <font color="Red"><-- why BSTR? A wchar_t array is the appropriate type for unicode - MultiByteToWideChar() takes a LPWSTR, not a BSTR</font>
MultiByteToWideChar(CP_ACP, 0, convertThis, nLen, unicodeStr, nLen); <font color="Red"><-- The original CString was already Unicode...this conversion is unnecessary</font>
m_EditControl.SetWindowText(unicodeStr);
SysFreeString(unicodeStr);
delete convertThis;
#else If you just need to convert a CStringA to a CString, you can just do this:
<font color="Green">
CStringA strText = (This piece of code returns a CStringA from the back-end of my program)
CString strTextGeneric(strText);
m_EditControl.SetWindowText(strTextGeneric);
<font color="Green"> Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Unfortunately it's not that simple, the string type is a CStringW yes but the characters are actually in CStringA format so the conversion is necessary. The compiler doesn't realize that it's a CStringA because the project settings for my front-end project define _UNICODE but my backend (a series of separate projects and libraries) is all in MBCS, which is where the function comes from (i.e. lots of text without the _T macro). I can't change that - the backend is going to return a multi-byte CString no matter what I do, but the program and compiler think it's of type CStringW because of my front-end project settings.
sprintf works correctly because of the above reason (even though CString type is a wide character array, the data inside is actually MBCS format).
I need the BSTR because MultiByteToWideChar will not compile if I define the type as wchar_t, and SetWindowText would require a conversion if I defined the type as LPWSTR. If I use BSTR I can do what I did and it works, if I don't use a BSTR additional steps are required.
I have tried:
CStringA strText = (CStringA)function();
CString strTextGeneric(strText);
m_EditControl.SetWindowText(strTextGeneric);
But that does not work, it just returns some garbled crud, probably because it thinks that the piece of code that returns CStringA is actually a CStringW.
But you're right about the +1 for null terminator, I did forget about that. However it doesn't help if I add that, it still crashes unless I define convertThis as a char array with a static length.
KR
|
|
|
|
|
KellyR wrote: I need the BSTR because MultiByteToWideChar will not compile if I define the type as wchar_t, and SetWindowText would require a conversion if I defined the type as LPWSTR
That doesn't make sense. A BSTR is a WCHAR*, which is a wchar_t*
Using a generic string type, implemented as a template no less, on a back end that could be used
by a front end with a different type....bummer. I don't know what to say about that
Regardless, I suppose using the square brackets and leaving room for null terminators should
help a lot.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: Using a generic string type, implemented as a template no less, on a back end that could be used
by a front end with a different type....bummer. I don't know what to say about that
It's horrible.
Mark Salsbery wrote: Regardless, I suppose using the square brackets and leaving room for null terminators should
help a lot.
Everything seems to work now with square brackets and with the +1 for null terminator. Thanks!
KR
|
|
|
|
|
KellyR wrote: It's horrible.
Heh - it's painful to think about
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|