xref: /aoo41x/main/svl/source/svdde/ddewrap.cxx (revision 40df464e)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 
25 // MARKER(update_precomp.py): autogen include statement, do not remove
26 #include "precompiled_svl.hxx"
27 #define _SVTOOLS_SVDDE_DDEWRAP_CXX_
28 
29 #if defined _MSC_VER
30 #pragma warning(push, 1)
31 #endif
32 #include <windows.h>
33 #if defined _MSC_VER
34 #pragma warning(pop)
35 #endif
36 #include "ddewrap.hxx"
37 
38 //------------------------------------------------------------------------
39 
DdeCreateStringHandleW_9x(DWORD idInst,LPCWSTR pszString,int)40 HSZ WINAPI DdeCreateStringHandleW_9x( DWORD idInst, LPCWSTR pszString, int )
41 {
42 	HSZ		hszResult;
43 	LPSTR	pszANSIString;
44 	int		nSize;
45 
46 	nSize = pszString ? WideCharToMultiByte( CP_ACP, 0, pszString, -1, NULL, 0, NULL, NULL ) : 0;
47 	pszANSIString = nSize ? (LPSTR)HeapAlloc( GetProcessHeap(), 0, nSize * sizeof(CHAR) ) : NULL;
48 
49 	if ( pszANSIString )
50 		WideCharToMultiByte( CP_ACP, 0, pszString, -1, pszANSIString, nSize, NULL, NULL );
51 
52 	hszResult = DdeCreateStringHandleA( idInst, pszANSIString, CP_WINANSI );
53 
54 	if ( pszANSIString )
55 		HeapFree( GetProcessHeap(), 0, pszANSIString );
56 
57 	return hszResult;
58 }
59 
60 //------------------------------------------------------------------------
61 
DdeQueryStringW_9x(DWORD idInst,HSZ hsz,LPWSTR pszString,DWORD cchMax,int)62 DWORD WINAPI DdeQueryStringW_9x( DWORD idInst, HSZ hsz, LPWSTR pszString, DWORD cchMax, int )
63 {
64 	DWORD	dwResult;
65 	LPSTR	pszANSIString;
66 
67 	pszANSIString = cchMax ? (LPSTR)HeapAlloc( GetProcessHeap(), 0, cchMax * sizeof(CHAR) ) : NULL;
68 
69 	dwResult = DdeQueryStringA( idInst, hsz, pszANSIString, cchMax, CP_WINANSI );
70 
71 	if ( dwResult && pszANSIString )
72 		MultiByteToWideChar( CP_ACP, 0, pszANSIString, -1, pszString, cchMax );
73 
74 	if ( pszANSIString )
75 		HeapFree( GetProcessHeap(), 0, pszANSIString );
76 
77 	return dwResult;
78 }
79 
80 //------------------------------------------------------------------------
81 
DdeInitializeW_9x(LPDWORD pidInst,PFNCALLBACK pfnCallback,DWORD afCmd,DWORD ulRes)82 UINT WINAPI DdeInitializeW_9x( LPDWORD pidInst, PFNCALLBACK pfnCallback, DWORD afCmd, DWORD ulRes )
83 {
84 	return DdeInitializeA( pidInst, pfnCallback, afCmd, ulRes );
85 }
86 
87 //------------------------------------------------------------------------
88 
89 #define DEFINE_WAPI_FUNC(func) \
90 func##_PROC lpfn##func = (LONG)GetVersion() >= 0 ? func : func##_9x;
91 
92 
93 DEFINE_WAPI_FUNC( DdeCreateStringHandleW );
94 DEFINE_WAPI_FUNC( DdeQueryStringW );
95 DEFINE_WAPI_FUNC( DdeInitializeW );
96 
97