2

Currently I am working on an old VB6 app to be compatible with UNICODE.

This app has SSTab and within this tab, there are user control q1, q2, q3 and so on.
For q1, it has the following code:

Private WithEvents q1 As VBControlExtender
Private progID As String

procId = “ALCTX10.CTX10.1”
Set q1 = Controls.Add(procId, “q1”)
myTab.tab = 1 
q1.Move borderSize, topMargin, myTab.Width - borderSize * 2, _ 
myTab.Height - borderSize - topMargin 
q1.Visible = True

The procId is referring to VC++ 6 DLL. All user controls are using this DLL.
For VC++ 6 DLL, I added ",_UNICODE, UNICODE" into the preprocessor definitions under the project setting of VC++ 6. And compiled the DLL again and then brought it back to VB6.

The problem is I am still getting the same UNICODE issue from VB6 app. I am using a foreign version of Windows XP so it is not the font problem. I can’t just replace this DLL with UNICODE supported TextBox or RichTextBox since there are too many things going underneath the DLL.

I would appreciate very much if anyone sheds a light on this problem. Thanks.

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
  • 2
    VB6 is Unicode internally. COM is Unicode. But the OS that VB6 was designed for is ANSI. So VB6 translate all dll calls to ANSI. All windows are ANSI windows. – Lundt Oct 28 '22 at 06:55
  • VB6 TextBox is ANSI but there is a custom TextBox which is UNICODE. Similarly, could there be a solution to make VB6 to recognize this DLL to be UNICODE? – user3239379 Oct 28 '22 at 07:34
  • 1
    See posting #3 by Bonnie West [here](https://www.vbforums.com/showthread.php?812577-RESOLVED-Problem-with-Standard-DLL) for how to "trick" VB6 into passing UNICODE strings to a native DLL. – Hel O'Ween Oct 28 '22 at 08:14
  • Anything that comes from Windows, like a key press, will most likely be changed to ANSI because the form is ANSI. Anything from COM will stay Unicode. If you are calling API calls you call the `W` version and instead of a string (which will be converted to ANSI) you pass a byte array (and in API calls you pass the first elemment. **So it depends on what you are doing**. – Lundt Oct 28 '22 at 08:31
  • `A() = "MyUnicodeByteArray"` You pass `A(0)` and make sure there is a vbnull at the end. – Lundt Oct 28 '22 at 09:19
  • It seems that someone else has already done this. Then could there be any sample code that I can download and test it? – user3239379 Oct 28 '22 at 09:28
  • I have a VB6 text editor that creates Unicode RTF child window, but it doesn't work right. I ported the code to VB.NET (while VB.NET tries to be C#, it understands VBA syntax). Now it does Unicode correctly. – Lundt Oct 28 '22 at 09:38
  • Here is a VB.NET program written in VB6 syntax that is unicode - https://1drv.ms/u/s!AvqkaKIXzvDihXvpwkLf7OWT2VWi?e=hwsfLw It doesn't save or open fles yet – Lundt Oct 28 '22 at 09:46
  • I have to stick with VB6 and I would like to know more about how to trick VB6 into passing UNICODE strings to a DLL. – user3239379 Oct 28 '22 at 10:06
  • 1
    The first concept that it has nothing to do with DLLs but with windows that are created. – Lundt Oct 28 '22 at 10:33
  • Does this answer your question? [What's the best option to display Unicode text (hebrew, etc.) in VB6](https://stackoverflow.com/questions/540361/whats-the-best-option-to-display-unicode-text-hebrew-etc-in-vb6) – GSerg Oct 31 '22 at 12:49
  • Does this answer your question? [How can I make support Unicode characters in whole my VB 6.0 application](https://stackoverflow.com/q/18361499/11683) – GSerg Oct 31 '22 at 12:49
  • *If you register the window class using the ANSI version of RegisterClassEx, RegisterClassExA, the application requests that the system pass text parameters of messages to the windows of the created class using the ANSI character set; if you register the class using the Unicode version of RegisterClassEx, RegisterClassExW, the application requests that the system pass text parameters of messages to the windows of the created class using the Unicode character set. The IsWindowUnicode function enables applications to query the nature of each window.* – Lundt Nov 02 '22 at 03:25
  • *For more information on ANSI and Unicode functions, see Conventions for Function Prototypes.* https://learn.microsoft.com/en-us/windows/win32/winmsg/about-window-classes. – Lundt Nov 02 '22 at 03:26
  • So controls and main windows send each other messages or notifications. Anything from or to the main windows will be Unicode converted to ANSI. As I showed you in the Basic example you need to dump the VB6 forms package entirely and follow the example code (which is VBA/VB6 ported to VB.NET - so extra brackets and no `set` keyword) and create your own main Window that is Unicode. Also as I said you need to pass the first byte in a byte array instead of a string - `MyByteArrayString(0)` instead of `MyString`. – Lundt Nov 02 '22 at 03:26
  • If I upgrade my VB6 app to .NET, will the unicode issue be eliminated automatically? Or should I still do something on it? – user3239379 Nov 05 '22 at 01:19
  • Pretty much it will be. I don't know your whole codebase, but if you aren't calling API calls it should be automatic. – Lundt Nov 12 '22 at 07:51

0 Answers0