Re: DeleteFile shows as DeleteFileA
Giovanni Dicanio wrote:
"Goran" <goran.pusic@gmail.com> ha scritto nel messaggio
news:3d8eb75b-8d6f-4036-b3c0-2ee0b0f80dbe@u34g2000yqu.googlegroups.com...
Passing that UTF-8 string to DeleteFile (that is, "A" version will be
picked by the compiler) is quite likely to lead to trouble, and a +/-
subtle one (system presumes "ANSI" encoding, whereas string passed in
ain't that). So, conversion from UTF-8 to corresponding code page is
both restrictive and necessary.
So even if UTF-8 is used, it's better to define (_)UNICODE and to make
it a habit to go to UTF-16 before going to Win32.
Very good point, Goran!
Giovanni
BTW I really need to better learn this UNICODE crap. :)
Not sure if its related, maybe Goran to provide insight, I seem to
recall the need to use some OEM function in an old piece of code
related to this, I think, let me check..... Yeah...
SetFileApisToOem()
Back in 1999, I forget the details, but we had to use it for an
console utility to help prepare finish the installation upgrade of a
locked file using the reboot procedure; MoveFileEx() for NT based
systems or preparing the wininit.ini.
Here is the C code I had, again, I don't recall the specifics why it
was needed. It might have been because we needed to make sure it
worked for Win95 as well.
// file: sysmove.cpp
#include <stdio.h>
#include <windows.h>
int main(int argc, char *argv[])
{
char src[MAX_PATH] = {0};
char tar[MAX_PATH] = {0};
if (argc < 3) {
printf("SysMove v1.1 (c)1999 Santronics Software Inc\n");
printf("Prepares a system file for replace upon reboot.\n");
printf("usage> sysmove sourcefile targetfile\n");
return 1;
}
if (argc > 1) strncpy(src,argv[1], sizeof(src)-1);
if (argc > 2) strncpy(tar,argv[2], sizeof(tar)-1);
SetFileApisToOEM();
OSVERSIONINFO osv = {0};
osv.dwOSVersionInfoSize = sizeof(osv);
GetVersionEx(&osv);
if (osv.dwPlatformId == VER_PLATFORM_WIN32_NT) {
printf("* Windows NT-based system\n");
if (!MoveFileEx(src,tar,
MOVEFILE_DELAY_UNTIL_REBOOT |
MOVEFILE_REPLACE_EXISTING)) {
printf("! MoveFileEx error %d\n", GetLastError());
return 1;
}
}
else { // assume Win95
printf("* Windows 95\n");
if (!WritePrivateProfileString("rename",src,tar,"wininit.ini")) {
printf("! error %d - wininit.ini\n", GetLastError());
return 1;
}
}
printf("! Successful System File Move Preparation. Now reboot.");
return 0;
}
--
HLS