Skip to content

Commit ef8ae3f

Browse files
Merge 4ded318 into 7b4dedb
2 parents 7b4dedb + 4ded318 commit ef8ae3f

File tree

16 files changed

+513
-717
lines changed

16 files changed

+513
-717
lines changed

platforms/win32/plugins/DropPlugin/sqWin32Drop.c

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -212,19 +212,26 @@ HANDLE DibFromBitmap (
212212
}
213213

214214
BOOL WriteDIB (
215-
LPSTR szFile,
215+
LPCWSTR szFile,
216216
HANDLE hdib)
217217
{
218218
BITMAPFILEHEADER hdr;
219219
LPBITMAPINFOHEADER lpbi;
220-
HFILE fh;
221-
OFSTRUCT of;
220+
HANDLE fh;
221+
DWORD nbwritten;
222222

223223
if (!hdib)
224224
return FALSE;
225225

226-
fh = OpenFile(szFile, &of, (UINT)OF_CREATE|OF_READWRITE);
227-
if (fh == -1)
226+
fh = CreateFileW(szFile,
227+
(GENERIC_READ | GENERIC_WRITE) ,
228+
FILE_SHARE_READ ,
229+
NULL, /* No security descriptor */
230+
OPEN_ALWAYS ,
231+
FILE_ATTRIBUTE_NORMAL,
232+
NULL /* No template */);
233+
234+
if (fh == INVALID_HANDLE_VALUE)
228235
return FALSE;
229236

230237
lpbi = (VOID FAR *)GlobalLock (hdib);
@@ -240,16 +247,16 @@ BOOL WriteDIB (
240247
/* Write the file header */
241248

242249
/* write bfType*/
243-
_lwrite(fh, (LPSTR)&hdr.bfType, (UINT)sizeof (WORD));
250+
WriteFile(fh, (LPSTR)&hdr.bfType, (UINT)sizeof (WORD),&nbwritten,NULL);
244251
/* now pass over extra word, and only write next 3 DWORDS!*/
245-
_lwrite(fh, (LPSTR)&hdr.bfSize, sizeof(DWORD) * 3);
252+
WriteFile(fh, (LPSTR)&hdr.bfSize, sizeof(DWORD) * 3, &nbwritten, NULL);
246253

247254
/* this struct already DWORD aligned!*/
248255
/* Write the DIB header and the bits */
249-
_lwrite (fh, (LPSTR)lpbi, GlobalSize (hdib));
256+
WriteFile(fh, (LPSTR)lpbi, GlobalSize (hdib), &nbwritten, NULL);
250257

251258
GlobalUnlock (hdib);
252-
_lclose(fh);
259+
CloseHandle(fh);
253260
return TRUE;
254261
}
255262

@@ -509,7 +516,7 @@ STDMETHODIMP DropTarget_Drop(DropTarget *dt,
509516
DWORD i;
510517

511518
DPRINTF(("Success\n"));
512-
numDropFiles = DragQueryFile(hDrop, -1, NULL, 0);
519+
numDropFiles = DragQueryFileW(hDrop, -1, NULL, 0);
513520
dropFiles = calloc(numDropFiles, sizeof(char*));
514521
for(i=0; i<numDropFiles; i++) {
515522
WCHAR *tmpPath;
@@ -546,17 +553,20 @@ STDMETHODIMP DropTarget_Drop(DropTarget *dt,
546553

547554
hRes = ido->lpVtbl->GetData(ido, &fmtetc, &medium);
548555
if(hRes == S_OK) {
549-
TCHAR tmpName[MAX_PATH+1];
556+
WCHAR tmpNameW[MAX_PATH+1];
550557
HANDLE hDib = medium.hGlobal;
551558

552559
DPRINTF(("Success\n"));
553560

554-
GetTempPath(MAX_PATH,tmpName);
555-
strcat(tmpName,"$$squeak$$.bmp");
556-
if(WriteDIB(tmpName, hDib)) {
557-
numDropFiles = 1;
558-
dropFiles = calloc(1, sizeof(void*));
559-
dropFiles[0] = _strdup(tmpName);
561+
GetTempPathW(MAX_PATH,tmpNameW);
562+
wcscat(tmpNameW,L"$$squeak$$.bmp");
563+
if(WriteDIB(tmpNameW, hDib)) {
564+
char tmpNameA[MAX_PATH_UTF8 + 1];
565+
if(WideCharToMultiByte(CP_UTF8, 0, tmpNameW, -1, tmpNameA, MAX_PATH_UTF8, NULL, NULL)) {
566+
numDropFiles = 1;
567+
dropFiles = calloc(1, sizeof(void*));
568+
dropFiles[0] = _strdup(tmpNameA);
569+
}
560570
}
561571
if(medium.pUnkForRelease == NULL) {
562572
GlobalFree(hDib);
@@ -580,20 +590,23 @@ STDMETHODIMP DropTarget_Drop(DropTarget *dt,
580590

581591
hRes = ido->lpVtbl->GetData(ido, &fmtetc, &medium);
582592
if(hRes == S_OK) {
583-
TCHAR tmpName[MAX_PATH+1];
593+
WCHAR tmpNameW[MAX_PATH+1];
584594
HANDLE hDib;
585595
HBITMAP hBM = medium.hBitmap;
586596

587597
DPRINTF(("Success\n"));
588598

589-
GetTempPath(MAX_PATH,tmpName);
590-
strcat(tmpName,"$$squeak$$.bmp");
599+
GetTempPathW(MAX_PATH,tmpNameW);
600+
wcscat(tmpNameW,L"$$squeak$$.bmp");
591601
hDib = DibFromBitmap(hBM, BI_RGB, 0, NULL);
592602
if(hDib) {
593-
if(WriteDIB(tmpName, hDib)) {
594-
numDropFiles = 1;
595-
dropFiles = calloc(1, sizeof(void*));
596-
dropFiles[0] = _strdup(tmpName);
603+
if(WriteDIB(tmpNameW, hDib)) {
604+
char tmpNameA[MAX_PATH_UTF8 + 1];
605+
if (WideCharToMultiByte(CP_UTF8, 0, tmpNameW, -1, tmpNameA, MAX_PATH_UTF8, NULL, NULL)) {
606+
numDropFiles = 1;
607+
dropFiles = calloc(1, sizeof(void*));
608+
dropFiles[0] = _strdup(tmpNameA);
609+
}
597610
}
598611
DeleteObject(hDib);
599612
}
@@ -618,7 +631,7 @@ STDMETHODIMP DropTarget_Drop(DropTarget *dt,
618631

619632
hRes = ido->lpVtbl->GetData(ido, &fmtetc, &medium);
620633
if(hRes == S_OK) {
621-
TCHAR tmpName[MAX_PATH+1];
634+
WCHAR tmpNameW[MAX_PATH+1];
622635
HANDLE hMF = medium.hGlobal;
623636
HANDLE hDib;
624637
BITMAPINFO bmi;
@@ -661,12 +674,15 @@ STDMETHODIMP DropTarget_Drop(DropTarget *dt,
661674
DeleteObject(hBM);
662675
}
663676

664-
GetTempPath(MAX_PATH,tmpName);
665-
strcat(tmpName,"$$squeak$$.bmp");
666-
if(WriteDIB(tmpName, hDib)) {
667-
numDropFiles = 1;
668-
dropFiles = calloc(1, sizeof(void*));
669-
dropFiles[0] = _strdup(tmpName);
677+
GetTempPathW(MAX_PATH,tmpNameW);
678+
wcscat(tmpNameW,L"$$squeak$$.bmp");
679+
if(WriteDIB(tmpNameW, hDib)) {
680+
char tmpNameA[MAX_PATH_UTF8 + 1];
681+
if (WideCharToMultiByte(CP_UTF8, 0, tmpNameW, -1, tmpNameA, MAX_PATH_UTF8, NULL, NULL)) {
682+
numDropFiles = 1;
683+
dropFiles = calloc(1, sizeof(void*));
684+
dropFiles[0] = _strdup(tmpNameA);
685+
}
670686
}
671687
GlobalFree(hDib);
672688
if(medium.pUnkForRelease == NULL) {

platforms/win32/plugins/FilePlugin/sqWin32FilePrims.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ size_t sqImageFileRead(void *ptr, size_t sz, size_t count, sqImageFile h)
517517
ReadFile((HANDLE)(h-1), (LPVOID) ptr, count*sz, &dwReallyRead, NULL);
518518
while(dwReallyRead != (DWORD)(count*sz)) {
519519
DWORD err = GetLastError();
520-
if(sqMessageBox(MB_ABORTRETRYIGNORE, TEXT("Squeak Warning"),"Image file read problem (%d out of %d bytes read)", dwReallyRead, count*sz)
520+
if(sqMessageBox(MB_ABORTRETRYIGNORE, TEXT("Squeak Warning"),TEXT("Image file read problem (%d out of %d bytes read)"), dwReallyRead, count*sz)
521521
== IDABORT) return (dwReallyRead / sz);
522522
sqImageFileSeek(h, position);
523523
ReadFile((HANDLE)(h-1), (LPVOID) ptr, count*sz, &dwReallyRead, NULL);

platforms/win32/plugins/HostWindowPlugin/sqWin32HostWindowPlugin.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,12 +415,17 @@ sqInt ioSetTitleOfWindow(sqInt windowIndex, char * newTitle, sqInt sizeOfTitle)
415415
* int size of new logo path. If one of the function is failing, the logo is not set.
416416
*/
417417
sqInt ioSetIconOfWindow(sqInt windowIndex, char * iconPath, sqInt sizeOfPath) {
418+
WCHAR iconPathW[MAX_PATH + 1];
418419
HWND hwnd = (windowIndex == 1 ? stWindow : ((HWND)windowIndex));
420+
int len;
419421
if (!IsWindow(hwnd)) return 0;
422+
len = MultiByteToWideChar(CP_UTF8, 0, iconPath, sizeOfPath, iconPathW, MAX_PATH);
423+
if(len <= 0) return -1; /* invalid UTF8 ? */
424+
iconPathW[len] = 0;
420425
//Check if file exists and have read rights
421-
if (access(iconPath, 4) == -1) { return -1; };
426+
if (_waccess(iconPath, 4) == -1) { return -1; };
422427
//Load the image into an icon
423-
HICON hIcon = (HICON)LoadImage(NULL, iconPath, IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
428+
HICON hIcon = (HICON)LoadImageW(NULL, iconPathW, IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
424429
if (hIcon == 0)
425430
return -2;
426431
SendMessage(hwnd, WM_SETICON, ICON_BIG, (LONG_PTR)hIcon);

platforms/win32/plugins/SocketPlugin/sqWin32NewNet.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,7 +2179,7 @@ void sqResolverGetAddressInfoHostSizeServiceSizeFlagsFamilyTypeProtocol(char *ho
21792179

21802180
if (gaiError)
21812181
{
2182-
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(gaiError));
2182+
fwprintf(stderr, L"getaddrinfo: %s\n", gai_strerrorW(gaiError));
21832183
addrList= 0; /* succeed with zero results for impossible constraints */
21842184
}
21852185

@@ -2349,7 +2349,7 @@ void sqResolverGetNameInfoSizeFlags(char *addr, sqInt addrSize, sqInt flags)
23492349

23502350
if (gaiError)
23512351
{
2352-
fprintf(stderr, "getnameinfo: %s\n", gai_strerror(gaiError));
2352+
fwprintf(stderr, L"getnameinfo: %s\n", gai_strerrorW(gaiError));
23532353
lastError= gaiError;
23542354
goto fail;
23552355
}

platforms/win32/vm/sqPlatformSpecific.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#ifdef WIN32_FILE_SUPPORT
3232

33+
#define NO_STD_FILE_SUPPORT /* STD_FILE or WIN32_FILE are mutually exclusive options */
3334
#undef sqImageFile
3435
#undef sqImageFileClose
3536
#undef sqImageFileOpen

platforms/win32/vm/sqWin32.h

Lines changed: 37 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
/* Definition for Intel Processors */
105105
#if defined(_M_IX86) || defined(i386)
106106
# define WIN32_NAME "Win32"
107-
# define WIN32_OS_NAME (fWindows95 ? "95" : "NT")
107+
# define WIN32_OS_NAME "NT"
108108
# define WIN32_PROCESSOR_NAME "IX86"
109109

110110
# if defined(X86)
@@ -143,16 +143,6 @@
143143

144144
#endif /* (_WIN32_WCE) */
145145

146-
/* THE FOLLOWING IS WRONG (& HENCE I'VE IF 0'ed IT OUT. WE CAN'T MERELY DEFINE
147-
* WIN32 BECAUSE WE MAY BE ON WIN64. eem 2017/05/16
148-
*/
149-
#if 0
150-
/* due to weird include orders, make sure WIN32 is defined */
151-
# if !defined(WIN32)
152-
# define WIN32 1
153-
# endif
154-
#endif
155-
156146
/* Experimental */
157147
#ifdef MINIMAL
158148
/* The hardcoded defs:
@@ -189,7 +179,6 @@ void SetupKeymap();
189179
void SetupWindows();
190180
void SetupPixmaps();
191181
void SetupPrinter();
192-
void SetupPreferences();
193182
void SetupMIDI();
194183

195184
/********************************************************/
@@ -259,21 +248,46 @@ int reverse_image_words(unsigned int *dst, unsigned int *src,int depth, int widt
259248
/********************************************************/
260249
/* Declarations we may need by other modules */
261250
/********************************************************/
262-
extern char imageName[]; /* full path and name to image */
263-
extern TCHAR imagePath[]; /* full path to image */
264-
extern TCHAR vmPath[]; /* full path to interpreter's directory */
265-
extern TCHAR vmName[]; /* name of the interpreter's executable */
266-
extern char windowTitle[]; /* window title string */
267-
extern char vmBuildString[]; /* the vm build string */
268-
extern TCHAR windowClassName[]; /* class name for the window */
251+
252+
/* Note: a character can require up to 4 bytes in UTF8 encoding
253+
But the expansion from UTF16 -> UTF8 is never more than 3 bytes for 1 short
254+
U+ 0000-U+ 007F - 1byte in utf8, 1 short in utf16.
255+
U+ 0080-U+ 07FF - 2byte in utf8, 1 short in utf16.
256+
U+ 0800-U+ FFFF - 3byte in utf8, 1 short in utf16.
257+
U+10000-U+10FFFF - 4byte in utf8, 2 short in utf16.
258+
*/
259+
#define MAX_PATH_UTF8 (MAX_PATH*3)
260+
261+
extern char imageName []; /* full path and name to image - UTF8 */
262+
extern WCHAR imageNameW[]; /* full path and name to image - UTF16 */
263+
extern char imagePathA[]; /* full path to image - UTF8 */
264+
extern WCHAR imagePathW[]; /* full path to image - UTF16 */
265+
extern char vmPathA[]; /* full path to interpreter's directory - UTF8 */
266+
extern WCHAR vmPathW[]; /* full path to interpreter's directory - UTF16 */
267+
extern char vmNameA[]; /* name of the interpreter's executable - UTF8 */
268+
extern WCHAR vmNameW[]; /* name of the interpreter's executable - UTF16 */
269+
extern char windowTitle[]; /* window title string - UTF8 */
270+
extern char vmBuildString[]; /* the vm build string */
271+
extern TCHAR windowClassName[]; /* class name for the window */
272+
273+
#ifdef UNICODE
274+
#define imageNameT imageNameW /* define the generic TCHAR* version */
275+
#define imagePath imagePathW
276+
#define vmName vmNameW
277+
#define vmPath vmPathW
278+
#else
279+
#define imageNameT imageName
280+
#define imagePath imagePathA
281+
#define vmName vmNameA
282+
#define vmPath vmPathA
283+
#endif
269284

270285
extern UINT SQ_LAUNCH_DROP;
271286

272287
extern const TCHAR U_ON[];
273288
extern const TCHAR U_OFF[];
274289
extern const TCHAR U_GLOBAL[];
275-
extern const TCHAR U_SLASH[];
276-
extern const TCHAR U_BACKSLASH[];
290+
extern const WCHAR W_BACKSLASH[];
277291

278292
#ifndef NO_PREFERENCES
279293
extern HMENU vmPrefsMenu; /* preferences menu */
@@ -293,7 +307,6 @@ extern BITMAPINFO *bmi4; /* 4 bit depth bitmap info */
293307
extern BITMAPINFO *bmi8; /* 8 bit depth bitmap info */
294308
extern BITMAPINFO *bmi16; /* 16 bit depth bitmap info */
295309
extern BITMAPINFO *bmi32; /* 32 bit depth bitmap info */
296-
extern BOOL fWindows95; /* Are we running on Win95 or NT? */
297310
extern BOOL fIsConsole; /* Are we running as a console app? */
298311

299312
/* Startup options */
@@ -332,32 +345,11 @@ extern BOOL f3ButtonMouse; /* Should we use a real 3 button mouse mapping? */
332345
extern BOOL fBufferMouse; /* Should we buffer mouse input? */
333346

334347

335-
/******************************************************/
336-
/* String conversions between Unicode / Ansi / Squeak */
337-
/******************************************************/
338-
/* Note: fromSqueak() and fromSqueak2() are inline conversions
339-
but operate on two different buffers. The maximum length
340-
of strings that can be converted is MAX_PATH */
341-
TCHAR* fromSqueak(const char *sqPtr, int sqLen); /* Inline Squeak -> C */
342-
TCHAR* fromSqueak2(const char *sqPtr, int sqLen); /* 2nd inline conversion */
343-
/* Note: toUnicode() and fromUnicode() are inline conversions
344-
with for at most MAX_PATH sized strings. If the VM
345-
is not compiled with UNICODE defined they just return
346-
the input strings. Also, toUnicode operates on the
347-
same buffer as fromSqueak() */
348-
TCHAR* toUnicode(const char *ptr); /* Inline Ansi -> Unicode */
349-
char* fromUnicode(const TCHAR *ptr); /* Inline Unicode -> Ansi */
350-
/* Note: toUnicodeNew and fromUnicodeNew malloc() new strings.
351-
It is up to the caller to free these! */
352-
TCHAR* toUnicodeNew(const char *ptr); /* Inline Ansi -> Unicode */
353-
char* fromUnicodeNew(const TCHAR *ptr); /* Inline Unicode -> Ansi */
354-
TCHAR *lstrrchr(TCHAR *source, TCHAR c);
355-
356348
/******************************************************/
357349
/* Output stuff */
358350
/******************************************************/
359351
#ifndef sqMessageBox
360-
int __cdecl sqMessageBox(DWORD dwFlags, const TCHAR *titleString, const char* fmt, ...);
352+
int __cdecl sqMessageBox(DWORD dwFlags, const TCHAR *titleString, const TCHAR* fmt, ...);
361353
#endif
362354

363355
#ifndef warnPrintf
@@ -380,7 +372,7 @@ void vprintLastError(TCHAR *fmt, ...);
380372
/******************************************************/
381373
/* Misc functions */
382374
/******************************************************/
383-
DWORD SqueakImageLength(TCHAR *fileName);
375+
DWORD SqueakImageLength(WCHAR *fileName);
384376
int isLocalFileName(TCHAR *fileName);
385377

386378
#ifndef NO_PLUGIN_SUPPORT

platforms/win32/vm/sqWin32Alloc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ void *sqAllocateMemory(usqInt minHeapSize, usqInt desiredHeapSize)
7676
} while(!pageBase);
7777
if(!pageBase) {
7878
sqMessageBox(MB_OK | MB_ICONSTOP, TEXT("VM Error:"),
79-
"Unable to allocate memory (%d bytes requested)",
79+
TEXT("Unable to allocate memory (%d bytes requested)"),
8080
maxReserved);
8181
return pageBase;
8282
}
8383
/* commit initial memory as requested */
8484
commit = nowReserved;
8585
if(!VirtualAlloc(pageBase, commit, MEM_COMMIT, PAGE_READWRITE)) {
8686
sqMessageBox(MB_OK | MB_ICONSTOP, TEXT("VM Error:"),
87-
"Unable to commit memory (%d bytes requested)",
87+
TEXT("Unable to commit memory (%d bytes requested)"),
8888
commit);
8989
return NULL;
9090
}

0 commit comments

Comments
 (0)