Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Some error with datatype

Posted on 2004-09-21
12
Medium Priority
?
596 Views
Last Modified: 2013-12-14
hi all,

i had downloaded the mapirule.cpp from the msdn site to intercept an incoming SMS..

i also downloaded a SendSms codes from : http://www.codeproject.com/ce/SMS_CEMPI.asp.
to send sms.

i also downloaded a string tokeniser from : http://www.codeproject.com/cpp/stringtok.asp

i had edited the codes inside the mapirule.ccp

===start codes edited===
if (wcsstr(pspvEmail->Value.lpszW, L"98494778") != NULL)

      {
            MessageBeep(MB_ICONASTERISK);
            MessageBox(NULL, pspvSubject->Value.lpszW, pspvEmail->Value.lpszW, MB_OK);

            //HANDLE hFile = CreateFile(_T("\\My Documents\\Personal\\jobs.txt"),GENERIC_WRITE, FILE_SHARE_READ,NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

            HANDLE hFile;
            const TCHAR* filename = TEXT("\\My Documents\\Personal\\jobs.txt"); // Name of file to be written
            const TCHAR* file_contents = pspvSubject->Value.lpszW; // String to be written to file
            TCHAR message[255]; // String to be displayed in message box
            //DWORD btw;
            DWORD bytesWritten;

            string show="";
            string in_file="";

            //The Results Vector
            vector<string> oResult;
            //Call Tokeniker
            in_file=file_contents;
            CTokenizer<CIsComma>::Tokenize(oResult, in_file, CIsComma());
            //Display Results
            for(int i=0; i<oResult.size(); i++)
              show+=oResult[i]+"TOK";

MessageBox(NULL,show, TEXT("????"), MB_OK);
            
            // Open existing file or create it if it does not exist
            hFile = CreateFile(filename, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);


            if (hFile == INVALID_HANDLE_VALUE)
            MessageBox(NULL,TEXT("Couldn't create the file!"), TEXT("Create File ERROR"), MB_OK);
            else
            {
wsprintf(message, TEXT("%s"), file_contents);
//btw = wcslen(message)*sizeof(TCHAR);

                  // Write a string to the file
                  if (WriteFile(hFile, message ,wcslen(message)*sizeof(TCHAR) , &bytesWritten, NULL)!=0)
                  {
                  //wsprintf(message, TEXT("Success - String %s written to file %s."), file_contents, filename);
                  wsprintf(message, TEXT("%s"), file_contents);

                  
                  }
                  else
                  {
                  wsprintf(message, TEXT("Error writing to file: %d"), GetLastError());
                  }
            

            // Display the message indicating the result
            MessageBox(NULL, message, TEXT("Result"), MB_OK);

            // Close file handle
            CloseHandle(hFile);

      }
            
            // Delete the message and mark it as handled so it won't show up in Inbox
            hr = DeleteMessage(pMsgStore, pMsg, cbMsg, lpMsg, cbDestFolder, lpDestFolder, pulEventType, pHandled);

            DoSendMessage(_T("hhhh"), (LPCTSTR)pspvEmail->Value.lpszA, _T("Ack:ECS/CQY/B2/PEU03A"));
            //DoSendMessage(_T("hhhh"), _T("97665982"), _T("Ack:ECS/CQY/B2/PEU03A"));
      }
===end of codes edited==


however i am getting some error when i combine e three files together as a common workspace (mapirule.vcw that contains the maipule project files)



below are the error i got..
===start of error===
Compiling...
mapirule.cpp
c:\documents and settings\tp\desktop\projfiles\mapirule(20-9)\tokenizer.h(29) : warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
c:\documents and settings\tp\desktop\projfiles\mapirule(20-9)\mapirule.cpp(634) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'const unsigned short *' (or there is no acceptable conversion)
c:\documents and settings\tp\desktop\projfiles\mapirule(20-9)\mapirule.cpp(640) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'const unsign
===end of error ===

any help will be greatly appreciated..
i need some help urgently..
0
Comment
Question by:TPoly
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
12 Comments
 
LVL 19

Assisted Solution

by:drichards
drichards earned 1920 total points
ID: 12119923
You appear to be doing a unicode buld, so these lines give you trouble:

          in_file=file_contents;
and
          MessageBox(NULL,show, TEXT("????"), MB_OK);

The clues are that it is using MessageBoxW (see error text for line 640) and thinks the string constant is a 'const unsigned short *' instead of a 'const char *'.

You can solve this one of two ways.

1) Turn off UNICODE.  Somewhere, either in a header or more likely in the project properties, you have defined _UNICODE.  You should remove that.

2) use std::wstring instead of std::string.

In either case, there is another problem with the MessageBox.  std::string coes not provide a cast operator to 'const char*', so you need to use:

          MessageBox(NULL,show.c_str(), TEXT("????"), MB_OK);

This will work with either change 1 or 2.
0
 
LVL 19

Assisted Solution

by:drichards
drichards earned 1920 total points
ID: 12119930
Just to be clear, use method 1 or 2, but not both, or you will end up with the opposite problem of the one you currently have.
0
 
LVL 19

Assisted Solution

by:drichards
drichards earned 1920 total points
ID: 12119940
Also, the warning is that you have a line somewhere that is trying to cast an int to a bool.  This is usually solved by doing something like:

   bool result = (val != testVal);

or

   bool result = (val == testVal);

where val is an integer and testVal is the test value.  The condition should be made appropriate (might be <, >, etc.).
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:TPoly
ID: 12120134
Thanks for the speedy reply, drichards.

I've edited my code using method 2.
But there are still some problems.

The boolean warning is solved.

