1

Possible Duplicate:
Use CString in console app when using VS Express

I'm seriously rusty with C, seems alot has changed since the last time I used it.

I'm trying to build a program that was written in VS2008, only I'm using 2012 Express. So, naturally, errors are everywhere.

First one on the list is CString. Keeps coming up as an undeclared identifier. From what I've picked up, the library isn't included in VS2012 Express. So I need to find a workaround. So far, Google is giving me results I can't understand (as stated, I'm seriously rusty).

Can anyone give me an easier alternative to CString in the code below? Thanks!

bool Decoder::decode(LPCWSTR theCaption, TABLE_SUMMARY& table)
{

 // If the caption doesn't contain the word "You" return false
CString strCaption = theCaption;


if (-1 == strCaption.Find(L"You"))
    return false;
Community
  • 1
  • 1
  • Try this ?: http://stackoverflow.com/questions/5760186/use-cstring-in-console-app-when-using-vs-express – FreudianSlip Dec 24 '12 at 09:16
  • Erm... there would be no `CString` in "C", so that's not rustiness, you're looking at "C++" which is a different language (with similar syntax). – johnsyweb Dec 24 '12 at 09:19
  • I tried the StdString from FruedianSlip, but no luck. I added the StdString.h file to my project, but I still get "cannot open type library file stdstring". Tried #import and #include. It has been a long time for me, frustrating! –  Dec 24 '12 at 09:46
  • CString is a string type for MFC and ATL, major class libraries for Visual Studio. Neither is provided by the Express edition, you only get them when you buy the RTM license. The Express edition is training wheels for writing your own C++ code. – Hans Passant Dec 25 '12 at 00:43

4 Answers4

0

it's ages I'm not using MFC, so I cannot be sure this suggestion will not result in a dead way...

You'll need to compile MFC yourself. Here I found some detailed suggestion. As I said, I can't try just now.

HTH

CapelliC
  • 59,646
  • 5
  • 47
  • 90
0
#include <cwchar>

...

if (std::wcsstr(theCaption, L"You") == 0)
    return false
fizzer
  • 13,551
  • 9
  • 39
  • 61
0

Why not use the basic CRT function?

bool Decoder::decode(LPCWSTR theCaption, TABLE_SUMMARY& table)
{
    if (wcsstr(theCaption, L"You") == NULL)
        return false;
    ...
}

If you need to do it case-insensitive I recommend this wcsistr implementation.

demorge
  • 1,097
  • 1
  • 7
  • 17
0

See WTL that could replace MFC, or, switch to STL, and if you just need to handle CString, you could use (for instance) std::string, adding what's missing from the interface.

I think the most interesting it's the CString automatic conversion to LPCSTR for ANSI programs, or LPCWSTR for Unicode.

I.e. something like

class CString : std::string {
public:

  operator PCSTR() const { return c_str(); }
  operator PCWSTR() const { return c_wstr(); }
};

could solve your immediate problem (untested code...)

Note that such implicit operator allows to pass CString directly to WINAPI.

If you pair that with a smart copy allocation (on write), that MFC implemented (sorry I'm not sure std::string that), you'll appreciate CString.

You will need to implement any of the missing CString member (should be fairly easy if are limited...)

Of course any other MFC reference is a different problem...

CapelliC
  • 59,646
  • 5
  • 47
  • 90