summaryrefslogtreecommitdiffstats
path: root/private/nw/nwscript/wide.c
blob: 09578c7bd9bbb4309ffbfd614398fdb95053ea6e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*************************************************************************
*
*  WIDE.C
*
*  Wide character translation routines
*
*  Copyright (c) 1995 Microsoft Corporation
*
*  $Log:   N:\NT\PRIVATE\NW4\NWSCRIPT\VCS\WIDE.C  $
*  
*     Rev 1.2   10 Apr 1996 14:24:14   terryt
*  Hotfix for 21181hq
*  
*     Rev 1.2   12 Mar 1996 19:56:36   terryt
*  Relative NDS names and merge
*  
*     Rev 1.1   22 Dec 1995 14:27:18   terryt
*  Add Microsoft headers
*  
*     Rev 1.0   15 Nov 1995 18:08:20   terryt
*  Initial revision.
*  
*     Rev 1.1   23 May 1995 19:37:32   terryt
*  Spruce up source
*  
*     Rev 1.0   15 May 1995 19:11:14   terryt
*  Initial revision.
*  
*************************************************************************/

#include <stdio.h>
#include <direct.h>
#include <time.h>
#include <stdlib.h>

#include <nt.h>
#include <ntrtl.h>
#include <nturtl.h>
#include <windows.h>

#include "nwscript.h"


/********************************************************************

        szToWide

Routine Description:

        Given a single byte character string, convert to wide

Arguments:

        lpszW   - Wide character string returned
        lpszC   - Single character string input
        nSize   - length of Wide character buffer

Return Value:
        0 = success
        else NT error

 *******************************************************************/
DWORD
szToWide( 
    LPWSTR lpszW, 
    LPCSTR lpszC, 
    INT nSize 
    )
{
    if (!MultiByteToWideChar(CP_OEMCP,
                             MB_PRECOMPOSED,
                             lpszC,
                             -1,
                             lpszW,
                             nSize))
    {
        return (GetLastError()) ;
    }
    
    return NO_ERROR ;
}

/********************************************************************

        WideTosz

Routine Description:

        Given a wide character string, convert to single

Arguments:

        lpszC   - Single character string returned
        lpszW   - Wide character string input
        nSize   - length of single character buffer

Return Value:
        0 = success
        else NT error

 *******************************************************************/
DWORD
WideTosz( 
    LPSTR lpszC, 
    LPWSTR lpszW, 
    INT nSize 
    )
{
    if (!WideCharToMultiByte(CP_OEMCP,
                             0,
                             (LPCWSTR) lpszW,
                             -1,
                             lpszC,
                             nSize,
                             NULL, 
                             NULL))
    {
        return (GetLastError()) ;
    }
    
    return NO_ERROR ;
}

/********************************************************************

        ConvertUnicodeToAscii

Routine Description:

        Given a wide character string, convert to single

Arguments:

        Buffer - buffer to be converted

Return Value:
        none

 *******************************************************************/
void
ConvertUnicodeToAscii( PVOID Buffer ) 
{
    LPCWSTR lpszW = Buffer;
    BYTE Destination[1024];

    WideTosz( (LPSTR)Destination, (LPWSTR)Buffer, 1024 );

    strcpy( Buffer, Destination );
}