8.10 Unicode C Code conversion

Wkunneke

Wkunneke

Active Member
In the process of upgrading to 8.10 and I've got a custom C bsfn that is misbehaving. Before getting too far into this please note that while I have more years of coding experience than I care to admit to, I do NOT consider myself a veteran C coder!

A number of things were changed automatically by the upgrade process that I've found, most of them directly related to changes in double byte, unicode strings. The following line of code:

strncpy (szLetterName, lpDS->szNameObject, sizeof (szLetterName));

was replaced with:

jdeStrncpy (szLetterName, lpDS->szNameObject, DIM (szLetterName));

The changes to strncopy make sense. I can also understand the need for a change to sizeof, but I'm unfamiliar with DIM so I don't understand why it was used as a replacement to the sizeof call. In other languages, DIM tends to be used to actively dimension or size an array. Is it being used to passively get the size of the varchar szLetterName as opposed to SETTING the size of szLetterName? Since this bsfn is not working, this was one line of code changed that I didn't understand, therefore it was something that immediately caught my attention. Thanks in advance,
 
I am glad to see that we are not alone, doing retrofit!

There is an extensive document regarding the Unicode implementation and the new standards. Search the Peoplesoft support site for Unicode Conversion Guidelines.

As for the problem with your business function, look for any "memset" that initialise a structure with a char rather than the usual NULL byte. If initializing with ' ' (space char), use jdeMemset. Failing to do that will initialise the variable with the Dagger character, which is probably not what you want! If initializing with NULL, memset will do just fine.

Also, if you want to debug your BSFN, make sure that you activate Unicode under MS Visual Studio/Tools/Options/Debugger.

The jdeStrncpy function is character based. This means that you need to pass the maximum number of characters to copy.

Assume this:

JCHAR szCharacter[11];
int iSizeof;
int iNumberOfChars;
int iCharSize;


iSizeof = sizeof(szCharacter);
iCharSize = sizeof(szCharacter[0]);
iNumberOfChars = sizeof(szCharacter) / iCharSize;

At the end of the execution, the following would have occured:
iSizeof = 22
iCharSize = 2
iNumberOfChars = 11

So if you wanted to copy a string to szCharacter using jdeStrncpy, you would need to pass the NUMBER OF CHARS and not the NUMBER OF BYTES. You would do the following:

jdeStrncpy(szCharacter, _J('Test'), iNumberOfChars-1);

The '-1' here is just for safety reasons to make sure you are not replacing the NULL TERMINATOR.

Since we all want to have our life simplified, the peoplesoft team defined the DIM for us as followed:

#define DIM(x) (sizeof(x)/sizeof(x[0]))

So we have:

DIM(szCharacter) = sizeof(szCharacter)/sizeof(szCharacter[0]) = 11

Good luck!

Oh, and by the way, if you like this answer, you can rate me :)
 
You are not alone and I will not go quietly into the night without at least some kicking and screaming! Thanks for the heads up on the Unicode Conversion Guidelines, I have a copy and have perused it somewhat. I apologize if I missed a reference to DIM, I really try to exhaust my resources before posting something here.

Your explanation makes perfect sense and definitely clears that up for me. An even bigger thanks on the suggestion to activate Unicode within MS VC.

"Still clearing debris from Hurricane Charley"
 
Oh - and don't forget to 'regenerate' any header files for custom tables... those _J() things are becoming a real pain.

db
 
Thanks Sebastien Leclerc for the amazing explanation.
I used to blindly copy-paste, now I know the reason behind it.
 
There is a tool that will convert C++ into the correct format from an older one.

codechangecom.exe is available from JDE and it tries it's best to convert all the JCHAR type stuff and the commands etc.
It converts the text files over for you

I have added the unicode cookbook. I don't have any docs on codechangecom other than what I made myself.
A little bit more info from a geek I respect very much :)
http://shannonscncjdeblog.blogspot.co.uk/2014_01_01_archive.html
 

Attachments

  • Unicode_Cookbook.doc
    319 KB · Views: 43
Back
Top