source: trunk/src/kernel32/heapstring.cpp@ 1212

Last change on this file since 1212 was 1131, checked in by sandervl, 26 years ago

version fixes, resource lookup change + lstrcmpniW added

File size: 23.6 KB
Line 
1/* $Id: heapstring.cpp,v 1.13 1999-10-04 20:52:33 sandervl Exp $ */
2
3/*
4 * Project Odin Software License can be found in LICENSE.TXT
5 *
6 * Win32 compatibility string functions for OS/2
7 *
8 * Copyright 1999 Patrick Haller
9 */
10
11/*****************************************************************************
12 * Includes *
13 *****************************************************************************/
14
15#include <os2win.h>
16#include <stdlib.h>
17#include <string.h>
18#include <winnls.h>
19#include <unicode.h>
20#include <ctype.h>
21#include <wcstr.h>
22#include "heap.h"
23#include <heapstring.h>
24#include "misc.h"
25
26
27/*****************************************************************************
28 * Defines *
29 *****************************************************************************/
30
31
32/*****************************************************************************
33 * Name :
34 * Purpose :
35 * Parameters:
36 * Variables :
37 * Result :
38 * Remark :
39 * Status :
40 *
41 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
42 *****************************************************************************/
43
44static UconvObject uconv_object = NULL;
45
46static BOOL getUconvObject( void )
47{
48 int rc;
49 BOOL ret;
50
51 if ( uconv_object )
52 ret = TRUE;
53 else
54 {
55 rc = UniCreateUconvObject( (UniChar*)L"",
56 &uconv_object );
57 if ( rc == ULS_SUCCESS )
58 ret = TRUE;
59 else
60 {
61 uconv_object = NULL; // to make sure
62 return FALSE;
63 }
64 dprintf(("KERNEL32: HeapString: UniCreateUconvObject(%d)\n",
65 rc));
66 }
67 return ret;
68}
69
70
71/*****************************************************************************
72 * Name :
73 * Purpose :
74 * Parameters:
75 * Variables :
76 * Result :
77 * Remark :
78 * Status :
79 *
80 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
81 *****************************************************************************/
82
83int WIN32API lstrlenA(LPCSTR arg1)
84{
85 dprintf(("KERNEL32: lstrlenA(%s)\n",
86 arg1));
87
88 return O32_lstrlen(arg1);
89}
90
91
92/*****************************************************************************
93 * Name :
94 * Purpose :
95 * Parameters:
96 * Variables :
97 * Result :
98 * Remark :
99 * Status :
100 *
101 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
102 *****************************************************************************/
103
104int WIN32API lstrlenW(LPCWSTR arg1)
105{
106 int rc;
107
108 rc = UniStrlen( (UniChar*)arg1);
109 dprintf(("KERNEL32: lstrlenW(%08xh) returns %d\n",
110 arg1,
111 rc));
112 return rc;
113}
114
115
116/*****************************************************************************
117 * Name :
118 * Purpose :
119 * Parameters:
120 * Variables :
121 * Result :
122 * Remark :
123 * Status :
124 *
125 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
126 *****************************************************************************/
127
128LPSTR WIN32API lstrcatA(LPSTR arg1, LPCSTR arg2)
129{
130 dprintf(("KERNEL32: lstrcat(%s,%s)\n",
131 arg1,
132 arg2));
133
134 return O32_lstrcat(arg1, arg2);
135}
136
137
138/*****************************************************************************
139 * Name :
140 * Purpose :
141 * Parameters:
142 * Variables :
143 * Result :
144 * Remark :
145 * Status :
146 *
147 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
148 *****************************************************************************/
149
150LPWSTR WIN32API lstrcatW(LPWSTR arg1, LPCWSTR arg2)
151{
152 dprintf(("KERNEL32: OS2lstrcatW(%08xh,%08xh)\n",
153 arg1,
154 arg2));
155
156 UniStrcat( (UniChar*) arg1, (UniChar*) arg2 );
157 return arg1;
158}
159
160
161/*****************************************************************************
162 * Name :
163 * Purpose :
164 * Parameters:
165 * Variables :
166 * Result :
167 * Remark :
168 * Status :
169 *
170 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
171 *****************************************************************************/
172
173int WIN32API lstrcmpA(LPCSTR arg1, LPCSTR arg2)
174{
175 dprintf(("KERNEL32: OS2lstrcmpA(%s,%s)\n",
176 arg1,
177 arg2));
178
179 return O32_lstrcmp(arg1, arg2);
180}
181
182
183/*****************************************************************************
184 * Name :
185 * Purpose :
186 * Parameters:
187 * Variables :
188 * Result :
189 * Remark :
190 * Status :
191 *
192 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
193 *****************************************************************************/
194
195int WIN32API lstrncmpA(LPCSTR arg1, LPCSTR arg2, int l)
196{
197 dprintf(("KERNEL32: OS2lstrncmpA(%s,%s,%d)\n",
198 arg1,
199 arg2,
200 l));
201
202 return strncmp(arg1, arg2, l);
203}
204
205/*****************************************************************************
206 * Name : lstrncmpiA
207 * Purpose :
208 * Parameters:
209 * Variables :
210 * Result :
211 * Remark :
212 * Status :
213 *
214 * Author : Przemyslaw Dobrowolski
215 *****************************************************************************/
216INT WINAPI lstrncmpiA( LPCSTR str1, LPCSTR str2, INT n )
217{
218 INT firstch,lastch;
219 INT result = 0;
220
221 if (n)
222 {
223 do
224 {
225 firstch = tolower(*str1);
226 lastch = tolower(*str2);
227 str1++;
228 str2++;
229 } while (--n && str1 && str2 && firstch == lastch);
230
231 result = firstch - lastch;
232 }
233
234 return(result);
235}
236//TODO: Don't know if this is completely correct
237int WIN32API lstrncmpiW(LPCWSTR str1, LPCWSTR str2, int n)
238{
239 INT firstch,lastch;
240 INT result = 0;
241
242 if (n)
243 {
244 do
245 {
246 firstch = tolower((char)*str1);
247 lastch = tolower((char)*str2);
248 str1++;
249 str2++;
250 } while (--n && str1 && str2 && firstch == lastch);
251
252 result = firstch - lastch;
253 }
254
255 return(result);
256}
257
258/*****************************************************************************
259 * Name :
260 * Purpose :
261 * Parameters:
262 * Variables :
263 * Result :
264 * Remark :
265 * Status :
266 *
267 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
268 *****************************************************************************/
269
270int WIN32API lstrcmpW(LPCWSTR arg1, LPCWSTR arg2)
271{
272 dprintf(("KERNEL32: lstrcmpW (%08xh-%ls, %08xh-%ls)\n",
273 arg1,
274 arg1,
275 arg2,
276 arg2));
277// return UniStrcmp( (UniChar*)arg1,
278// (UniChar*)arg2 );
279 return wcscmp( (wchar_t*)arg1,
280 (wchar_t*)arg2 );
281}
282
283
284/*****************************************************************************
285 * Name :
286 * Purpose :
287 * Parameters:
288 * Variables :
289 * Result :
290 * Remark :
291 * Status :
292 *
293 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
294 *****************************************************************************/
295
296int WIN32API lstrncmpW(LPCWSTR arg1, LPCWSTR arg2, int l)
297{
298 dprintf(("KERNEL32: OS2lstrncmpW(%08xh,%08xh,%d)\n",
299 arg1,
300 arg2,
301 l));
302
303 return wcsncmp((wchar_t*)arg1,
304 (wchar_t*)arg2,
305 l);
306}
307
308/*****************************************************************************
309 * Name :
310 * Purpose :
311 * Parameters:
312 * Variables :
313 * Result :
314 * Remark :
315 * Status :
316 *
317 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
318 *****************************************************************************/
319
320LPSTR WIN32API lstrcpyA(LPSTR arg1, LPCSTR arg2)
321{
322 dprintf(("KERNEL32: lstrcpy(%08xh,%s)\n",
323 arg1,
324 arg2));
325
326 return O32_lstrcpy(arg1, arg2);
327}
328
329
330/*****************************************************************************
331 * Name :
332 * Purpose :
333 * Parameters:
334 * Variables :
335 * Result :
336 * Remark :
337 * Status :
338 *
339 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
340 *****************************************************************************/
341
342LPWSTR WIN32API lstrcpyW(LPWSTR dest, LPCWSTR src)
343{
344 dprintf(("KERNEL32: lstrcpyW(%08xh,%08xh)",
345 dest,
346 src));
347
348 UniStrcpy( (UniChar*)dest,
349 (UniChar*)src );
350 return dest;
351}
352
353
354/*****************************************************************************
355 * Name :
356 * Purpose :
357 * Parameters:
358 * Variables :
359 * Result :
360 * Remark :
361 * Status :
362 *
363 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
364 *****************************************************************************/
365
366LPSTR WIN32API lstrcpynA(LPSTR arg1, LPCSTR arg2, int arg3)
367{
368 register LPSTR p1 = arg1;
369 register LPSTR p2 = (LPSTR)arg2;
370
371 dprintf(("KERNEL32: OS2lstrcpyA(%08xh, %08xh, %08xh)\n",
372 arg1,
373 arg2,
374 arg3));
375
376 //PH: looks like either \0 or arg3 terminate the copy
377 //return strncpy(arg1, arg2, arg3);
378 arg3--; // pre-decrement to avoid exceeding buffer length
379 // results in better code than (arg1 > 1)
380
381 for (;*p2 && arg3; arg3--)
382 *p1++ = *p2++;
383
384 *p1 = 0; //CB: copy arg-1, set end 0
385
386 return arg1;
387}
388
389
390/*****************************************************************************
391 * Name :
392 * Purpose :
393 * Parameters:
394 * Variables :
395 * Result :
396 * Remark :
397 * Status :
398 *
399 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
400 *****************************************************************************/
401
402LPWSTR WIN32API lstrcpynW(LPWSTR dest, LPCWSTR src, int arg3)
403{
404 dprintf(("KERNEL32: lstrcpynW(%08xh,%08xh,%08xh)",
405 dest,
406 src,
407 arg3));
408
409 if (arg3 == 0)
410 return NULL;
411
412 UniStrncpy( (UniChar*)dest,
413 (UniChar*)src,
414 arg3-1); //CB: copy arg3-1 characters
415 dest[arg3-1] = 0; //CB: set end
416 return dest;
417}
418
419
420/*****************************************************************************
421 * Name :
422 * Purpose :
423 * Parameters:
424 * Variables :
425 * Result :
426 * Remark :
427 * Status :
428 *
429 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
430 *****************************************************************************/
431
432int WIN32API lstrcmpiA(LPCSTR arg1, LPCSTR arg2)
433{
434 dprintf(("KERNEL32: lstrcmpiA(%s,%s)\n",
435 arg1,
436 arg2));
437
438 return O32_lstrcmpi(arg1, arg2);
439}
440
441
442/*****************************************************************************
443 * Name :
444 * Purpose :
445 * Parameters:
446 * Variables :
447 * Result :
448 * Remark :
449 * Status :
450 *
451 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
452 *****************************************************************************/
453
454int WIN32API lstrcmpiW(LPCWSTR arg1, LPCWSTR arg2)
455{
456 char *astr1, *astr2;
457 int rc;
458
459 dprintf(("KERNEL32: lstrcmpiW(%08xh,%08xh)\n",
460 arg1,
461 arg2));
462
463 // NOTE: This function has no equivalent in uunidef.h
464 astr1 = UnicodeToAsciiString((LPWSTR)arg1);
465 astr2 = UnicodeToAsciiString((LPWSTR)arg2);
466 rc = O32_lstrcmpi(astr1, astr2);
467 FreeAsciiString(astr2);
468 FreeAsciiString(astr1);
469 return(rc);
470}
471
472
473/*****************************************************************************
474 * Name :
475 * Purpose :
476 * Parameters:
477 * Variables :
478 * Result :
479 * Remark :
480 * Status :
481 *
482 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
483 *****************************************************************************/
484
485// unilen: length of astring buffer (including 0 terminator)
486// returns string length
487
488int WIN32API lstrcpynWtoA(LPSTR astring,
489 LPWSTR ustring,
490 int unilen)
491{
492 int i;
493 int rc;
494 size_t uni_chars_left;
495 size_t out_bytes_left;
496 size_t num_subs;
497 UniChar* in_buf;
498 char* out_buf;
499
500 if (ustring == NULL)
501 {
502 if (astring != NULL && unilen > 0)
503 astring[0] = 0;
504 return 0;
505 }
506
507 if (astring == NULL || unilen <= 0)
508 return 0;
509
510 if (getUconvObject())
511 {
512 if (unilen == 1)
513 {
514 astring[0] = 0;
515 return 0; //no data
516 }
517
518 uni_chars_left = unilen-1; //elements
519 out_bytes_left = uni_chars_left; //size in bytes == elements
520 in_buf = (UniChar*)ustring;
521 out_buf = astring;
522 rc = UniUconvFromUcs(uconv_object,
523 &in_buf, &uni_chars_left,
524 (void**)&out_buf, &out_bytes_left,
525 &num_subs);
526
527 unilen -= 1+out_bytes_left; //end + left bytes
528 astring[unilen] = 0; //terminate
529
530 return unilen;
531
532 }
533 else
534 {
535 /* idiots unicode conversion :) */
536 for (i = 0; i < unilen-1; i++)
537 {
538 astring[i] = (ustring[i] > 255) ? (char)20 : (char)ustring[i]; //CB: handle invalid characters as space
539 if (ustring[i] == 0) return i; //asta la vista, baby
540 }
541
542 astring[unilen-1] = 0; // @@@PH: 1999/06/09 fix - always terminate string
543
544 return(unilen-1);
545 }
546}
547
548
549/*****************************************************************************
550 * Name :
551 * Purpose :
552 * Parameters:
553 * Variables :
554 * Result :
555 * Remark :
556 * Status :
557 *
558 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
559 *****************************************************************************/
560
561// asciilen: max length of unicode buffer (including end 0)
562
563int WIN32API lstrcpynAtoW(LPWSTR unicode,
564 LPSTR ascii,
565 int asciilen)
566{
567 int rc;
568 int i;
569 size_t uni_chars_left;
570 size_t in_bytes_left;
571 size_t num_subs;
572 UniChar* out_buf;
573 char* in_buf;
574
575 dprintf(("KERNEL32: HeapString: lstrcpynAtoW(%s,%08xh)\n",
576 ascii,
577 unicode));
578
579 //CB: no input, set at least terminator
580 if (ascii == NULL)
581 {
582 if (unicode != NULL && asciilen > 0) unicode[0] = 0;
583 return 0;
584 }
585
586 if (unicode == NULL || asciilen <= 0)
587 return 0; //nothing to do
588
589 if (getUconvObject())
590 {
591 if (asciilen == 1)
592 {
593 unicode[0] = 0;
594 return 0;
595 }
596
597 in_buf = ascii;
598 in_bytes_left = asciilen-1; //buffer size in bytes
599 out_buf = (UniChar*)unicode;
600
601 uni_chars_left = in_bytes_left; //elements
602
603 rc = UniUconvToUcs( uconv_object,
604 (void**)&in_buf, &in_bytes_left,
605 &out_buf, &uni_chars_left,
606 &num_subs );
607
608 unicode[asciilen-1-in_bytes_left] = 0;
609
610 //if (rc != ULS_SUCCESS && in_bytes_left > 0) //CB: never the case during my tests
611 // dprintf(("KERNEL32: AsciiToUnicode failed, %d bytes left!\n",in_bytes_left));
612 return asciilen - 1;
613 }
614 else
615 { //poor man's conversion
616
617 for(i = 0;i < asciilen-1;i++)
618 {
619 unicode[i] = ascii[i];
620 if (ascii[i] == 0)
621 return i-1; //work done
622 }
623
624 unicode[asciilen-1] = 0;
625 return asciilen-1;
626 }
627}
628
629
630/*****************************************************************************
631 * Name :
632 * Purpose : Converts unicode string to ascii string
633 * Parameters:
634 * Variables :
635 * Result : returns length of ascii string
636 * Remark :
637 * Status :
638 *
639 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
640 *****************************************************************************/
641
642LPSTR WIN32API lstrcpyWtoA(LPSTR ascii, LPWSTR unicode)
643{
644 if (unicode == NULL)
645 {
646 if (unicode != NULL) unicode[0] = 0; //CB: set at least end
647 return NULL;
648 }
649
650 if (unicode == NULL)
651 return NULL; /* garbage in, garbage out ! */
652
653 /* forward to function with len parameter */
654 lstrcpynWtoA(ascii,
655 unicode,
656 UniStrlen((UniChar*)unicode)+1); //end included
657
658 return ascii;
659}
660
661
662/*****************************************************************************
663 * Name :
664 * Purpose : Copies the full string from ascii to unicode
665 * Parameters:
666 * Variables :
667 * Result :
668 * Remark :
669 * Status :
670 *
671 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
672 *****************************************************************************/
673
674LPWSTR WIN32API lstrcpyAtoW(LPWSTR unicode, LPSTR ascii)
675{
676 /* achimha for security, strlen might trap if garbage in */
677 /* @@@PH 98/06/07 */
678 if (ascii == NULL)
679 {
680 if (unicode != NULL) unicode[0] = 0; //CB: set at least end
681 return NULL;
682 }
683
684 if (unicode == NULL)
685 return NULL; /* garbage in, garbage out ! */
686
687 /* forward to call with length parameter */
688 lstrcpynAtoW(unicode, ascii, strlen(ascii)+1); //end included
689 return (unicode);
690}
691
692
693
694
695/*****************************************************************************
696 * Name :
697 * Purpose :
698 * Parameters:
699 * Variables :
700 * Result :
701 * Remark :
702 * Status :
703 *
704 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
705 *****************************************************************************/
706
707LPVOID WIN32API HEAP_xalloc( HANDLE heap, DWORD flags, DWORD size )
708{
709 LPVOID p = HeapAlloc( heap, flags, size );
710 if (!p)
711 {
712 dprintf(("KERNEL32: HEAP_xalloc(%08xh,%08xh,%08xh) out of memory.\n",
713 heap,
714 flags,
715 size));
716 }
717 return p;
718}
719
720
721/*****************************************************************************
722 * Name :
723 * Purpose :
724 * Parameters:
725 * Variables :
726 * Result :
727 * Remark :
728 * Status :
729 *
730 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
731 *****************************************************************************/
732
733LPVOID WIN32API HEAP_xrealloc( HANDLE heap, DWORD flags, LPVOID lpMem, DWORD size )
734{
735 LPVOID p = HeapReAlloc( heap, flags, lpMem, size );
736 if (!p)
737 {
738 dprintf(("KERNEL32: HEAP_xrealloc(%08xh,%08xh,%08xh,%08xh) out of memory.\n",
739 heap,
740 flags,
741 lpMem,
742 size));
743 }
744 return p;
745}
746
747
748/*****************************************************************************
749 * Name :
750 * Purpose :
751 * Parameters:
752 * Variables :
753 * Result :
754 * Remark :
755 * Status :
756 *
757 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
758 *****************************************************************************/
759
760LPVOID WIN32API HEAP_malloc(DWORD size )
761{
762 LPVOID p = HeapAlloc( GetProcessHeap(), 0, size );
763 if (!p)
764 {
765 dprintf(("KERNEL32: HEAP_malloc(%08xh) out of memory.\n",
766 size));
767 }
768 return p;
769}
770
771
772/*****************************************************************************
773 * Name :
774 * Purpose :
775 * Parameters:
776 * Variables :
777 * Result :
778 * Remark :
779 * Status :
780 *
781 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
782 *****************************************************************************/
783
784LPVOID WIN32API HEAP_realloc(LPVOID lpMem, DWORD size )
785{
786 LPVOID p = HeapReAlloc( GetProcessHeap(), 0, lpMem, size );
787 if (!p)
788 {
789 dprintf(("KERNEL32: HEAP_realloc(%08xh,%08xh) out of memory.\n",
790 lpMem,
791 size));
792 }
793 return p;
794}
795
796
797/*****************************************************************************
798 * Name :
799 * Purpose :
800 * Parameters:
801 * Variables :
802 * Result :
803 * Remark :
804 * Status :
805 *
806 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
807 *****************************************************************************/
808
809VOID WIN32API HEAP_free(LPVOID lpMem)
810{
811 dprintf(("KERNEL32: HEAP_free(%08xh)\n",
812 lpMem));
813
814 HeapFree( GetProcessHeap(), 0, lpMem);
815}
816
817
818/*****************************************************************************
819 * Name :
820 * Purpose :
821 * Parameters:
822 * Variables :
823 * Result :
824 * Remark :
825 * Status :
826 *
827 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
828 *****************************************************************************/
829
830LPSTR WIN32API HEAP_strdupA( HANDLE heap, DWORD flags, LPCSTR str )
831{
832 LPSTR p = (LPSTR)HEAP_xalloc( heap, flags, strlen(str) + 1 );
833 strcpy( p, str );
834 return p;
835}
836
837
838/*****************************************************************************
839 * Name :
840 * Purpose :
841 * Parameters:
842 * Variables :
843 * Result :
844 * Remark :
845 * Status :
846 *
847 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
848 *****************************************************************************/
849
850LPWSTR WIN32API HEAP_strdupW( HANDLE heap, DWORD flags, LPCWSTR str )
851{
852 INT len = lstrlenW(str) + 1;
853 LPWSTR p = (LPWSTR)HEAP_xalloc( heap, flags, len * sizeof(WCHAR) );
854 lstrcpyW( p, str );
855 return p;
856}
857
858
859/*****************************************************************************
860 * Name :
861 * Purpose :
862 * Parameters:
863 * Variables :
864 * Result :
865 * Remark :
866 * Status :
867 *
868 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
869 *****************************************************************************/
870
871LPWSTR WIN32API HEAP_strdupAtoW( HANDLE heap, DWORD flags, LPCSTR str )
872{
873 LPWSTR ret;
874
875 if (!str) return NULL;
876 ret = (LPWSTR)HEAP_xalloc( heap, flags, (strlen(str)+1) * sizeof(WCHAR) );
877 lstrcpyAtoW( ret, (LPSTR)str );
878 return ret;
879}
880
881
882/*****************************************************************************
883 * Name :
884 * Purpose :
885 * Parameters:
886 * Variables :
887 * Result :
888 * Remark :
889 * Status :
890 *
891 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
892 *****************************************************************************/
893
894LPSTR WIN32API HEAP_strdupWtoA( HANDLE heap, DWORD flags, LPCWSTR str )
895{
896 LPSTR ret;
897
898 if (!str) return NULL;
899 ret = (LPSTR)HEAP_xalloc( heap, flags, lstrlenW(str) + 1 );
900 lstrcpyWtoA( ret, (LPWSTR)str );
901 return ret;
902}
903
904
905/*****************************************************************************
906 * Name : WideCharToLocal
907 * Purpose : similar lstrcpyWtoA, should handle codepages properly
908 * Parameters:
909 * Variables :
910 * Result : strlen of the destination string
911 * Remark :
912 * Status :
913 *
914 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
915 *****************************************************************************/
916
917INT WIN32API WideCharToLocal(LPSTR pLocal, LPWSTR pWide, INT dwChars)
918{
919 dprintf(("KERNEL32: WideCharToLocal(%08xh,%08xh,%08xh)\n",
920 pLocal,
921 pWide,
922 dwChars));
923
924 *pLocal = 0;
925 WideCharToMultiByte(CP_ACP,
926 0,
927 pWide,
928 -1,
929 pLocal,
930 dwChars,
931 NULL,
932 NULL);
933
934 return strlen(pLocal);
935}
936
937
938/*****************************************************************************
939 * Name : LocalToWideChar
940 * Purpose : similar lstrcpyAtoW, should handle codepages properly
941 * Parameters:
942 * Variables :
943 * Result : strlen of the destination string
944 * Remark :
945 * Status :
946 *
947 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
948 *****************************************************************************/
949
950INT WIN32API LocalToWideChar(LPWSTR pWide, LPSTR pLocal, INT dwChars)
951{
952 *pWide = 0;
953
954 dprintf(("KERNEL32: LocalToWideChar(%08xh,%08xh,%08xh)\n",
955 pLocal,
956 pWide,
957 dwChars));
958
959 MultiByteToWideChar(CP_ACP,
960 0,
961 pLocal,
962 -1,
963 pWide,
964 dwChars);
965
966 return lstrlenW(pWide);
967}
968
969
970
971
972
973
974#if 0
975
976
977/*****************************************************************************
978 * Name :
979 * Purpose :
980 * Parameters:
981 * Variables :
982 * Result :
983 * Remark :
984 * Status :
985 *
986 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
987 *****************************************************************************/
988
989// Converts unicode string to ascii string
990// returns pointer to ascii string
991char * WIN32API UnicodeToAsciiString(WCHAR *ustring)
992{
993 char *astring;
994
995 if(ustring == NULL) return(NULL);
996
997 astring = (char *)malloc( 1 + UniStrlen((UniChar*)ustring) );
998 UnicodeToAscii( ustring, astring );
999 return(astring);
1000}
1001
1002
1003/*****************************************************************************
1004 * Name :
1005 * Purpose :
1006 * Parameters:
1007 * Variables :
1008 * Result :
1009 * Remark :
1010 * Status :
1011 *
1012 * Author : Patrick Haller [Thu, 1999/08/05 20:46]
1013 *****************************************************************************/
1014
1015// Converts ascii string to unicode string
1016// returns pointer to unicode string
1017WCHAR * WIN32API AsciiToUnicodeString(char *astring)
1018{
1019 WCHAR *ustring;
1020
1021 if(astring == NULL)
1022 return(NULL);
1023
1024 ustring = (WCHAR *)malloc( 1 + strlen(astring) << 1 );
1025 AsciiToUnicode( astring, ustring );
1026 return(ustring);
1027}
1028
1029#endif
1030
1031
1032
Note: See TracBrowser for help on using the repository browser.