strcmp function

strcmp function

Anonymous
Not applicable
1,584 Views
8 Replies
Message 1 of 9

strcmp function

Anonymous
Not applicable

Hi. I'm updating code from VS 2002 to Vs 2012 for use with objectarx 2015. the following bit of code -

 if ((return_code == RTNORM) && (strcmp (fs_p_info, "Q") == 0))

 

gives me the following compiler error-

error C2664: 'strcmp' : cannot convert parameter 1 from 'TCHAR [6]' to 'const char *'

 

It seems the fix here should be fairly straightforward, however all the help places I've looked at haven't been of much help. So, I give up. Does anyone have any suggestions how to fix the error?

 

Thanks,

 

Brian

 

0 Likes
1,585 Views
8 Replies
Replies (8)
Message 2 of 9

artc2
Autodesk
Autodesk
ObjectARX 2015 works with Unicode, so it uses wchar_t rather than char. For string constants such as your "Q" you'll need to use an L prefix like so L"Q" to tell the compiler the string is a wide char string. And, you'll need to use wcscmp instead of strcmp.
0 Likes
Message 3 of 9

Anonymous
Not applicable

Thanks artc2. Very nice. Unicode. I learned of the Unicode environment early on but not much of how it is used in code. For example I know of the _T convention, and now the L and wcscmp. These worked fine btw. Thanks. What I would really like is an information source that discusses Unicode in the objectarxc 2015 environment. An objectarx unicode search lists plenty of 'functions' but still not clear where they apply, at least in my case. I have some other string problems to solve as well, for example the following code-

 

strcpy (module_entity_assigned_layer, current_module_entity.resval.rstring);

 

Produces the error-

error C2664: 'strcpy' : cannot convert parameter 2 from 'ACHAR *' to 'const char *'

 

I suspect that this is a unicode problem too, but deep in a resbuf (current_module_entity). Perhaps you might enlighten me on where I might find information to solve this one?

 

Brian (aka, manybeans)

 

 

 

 

0 Likes
Message 4 of 9

nick83
Advocate
Advocate

if you want your code works fine for Unicode, you have to:
1. strcpy, strcmp, strstr, strlen, fopen, fprintf, ... MUST be _tcscpy, _tcscmp... (better to use template functions)
2. input, output params MUST be ACHAR or TCHAR, not CHAR
3. if you used cont string, for example strcpy(buf, "testStr") you have to write _tcscpy(buf, _T("testStr"))
4. std::strinng MUST be std::wstring (if you used CString you have to do nothing at all ))) )

5. modify configuration properties for each project you have
5.1. Configuration properties -> General -> Character Set = Use Unicode Character set
5.2. Configuration properties -> C/C++ -> Treat WChar_t As Build in Type = Yes (/Zc:wchar_t)

0 Likes
Message 5 of 9

Anonymous
Not applicable

also, there use to be a tool 'Visual Teefy' via adn, maybe still is avail?

here is some old info topic about unicode that might help:  http://through-the-interface.typepad.com/through_the_interface/2006/07/migrating_code_.html

0 Likes
Message 6 of 9

Anonymous
Not applicable

Thanks Nick83 for enlightening me here. All great info, and indeed is helping me to adjust my code as I move along. It will be some work. My app is 100,000 lines of code, plus some. Thanks again.

 

Brian (aka, manybeans)

0 Likes
Message 7 of 9

Anonymous
Not applicable

Hi LE3. Thank you too for the reference. I found Objectarx 2007 which includes the Unicode migration guide. Very good to have that. I'll give a search at the ADN for visual teefy. Thanks again.

 

Brian (aka, manybeans)

0 Likes
Message 8 of 9

Anonymous
Not applicable

Unicode Issue. as nick83 said, in order to make your code more compatible,you can use TCHAR/ACHAR rather than char or wchar_t, also when encounter the strings, use _T("string") or TEXT("string") rather than L"string", the later may still cause error if you change to ascii environment. finally, all functions that associate with string should use the _t format,like _tcscmp and sor forth. all these methods could help avoiding compile errors when development environment changes.

0 Likes
Message 9 of 9

Anonymous
Not applicable

Hi,

 

As I mentioned some time ago all my unicode issues are done now and my code runs just fine. Thanks for your comments though.

 

I do have one other issue having to do with the linfeed escape sequence  _T("\n"). If you are interested please see my 9/25 post.

 

manybeans

0 Likes