CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    Join Date
    Apr 2001
    Posts
    488

    Errors on release build with UNICODE

    Can someone explain to me why I would need to include UNICODE in my application? I seem to be having some problems when I switch from debug to release build. If I comment out all my stuff in my stdafx.h file that deals with unicode,

    #define _WIN32_WINNT 0x403
    //#define UNICODE
    #define _UNICODE

    #include <windows.h>
    #include <iostream>
    using namespace std;

    #ifdef UNICODE
    #define _tcout wcout
    #define _tostream wostream
    #else
    #define _tcout cout
    #define _tostream ostream
    #endif



    it builds fine but gives me an error when I try to run the program (Application Error the memory could not be written...). If I leave the UNICODE stuff in, when It builds I get the error
    Compiling...
    CVIEWService.cpp
    C:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afxinet.inl(39) : error C2664: 'GopherGetLocatorTypeW' : cannot convert parameter 1 from 'const char *' to 'const unsigned short *'. It is a problem between my debug and release builds, because the debug build works great! I have checked the project settings and there is no unicode defined in the release build. Does anyone have any suggestions????


  2. #2
    Join Date
    Apr 2001
    Posts
    90

    Re: Errors on release build with UNICODE

    try putting _UNICODE in your preprocessor directives in Project|Setttings|C++|Preprocessor...

    CodeHacker
    Rate me if it helped, Thanks

  3. #3
    Join Date
    Apr 2001
    Posts
    488

    Re: Errors on release build with UNICODE

    I have tried that. It gives me a ton of other errors. I think the problem that I have comes from the fact that I took existing C code and added it to my MFC project. I think that the old code uses UNICODE stuff (atleast the header file includes UNICODE), and obviously the MFC stuff does not. How can I get around this?


  4. #4
    Join Date
    Apr 2001
    Posts
    90

    Re: Errors on release build with UNICODE

    Did you remember to put wWinMainCRTStartup as your Link|Entry Point?

    CodeHacker
    Rate me if it helped, Thanks

  5. #5
    Join Date
    Apr 2001
    Posts
    488

    Re: Errors on release build with UNICODE

    Okay, you lost me. How do I do that? Where is my link/entry point? and how do I put wWinMainCRTStartup there or check to see if it is there. I assume that it is under project/settings, but the only thing that I see there that has to do with link and entry is under the link tab and the output option.


  6. #6
    Join Date
    Apr 2001
    Posts
    90

    Re: Errors on release build with UNICODE

    That's exactly where you put it 8-)

    CodeHacker
    Rate me if it helped, Thanks

  7. #7
    Join Date
    Apr 2001
    Posts
    488

    Re: Errors on release build with UNICODE

    When I put it there it gives me a linking error if I do not include the unicode in the header. If I do include the Unicode, (#define UNICODE) then it gives me the same 3 original errors.

    --------------------Configuration: CVIEW Service - Win32 Release--------------------
    Compiling...
    CVIEWService.cpp
    C:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afxinet.inl(39) : error C2664: 'GopherGetLocatorTypeW' : cannot convert parameter 1 from 'const char *' to 'const unsigned short *'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    Service.cpp
    C:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afxinet.inl(39) : error C2664: 'GopherGetLocatorTypeW' : cannot convert parameter 1 from 'const char *' to 'const unsigned short *'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    xCVIEW.cpp
    C:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afxinet.inl(39) : error C2664: 'GopherGetLocatorTypeW' : cannot convert parameter 1 from 'const char *' to 'const unsigned short *'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    Generating Code...
    Error executing cl.exe.

    CVIEWService.exe - 3 error(s), 0 warning(s)


  8. #8
    Join Date
    Apr 2001
    Posts
    90

    Re: Errors on release build with UNICODE

    I'm assuming these errors are on lines containing literal strings. Just put an L in front of your string, like...

    L"Hello World"

    CodeHacker
    Rate me if it helped, Thanks

  9. #9
    Join Date
    Apr 2001
    Posts
    488

    Re: Errors on release build with UNICODE

    Actually the errors are coming from a Microsoft file not from my code. My project seems to have a problem with the Microsoft code in "afxinet.inl". If it was just as easy as putting an L in front of a string, I would jump for joy. I think this problem is a little more complex. I have been stuck on it for days. Thanks for all the advice though. I will go though and rate what we have discussed. Please let me know if you have any other ideas. I am at the end of my rope.


  10. #10
    Join Date
    Aug 2001
    Location
    Minnesota, USA
    Posts
    801

    Re: Errors on release build with UNICODE

    Your problem is that _UNICODE is not being defined early enough. The error results because the LPCTSTR type is being defined as const char * instead of const unsigned short * (wchar_t). Do you define _UNICODE before any includes in stdafx.h?

    Chris Richardson


  11. #11
    Join Date
    Apr 2001
    Posts
    90

    Re: Errors on release build with UNICODE

    I had a funky problem with UNICODE once and it turned out that I HAD to have #include "stdafx.h" as the 1st include in ALL of my files. Also, check your precompiled header settings for all of your files. Other than that good luck. Thanks for rating.

    CodeHacker
    Rate me if it helped, Thanks

  12. #12
    Join Date
    Apr 2001
    Posts
    90

    Re: Errors on release build with UNICODE

    Make sure the preprocessor definition MCBS is not in your settings as well! That bit me once. If none of this works I would manually go through ALL of the project settings in the debug mode since it works. Then compare them to your release settings. Only things like _DEBUG, etc should be different.

    CodeHacker
    Rate me if it helped, Thanks

  13. #13
    Join Date
    Apr 2001
    Posts
    488

    Re: Errors on release build with UNICODE

    Great suggestion. I have messed around with it and put my #define UNICODE at the very top of my stdafx.h file and I get 102 errors all of them similar in syntax.

    Compiling...
    StdAfx.cpp
    C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\ios.h(146) : error C2872: 'streambuf' : ambiguous symbol
    C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\ios.h(159) : error C2872: 'ostream' : ambiguous symbol
    C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\ios.h(159) : error C2872: 'ostream' : ambiguous symbol
    C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\ios.h(160) : error C2872: 'ostream' : ambiguous symbol
    C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\ios.h(180) : error C2872: 'streambuf' : ambiguous symbol
    etc ...

    I have even commented out everything except the MFC stuff and the unicode stuff.

    //#define _WIN32_WINNT 0x403
    #define UNICODE
    #define _UNICODE

    //#include <windows.h>
    //#include <iostream>
    //using namespace std;

    #ifdef UNICODE
    #define _tcout wcout
    #define _tostream wostream
    #else
    #define _tcout cout
    #define _tostream ostream
    #endif
    #include <TCHAR.H>

    #if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000

    #include <iostream.h>
    #include <process.h>
    #include <TCHAR.h>
    #include <afxwin.h> // MFC core and standard components
    #include <afxext.h> // MFC extensions
    #include <afxdisp.h> // MFC Automation classes
    #include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
    #ifndef _AFX_NO_AFXCMN_SUPPORT
    #include <afxcmn.h> // MFC support for Windows Common Controls
    #include <afxmt.h>
    #endif // _AFX_NO_AFXCMN_SUPPORT



    and then I get the following errors,

    Compiling...
    StdAfx.cpp
    Compiling...
    common.cpp
    E:\CLC\VSS\xCVIEW\xCVIEW code modifications\common.cpp(68) : error C2664: 'CreateProcessW' : cannot convert parameter 1 from 'const char *' to 'const unsigned short *'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    E:\CLC\VSS\xCVIEW\xCVIEW code modifications\common.cpp(114) : error C2664: 'CreateProcessW' : cannot convert parameter 1 from 'const char *' to 'const unsigned short *'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    E:\CLC\VSS\xCVIEW\xCVIEW code modifications\common.cpp(176) : error C2664: 'RegEnumKeyW' : cannot convert parameter 3 from 'char [260]' to 'unsigned short *'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    E:\CLC\VSS\xCVIEW\xCVIEW code modifications\common.cpp(181) : error C2664: 'RegEnumKeyW' : cannot convert parameter 3 from 'char [260]' to 'unsigned short *'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    E:\CLC\VSS\xCVIEW\xCVIEW code modifications\common.cpp(184) : error C2664: 'RegOpenKeyExW' : cannot convert parameter 2 from 'char [260]' to 'const unsigned short *'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    E:\CLC\VSS\xCVIEW\xCVIEW code modifications\common.cpp(254) : error C2664: 'RegEnumKeyW' : cannot convert parameter 3 from 'char [260]' to 'unsigned short *'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    E:\CLC\VSS\xCVIEW\xCVIEW code modifications\common.cpp(259) : error C2664: 'RegEnumKeyW' : cannot convert parameter 3 from 'char [260]' to 'unsigned short *'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    E:\CLC\VSS\xCVIEW\xCVIEW code modifications\common.cpp(262) : error C2664: 'RegOpenKeyExW' : cannot convert parameter 2 from 'char [260]' to 'const unsigned short *'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    CVIEWService.cpp
    E:\CLC\VSS\xCVIEW\xCVIEW code modifications\CVIEWService.cpp(373) : error C2664: '__thiscall CEventLog::CEventLog(const unsigned short *,const unsigned short *)' : cannot convert parameter 1 from 'char [7]' to 'const unsigned short *'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    E:\CLC\VSS\xCVIEW\xCVIEW code modifications\CVIEWService.cpp(403) : error C2664: 'CreateMutexW' : cannot convert parameter 3 from 'char [17]' to 'const unsigned short *'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    E:\CLC\VSS\xCVIEW\xCVIEW code modifications\CVIEWService.cpp(477) : error C2664: 'strcpy' : cannot convert parameter 1 from 'unsigned short [257]' to 'char *'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    E:\CLC\VSS\xCVIEW\xCVIEW code modifications\CVIEWService.cpp(478) : error C2664: 'strcpy' : cannot convert parameter 1 from 'unsigned short [257]' to 'char *'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    EventLog.cpp
    Service.cpp
    E:\CLC\VSS\xCVIEW\xCVIEW code modifications\Service.cpp(294) : error C2664: 'CxCVIEW::CxCVIEW' : cannot convert parameter 1 from 'char [7]' to 'unsigned short *'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    E:\CLC\VSS\xCVIEW\xCVIEW code modifications\Service.cpp(370) : error C2664: '__thiscall CEventLog::CEventLog(const unsigned short *,const unsigned short *)' : cannot convert parameter 1 from 'char [7]' to 'const unsigned short *'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    xCVIEW.cpp
    .
    .
    .
    etc (72 of those)


  14. #14
    Join Date
    Aug 2001
    Location
    Minnesota, USA
    Posts
    801

    Re: Errors on release build with UNICODE

    I hope that was not a sarcastic 'Great Suggestion' in your last post. If you knew what was going on with those errors, you would simply go fix them. Replace all your instances of char with TCHAR, and you will get rid of some of them. The next step is to replace your function calls like strcpy with the TCHAR equivalents. In the case of strcpy it is _tcscpy. The last step is when you have literal strings, you should put eclose them in the _T macro like this:

    const TCHAR * pString = _T("Hello");

    I have just done this to a large application and it is not very difficult. Then it will build unicode and ansi, debug and release.

    Chris Richardson


  15. #15
    Join Date
    Apr 2001
    Posts
    90

    Re: Errors on release build with UNICODE

    Did you resolve this issue? If so, please post the solution for the rest of us.

    CodeHacker
    Rate me if it helped, Thanks

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured