NO

Author Topic: Some problem with the "#define UNICODE" identifier  (Read 3411 times)

sunshine

  • Guest
Some problem with the "#define UNICODE" identifier
« on: May 30, 2011, 04:54:42 AM »
First, I prepared my code like this:

#include <stdio.h>
#define UNICODE
int main() {
return 0;
}

then I built it and checked the "EXE" file with the tool named "PE explorer",
in the import table, I found some API functions like "GetStartupInfoA", "GetCommandLineA","GetModuleFileNameA" and "FreeEnvironmentStringsA".
In my opinion, these functions should have a name end with "W".

If I prepare my code like this:

#include <stdio.h>
#define UNICODE
int main() {
lstrlen(L"Hello!");
return 0;
}

A function named "lstrlenW" will appear in the import table,
but the functions "GetStartupInfoA", "GetCommandLineA", "GetModuleFileNameA" and "FreeEnvironmentStringsA" are still exist.
« Last Edit: May 30, 2011, 04:56:26 AM by sunshine »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: Some problem with the "#define UNICODE" identifier
« Reply #1 on: May 30, 2011, 05:37:31 AM »
From pellesC help -> Appendix -> Program startup: the true story
Quote
When the entry point is main, execution will actually begin in a function called mainCRTStartup
When the entry point is wmain, execution will begin in a function called wmainCRTStartup, but otherwise it is the same process.
#define UNICODE should be before includes.
Code: [Select]
#define UNICODE
#include <stdio.h>
#include <tchar.h>

//int _tmain(int argc, _TCHAR* argv[])
int _tmain(void)
{
return 0;
}

May the source be with you

CommonTater

  • Guest
Re: Some problem with the "#define UNICODE" identifier
« Reply #2 on: May 30, 2011, 06:11:05 AM »
You should also #define _UNICODE for C library functions...

Code: [Select]
#define UNICODE
#define _UNICODE
#include <windows.h>
...


sunshine

  • Guest
Re: Some problem with the "#define UNICODE" identifier
« Reply #3 on: May 30, 2011, 08:01:35 AM »
Code: [Select]
#define UNICODE
#define _UNICODE

#include <stdio.h>
#include <tchar.h>

int _tmain(int argc, _TCHAR* argv[]) {
return 0;
}

This time,only "GetStartupInfoA".

CommonTater

  • Guest
Re: Some problem with the "#define UNICODE" identifier
« Reply #4 on: May 30, 2011, 02:54:44 PM »
Try using ...

Code: [Select]
#define UNICODE
#define _UNICODE
#include <windows.h>
#include <wchar.h>

in wmain (int argc, wchar_t *argv[])
  { ...


See the information about program startup in the help file... it's in the appendix...

If you look at what a console mode startup takes from the function calls you listed you will probably find it really doesn't make any difference to the problem you are running...

GetStartupInfoA... is probably used mostly for the console window title, which doesn't need to be unicode.
GetCommandLine ... is used in preparing argv[] so it should switch...
GetModuleFilename... fetches argv[0] for you, so it should switch
FreeEnvironmentStrings ... is a buried function so it's of no consequence whether it's A or W.

The UNICODE and _UNICODE defines do not change the *entire operating system* back and forth between ansi and unicode for you they simply allow you to use unicode text in system calls from your programs...