=========edited code=========
                               const TCHAR* filename = TEXT("\\My Documents\\Personal\\jobs.txt"); // Name of file to be written
            const TCHAR* file_contents = pspvSubject->Value.lpszW; // String to be written to file
            TCHAR message[255]; // String to be displayed in message box
            //DWORD btw;
            DWORD bytesWritten;

            wstring show="";
            wstring in_file="";

            //The Results Vector
            vector<string> oResult;
            //Call Tokeniker
            in_file=file_contents;
            CTokenizer<CIsComma>::Tokenize(oResult, in_file, CIsComma());
            //Display Results
            for(int i=0; i<oResult.size(); i++)
              show+=oResult[i]+"TOK";

                               MessageBox(NULL,show.c_str(), TEXT("????"), MB_OK);
=========edited code=========

++++++++++errors++++++++++++
Compiling...
mapirule.cpp


c:\documents and settings\tp\desktop\projfiles\mapirule(20-9)\mapirule.cpp(628) : error C2440: 'initializing' : cannot convert from 'char [1]' to 'class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> >'

No constructor could take the source type, or constructor overload resolution was ambiguous


c:\documents and settings\tp\desktop\projfiles\mapirule(20-9)\mapirule.cpp(629) : error C2440: 'initializing' : cannot convert from 'char [1]' to 'class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> >'

No constructor could take the source type, or constructor overload resolution was ambiguous


c:\documents and settings\tp\desktop\projfiles\mapirule(20-9)\mapirule.cpp(635) : error C2664: 'Tokenize' : cannot convert parameter 2 from 'class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> >' to 'const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &'
       
Reason: cannot convert from 'class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> >' to 'const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >'
No constructor could take the source type, or constructor overload resolution was ambiguous


c:\documents and settings\tp\desktop\projfiles\mapirule(20-9)\mapirule.cpp(638) : error C2679: binary '+=' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conversion)


Error executing clarm.exe.


mapirule.obj - 4 error(s), 0 warning(s)
++++++++++errors++++++++++++
0
 
LVL 19

Assisted Solution

by:drichards
drichards earned 1920 total points
ID: 12120176
Looks like you'll have to turn off UNICODE.  The wstring problems can be easily fixed:

          wstring show=L"";
          wstring in_file=L"";

and the vector needs to be 'vector<wstring>'.

Unfortunately, I don't know what CTokenizer is and it seems to want only string parameters.  You need to recode the functionality of CTokenizer or change the build so it doesn't use UNICODE and put all the wstring's back to string's.
0
 
LVL 19

Expert Comment

by:drichards
ID: 12120201
OK, I looked up CTokenizer on CodeProject.  It does not handle wstring's, so your only option is to go back to string's and get rid of the _UNICODE.  Otherwise, you have to dump or rewrite CTokenizer.
0
 

Author Comment

by:TPoly
ID: 12120213
Actually I need to use unicode.

Do you know of any other tokenizer that handles wstrings?
0
 
LVL 19

Accepted Solution

by:
drichards earned 1920 total points
ID: 12120371
I don't know of one, but here's one I wrote.  It's cheap, but it works.

class CTokenizerW
{
public:
    static Tokenize(std::vector<std::wstring> &result, std::wstring &input, wchar_t delim)
    {
        std::wstring::size_type len = input.length();
        std::wstring::size_type offset = 0;
        while (offset <= len)
        {
            std::wstring::size_type delimPos = input.find(delim, offset);
            result.push_back(std::wstring(input.substr(offset, delimPos-offset)));
            offset = delimPos < len ? delimPos+1 : delimPos;
        }
    }
};

Your code would looklike this:


          wstring show=L"";
          wstring in_file=L"";

          //The Results Vector
          vector<wstring> oResult;
          //Call Tokeniker
          in_file=file_contents;
          CTokenizerW::Tokenize(oResult, in_file, (wchar_t)',');
          //Display Results
          for(int i=0; i<oResult.size(); i++)
            show+=oResult[i]+L"TOK";
0
 

Author Comment

by:TPoly
ID: 12120563
so your CTokenizerW class change with the Tokenizer.h 's class CTokenizer is it?

and
======
Your code would looklike this:


          wstring show=L"";
          wstring in_file=L"";

          //The Results Vector
          vector<wstring> oResult;
          //Call Tokeniker
          in_file=file_contents;
          CTokenizerW::Tokenize(oResult, in_file, (wchar_t)',');
          //Display Results
          for(int i=0; i<oResult.size(); i++)
            show+=oResult[i]+L"TOK";
=========

jus edit in the mapirule.cpp?
0
 

Author Comment

by:TPoly
ID: 12120684
To add to my last post:

I am using eMbedded Visual C++ for this project, does it matter?
0
 

Author Comment

by:TPoly
ID: 12120961
==new error===

Compiling...
mapirule.cpp
c:\program files\windows ce tools\wce420\pocket pc 2003\include\armv4\xstring(724) : warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify -GX
        c:\program files\windows ce tools\wce420\pocket pc 2003\include\armv4\xstring(720) : while compiling class-template member function 'void __cdecl std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::_Copy(unsign
ed int)'
c:\program files\windows ce tools\wce420\pocket pc 2003\include\armv4\xstring(724) : warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify -GX
        c:\program files\windows ce tools\wce420\pocket pc 2003\include\armv4\xstring(720) : while compiling class-template member function 'void __cdecl std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<u
nsigned short> >::_Copy(unsigned int)'

mapirule.obj - 0 error(s), 2 warning(s)

===end of error===
0
 
LVL 17

Assisted Solution

by:rstaveley
rstaveley earned 80 total points
ID: 12122489
Add -GX to your compiler options. Stack unwinding isn't enabled by default, but you need it with STL.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question