Added an unknown VxD error code.
[wine] / dlls / imm32 / string.c
1 /*
2  *      Helper functions for ANSI<->UNICODE string conversion
3  *
4  *      Copyright 2000 Hidenori Takeshima
5  */
6
7 #include "config.h"
8
9 #include "winbase.h"
10 #include "windef.h"
11 #include "wingdi.h"
12 #include "winuser.h"
13 #include "winerror.h"
14 #include "winnls.h"
15 #include "immddk.h"
16 #include "debugtools.h"
17 DEFAULT_DEBUG_CHANNEL(imm);
18
19 #include "imm_private.h"
20
21
22 INT IMM32_strlenAtoW( LPCSTR lpstr )
23 {
24         INT     len;
25
26         len = MultiByteToWideChar( CP_ACP, 0, lpstr, -1, NULL, 0 );
27         return ( len > 0 ) ? (len-1) : 0;
28 }
29
30 INT IMM32_strlenWtoA( LPCWSTR lpwstr )
31 {
32         INT     len;
33
34         len = WideCharToMultiByte( CP_ACP, 0, lpwstr, -1,
35                                    NULL, 0, NULL, NULL );
36         return ( len > 0 ) ? (len-1) : 0;
37 }
38
39 LPWSTR IMM32_strncpyAtoW( LPWSTR lpwstr, LPCSTR lpstr, INT wbuflen )
40 {
41         INT     len;
42
43         len = MultiByteToWideChar( CP_ACP, 0, lpstr, -1, lpwstr, wbuflen );
44         if ( len == 0 )
45                 *lpwstr = 0;
46         return lpwstr;
47 }
48
49 LPSTR IMM32_strncpyWtoA( LPSTR lpstr, LPCWSTR lpwstr, INT abuflen )
50 {
51         INT     len;
52
53         len = WideCharToMultiByte( CP_ACP, 0, lpwstr, -1,
54                                    lpstr, abuflen, NULL, NULL );
55         if ( len == 0 )
56                 *lpstr = 0;
57         return lpstr;
58 }
59
60 LPWSTR IMM32_strdupAtoW( LPCSTR lpstr )
61 {
62         INT len;
63         LPWSTR lpwstr = NULL;
64
65         len = IMM32_strlenAtoW( lpstr );
66         if ( len > 0 )
67         {
68                 lpwstr = (LPWSTR)IMM32_HeapAlloc( 0, sizeof(WCHAR)*(len+1) );
69                 if ( lpwstr != NULL )
70                         (void)IMM32_strncpyAtoW( lpwstr, lpstr, len+1 );
71         }
72
73         return lpwstr;
74 }
75
76 LPSTR IMM32_strdupWtoA( LPCWSTR lpwstr )
77 {
78         INT len;
79         LPSTR lpstr = NULL;
80
81         len = IMM32_strlenWtoA( lpwstr );
82         if ( len > 0 )
83         {
84                 lpstr = (LPSTR)IMM32_HeapAlloc( 0, sizeof(CHAR)*(len+1) );
85                 if ( lpstr != NULL )
86                         (void)IMM32_strncpyWtoA( lpstr, lpwstr, len+1 );
87         }
88
89         return lpstr;
90 }