• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 601
  • Last Modified:

Some error with datatype

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
TPoly
Asked:
TPoly
  • 6
  • 5
6 Solutions
 
drichardsCommented:
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
 
drichardsCommented:
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
 
drichardsCommented:
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
TPolyAuthor Commented:
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
 
drichardsCommented:
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
 
drichardsCommented:
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
 
TPolyAuthor Commented:
Actually I need to use unicode.

Do you know of any other tokenizer that handles wstrings?
0
 
drichardsCommented:
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
 
TPolyAuthor Commented:
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
 
TPolyAuthor Commented:
To add to my last post:

I am using eMbedded Visual C++ for this project, does it matter?
0
 
TPolyAuthor Commented:
==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
 
rstaveleyCommented:
Add -GX to your compiler options. Stack unwinding isn't enabled by default, but you need it with STL.
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now