Highlighted
Absent Member.
Absent Member.
686 views

[archive] Difference between ansi and unicode

[Migrated content. Thread originally posted on 14 November 2005]

Good Day,

Reading the microsoft web about the api InternetCheckConnection, i see two ways to use it:

move "http://www.microsoft.com" to pagina-web
inspect pagina-web replacing trailing space by null

initialize reserved boolean
move 1 to flags

call "wininet.dll"
call "InternetCheckConnectionA" using
by reference pagina-web
by value flags
by value reserved
giving boolean
cancel "wininet.dll"

if Boolean = 1
perform connected
else
perform not_connected
end-if

That api works, but the same coding calling InternetCheckConnectionW dont works.
In microsoft WEB it says that the difference between the two apis is InternetCheckConnectionA is in ANSI and InternetCheckConnectionW is in UNICODE

then, my question is, what is the difference calling both apis? (im a bit loosed in this subject)

Thank You
0 Likes
6 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] Difference between ansi and unicode

This is a long story...

But basically, when Windows first rolled out, there were nothing but western hemisphere (typically north America and western Europe) characters, Windows where then designed to handle the ANSI character sets only.

As the world moved on, Microsoft realised there was plenty of money outside of the western hemisphere as well. To accomplish this, they realised they would have to support a more extensive character set than ANSI.

The big difference here is of course that these character sets outside of the western hemisphere requires more room, Chinese for instance, is not even close to fit within the 256 bytes enhanced ASCII or ANSI provides. Not to forget that one may as well want to have the capability to mix character sets...

So, extended character sets would require more space.

Extended character set definitions has historically been some of a "fix" proprietary to the hosting platforms. Thus, not portable.

Eventually however, there were an ISO group formed to define a common rule for extended character sets. The results from this group is commonly known as UNICODE. Now, I could write pages about UNICODE, but we will leave that for another time, it is not relevant to your question anyway.

Microsoft of course had to do things their own way, at least to the extent that they gave it their own name; WIDECHAR.

Microsoft was clear that they did not want to build everything from the beginning, besides, there were an established codebade out there, which certainly did not want to reprogram.

So, what Microsoft did, was to duplicate all their API functions in one Ansi and one Widechar version. Thus, the original:


GetComputerName


Split into:

  GetComputerNameA
and
  GetComputerNameW


Mind you, this only applies to functions that handles strings, the GetDC function for instance appears in only one version, because it does only handle numbers. Numbers are universal.

What is then the difference of these?

The Ansi version take one byte per character and has a string terminated by one ascii 0.

The UNICODE version on the other side *may* take anything between 1 byte per character and up 6 bytes per character. Also, terminating a UNICODE string requires two ascii 00.
Top this with the fact that the UNICODE string may as well have a prefix identifying what version of UNICODE you use.

Yes, there are multiple versions of UNICODE; UTF-8, UTF-16 and UTF-32. But that is another story as well.

As for ACUCOBOL-GT and Windows, you will use the 'A' version of the functions, GetComputerNameA.

It is however possible to access Widechar versions as well, but then following certain rules, doing some twist and tricks. There is an example of how to do this, a program that illustrates how to enumerate open files on a server and possibly enforce a closing on them.

Hope this was the answer you were looking for.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Difference between ansi and unicode

Yeah, i was using InternetConnectionCheckA, but yesterday, i get a memory access violation in that api in a computer with Windows 98, and testing with InternetConnectionCheckW dont get the memory access violation (maybe only because i dont using it correctly and then dont do anything to get memory violation, but need to test it).

Can you tell me where i can find that program to see the tricks?

Thank you
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Difference between ansi and unicode

You are most likely not using it correctly.
In fact, I cannot find any documentation on it. Without documentation, you should not use it.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Difference between ansi and unicode

Originally posted by gforseth
There is an example of how to do this, a program that illustrates how to enumerate open files on a server and possibly enforce a closing on them.


Dont know where i can get that example?

Thank you
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Difference between ansi and unicode

It is around here somewhere, but here is a copy too.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Difference between ansi and unicode

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.