ddeml16.c 11.8 KB
Newer Older
1 2 3 4 5 6 7
/*
 * DDEML library
 *
 * Copyright 1997 Alexandre Julliard
 * Copyright 1997 Len White
 * Copyright 1999 Keith Matthews
 * Copyright 2000 Corel
8
 * Copyright 2001,2002 Eric Pouech
9 10 11 12 13 14 15 16 17 18 19 20 21
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
22
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 24
 */

25
#include <stdarg.h>
26 27
#include <string.h>
#include "windef.h"
28
#include "winbase.h"
29
#include "wine/windef16.h"
30
#include "wownt32.h"
31 32
#include "dde.h"
#include "ddeml.h"
33
#include "dde_private.h"
34
#include "wine/debug.h"
35

36
WINE_DEFAULT_DEBUG_CHANNEL(ddeml);
37 38


39 40
typedef HDDEDATA (CALLBACK *PFNCALLBACK16)(UINT16,UINT16,HCONV,HSZ,HSZ,HDDEDATA,
                                           DWORD,DWORD);
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

typedef struct
{
    UINT16  cb;
    UINT16  wFlags;
    UINT16  wCountryID;
    INT16   iCodePage;
    DWORD   dwLangID;
    DWORD   dwSecurity;
} CONVCONTEXT16, *LPCONVCONTEXT16;

typedef struct
{
    DWORD          cb;
    DWORD          hUser;
    HCONV          hConvPartner;
    HSZ            hszSvcPartner;
    HSZ            hszServiceReq;
    HSZ            hszTopic;
    HSZ            hszItem;
    UINT16         wFmt;
    UINT16         wType;
    UINT16         wStatus;
    UINT16         wConvst;
    UINT16         wLastError;
    HCONVLIST      hConvList;
    CONVCONTEXT16  ConvCtxt;
} CONVINFO16, *LPCONVINFO16;

70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
static void map1632_conv_context(CONVCONTEXT* cc32, const CONVCONTEXT16* cc16)
{
    cc32->cb = sizeof(*cc32);
    cc32->wFlags = cc16->wFlags;
    cc32->wCountryID = cc16->wCountryID;
    cc32->iCodePage = cc16->iCodePage;
    cc32->dwLangID = cc16->dwLangID;
    cc32->dwSecurity = cc16->dwSecurity;
}

static void map3216_conv_context(CONVCONTEXT16* cc16, const CONVCONTEXT* cc32)
{
    cc16->cb = sizeof(*cc16);
    cc16->wFlags = cc32->wFlags;
    cc16->wCountryID = cc32->wCountryID;
    cc16->iCodePage = cc32->iCodePage;
    cc16->dwLangID = cc32->dwLangID;
    cc16->dwSecurity = cc32->dwSecurity;
}

90 91 92 93 94 95

/******************************************************************
 *		WDML_InvokeCallback16
 *
 *
 */
96 97
HDDEDATA	WDML_InvokeCallback16(PFNCALLBACK pfn, UINT uType, UINT uFmt,
                                      HCONV hConv, HSZ hsz1, HSZ hsz2,
98
                                      HDDEDATA hdata, DWORD dwData1, DWORD dwData2)
99
{
100
    DWORD               d1 = 0;
101 102
    HDDEDATA            ret;
    CONVCONTEXT16       cc16;
103
    WORD args[16];
104 105 106 107 108

    switch (uType)
    {
    case XTYP_CONNECT:
    case XTYP_WILDCONNECT:
109 110 111 112 113 114
        if (dwData1)
        {
            map3216_conv_context(&cc16, (const CONVCONTEXT*)dwData1);
            d1 = MapLS(&cc16);
        }
        else
115 116 117 118 119
        break;
    default:
        d1 = dwData1;
        break;
    }
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
    args[15] = HIWORD(uType);
    args[14] = LOWORD(uType);
    args[13] = HIWORD(uFmt);
    args[12] = LOWORD(uFmt);
    args[11] = HIWORD(hConv);
    args[10] = LOWORD(hConv);
    args[9]  = HIWORD(hsz1);
    args[8]  = LOWORD(hsz1);
    args[7]  = HIWORD(hsz2);
    args[6]  = LOWORD(hsz2);
    args[5]  = HIWORD(hdata);
    args[4]  = LOWORD(hdata);
    args[3]  = HIWORD(d1);
    args[2]  = LOWORD(d1);
    args[1]  = HIWORD(dwData2);
    args[0]  = LOWORD(dwData2);
    WOWCallback16Ex( (DWORD)pfn, WCB16_PASCAL, sizeof(args), args, (DWORD *)&ret );

138 139 140 141
    switch (uType)
    {
    case XTYP_CONNECT:
    case XTYP_WILDCONNECT:
142
        if (d1 != 0) UnMapLS(d1);
143 144 145
        break;
    }
    return ret;
146
}
147 148

/******************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
149
 *            DdeInitialize   (DDEML.2)
150 151 152 153
 */
UINT16 WINAPI DdeInitialize16(LPDWORD pidInst, PFNCALLBACK16 pfnCallback,
			      DWORD afCmd, DWORD ulRes)
{
154 155
    return WDML_Initialize(pidInst, (PFNCALLBACK)pfnCallback, afCmd, ulRes,
                           FALSE, TRUE);
156 157 158
}

/*****************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
159
 *            DdeUninitialize   (DDEML.3)
160 161 162
 */
BOOL16 WINAPI DdeUninitialize16(DWORD idInst)
{
163
    return (BOOL16)DdeUninitialize(idInst);
164 165 166
}

/*****************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
167
 * DdeConnectList [DDEML.4]
168 169 170
 */

HCONVLIST WINAPI DdeConnectList16(DWORD idInst, HSZ hszService, HSZ hszTopic,
171
				  HCONVLIST hConvList, LPCONVCONTEXT16 pCC16)
172
{
173 174
    CONVCONTEXT	        cc;
    CONVCONTEXT*	pCC = NULL;
175

176 177 178
    if (pCC16)
        map1632_conv_context(pCC = &cc, pCC16);
    return DdeConnectList(idInst, hszService, hszTopic, hConvList, pCC);
179 180 181
}

/*****************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
182
 * DdeQueryNextServer [DDEML.5]
183 184 185
 */
HCONV WINAPI DdeQueryNextServer16(HCONVLIST hConvList, HCONV hConvPrev)
{
186
    return DdeQueryNextServer(hConvList, hConvPrev);
187 188 189 190 191 192 193
}

/*****************************************************************
 *            DdeDisconnectList (DDEML.6)
 */
BOOL16 WINAPI DdeDisconnectList16(HCONVLIST hConvList)
{
194
    return (BOOL16)DdeDisconnectList(hConvList);
195 196 197 198
}


/*****************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
199
 *		DdeQueryString (DDEML.23)
200
 */
201
DWORD WINAPI DdeQueryString16(DWORD idInst, HSZ hsz, LPSTR lpsz, DWORD cchMax,
202
                              INT16 codepage)
203
{
204
    return DdeQueryStringA(idInst, hsz, lpsz, cchMax, codepage);
205 206 207
}

/*****************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
208
 *            DdeConnect   (DDEML.7)
209
 */
210
HCONV WINAPI DdeConnect16(DWORD idInst, HSZ hszService, HSZ hszTopic,
211
                          LPCONVCONTEXT16 pCC16)
212
{
213 214
    CONVCONTEXT	        cc;
    CONVCONTEXT*	pCC = NULL;
215

216 217 218
    if (pCC16)
        map1632_conv_context(pCC = &cc, pCC16);
    return DdeConnect(idInst, hszService, hszTopic, pCC);
219 220 221
}

/*****************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
222
 *            DdeDisconnect   (DDEML.8)
223 224 225
 */
BOOL16 WINAPI DdeDisconnect16(HCONV hConv)
{
226
    return (BOOL16)DdeDisconnect(hConv);
227 228 229
}

/*****************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
230
 *            DdeSetUserHandle (DDEML.10)
231 232 233
 */
BOOL16 WINAPI DdeSetUserHandle16(HCONV hConv, DWORD id, DWORD hUser)
{
234
    return DdeSetUserHandle(hConv, id, hUser);
235 236 237
}

/*****************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
238
 *            DdeCreateDataHandle (DDEML.14)
239
 */
240 241
HDDEDATA WINAPI DdeCreateDataHandle16(DWORD idInst, LPBYTE pSrc, DWORD cb,
                                      DWORD cbOff, HSZ hszItem, UINT16 wFmt,
242 243
				      UINT16 afCmd)
{
244
    return DdeCreateDataHandle(idInst, pSrc, cb, cbOff, hszItem, wFmt, afCmd);
245 246 247
}

/*****************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
248
 *            DdeCreateStringHandle   (DDEML.21)
249 250 251
 */
HSZ WINAPI DdeCreateStringHandle16(DWORD idInst, LPCSTR str, INT16 codepage)
{
252 253 254
    if  (codepage)
    {
        return DdeCreateStringHandleA(idInst, str, codepage);
255 256
    }
    else
257 258 259 260
    {
        TRACE("Default codepage supplied\n");
        return DdeCreateStringHandleA(idInst, str, CP_WINANSI);
    }
261 262 263
}

/*****************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
264
 *            DdeFreeStringHandle   (DDEML.22)
265 266 267
 */
BOOL16 WINAPI DdeFreeStringHandle16(DWORD idInst, HSZ hsz)
{
268
    return (BOOL16)DdeFreeStringHandle(idInst, hsz);
269 270 271
}

/*****************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
272
 *            DdeFreeDataHandle   (DDEML.19)
273 274 275
 */
BOOL16 WINAPI DdeFreeDataHandle16(HDDEDATA hData)
{
276
    return (BOOL16)DdeFreeDataHandle(hData);
277 278 279
}

/*****************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
280
 *            DdeKeepStringHandle   (DDEML.24)
281 282 283
 */
BOOL16 WINAPI DdeKeepStringHandle16(DWORD idInst, HSZ hsz)
{
284
    return (BOOL)DdeKeepStringHandle(idInst, hsz);
285 286 287
}

/*****************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
288
 *            DdeClientTransaction  (DDEML.11)
289
 */
290 291
HDDEDATA WINAPI DdeClientTransaction16(LPVOID pData, DWORD cbData, HCONV hConv,
                                       HSZ hszItem, UINT16 wFmt, UINT16 wType,
292
                                       DWORD dwTimeout, LPDWORD pdwResult)
293
{
294 295
    return DdeClientTransaction((LPBYTE)pData, cbData, hConv, hszItem,
                                wFmt, wType, dwTimeout, pdwResult);
296 297 298 299
}

/*****************************************************************
 *
Patrik Stridvall's avatar
Patrik Stridvall committed
300
 *            DdeAbandonTransaction (DDEML.12)
301 302
 *
 */
303
BOOL16 WINAPI DdeAbandonTransaction16(DWORD idInst, HCONV hConv, DWORD idTransaction)
304
{
305
    return (BOOL16)DdeAbandonTransaction(idInst, hConv, idTransaction);
306 307 308
}

/*****************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
309
 * DdePostAdvise [DDEML.13]
310 311 312
 */
BOOL16 WINAPI DdePostAdvise16(DWORD idInst, HSZ hszTopic, HSZ hszItem)
{
313
    return (BOOL16)DdePostAdvise(idInst, hszTopic, hszItem);
314 315 316
}

/*****************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
317
 *            DdeAddData (DDEML.15)
318
 */
319
HDDEDATA WINAPI DdeAddData16(HDDEDATA hData, LPBYTE pSrc, DWORD cb, DWORD cbOff)
320
{
321
    return DdeAddData(hData, pSrc, cb, cbOff);
322 323 324
}

/*****************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
325
 * DdeGetData [DDEML.16]
326
 */
327
DWORD WINAPI DdeGetData16(HDDEDATA hData, LPBYTE pDst, DWORD cbMax, DWORD cbOff)
328
{
329
    return DdeGetData(hData, pDst, cbMax, cbOff);
330 331 332
}

/*****************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
333
 *            DdeAccessData (DDEML.17)
334 335 336
 */
LPBYTE WINAPI DdeAccessData16(HDDEDATA hData, LPDWORD pcbDataSize)
{
337
    FIXME("expect trouble\n");
338 339
    /* FIXME: there's a memory leak here... */
    return (LPBYTE)MapLS(DdeAccessData(hData, pcbDataSize));
340 341 342
}

/*****************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
343
 *            DdeUnaccessData (DDEML.18)
344 345 346
 */
BOOL16 WINAPI DdeUnaccessData16(HDDEDATA hData)
{
347
    return DdeUnaccessData(hData);
348 349 350
}

/*****************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
351
 *            DdeEnableCallback (DDEML.26)
352 353 354
 */
BOOL16 WINAPI DdeEnableCallback16(DWORD idInst, HCONV hConv, UINT16 wCmd)
{
355
    return DdeEnableCallback(idInst, hConv, wCmd);
356 357 358
}

/*****************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
359
 *            DdeNameService  (DDEML.27)
360
 */
361
HDDEDATA WINAPI DdeNameService16(DWORD idInst, HSZ hsz1, HSZ hsz2, UINT16 afCmd)
362
{
363
    return DdeNameService(idInst, hsz1, hsz2, afCmd);
364 365 366
}

/*****************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
367
 *            DdeGetLastError  (DDEML.20)
368 369 370
 */
UINT16 WINAPI DdeGetLastError16(DWORD idInst)
{
371
    return (UINT16)DdeGetLastError(idInst);
372 373 374
}

/*****************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
375
 *            DdeCmpStringHandles (DDEML.36)
376 377 378
 */
INT16 WINAPI DdeCmpStringHandles16(HSZ hsz1, HSZ hsz2)
{
379
    return DdeCmpStringHandles(hsz1, hsz2);
380 381 382
}

/******************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
383
 *		DdeQueryConvInfo (DDEML.9)
384 385
 *
 */
386
UINT16 WINAPI DdeQueryConvInfo16(HCONV hConv, DWORD idTransaction,
387
                                 LPCONVINFO16 lpConvInfo)
388
{
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415
    CONVINFO    ci32;
    CONVINFO16  ci16;
    UINT        ret;

    ci32.cb = sizeof(ci32);
    ci32.ConvCtxt.cb = sizeof(ci32.ConvCtxt);

    ret = DdeQueryConvInfo(hConv, idTransaction, &ci32);
    if (ret == 0) return 0;

    ci16.hUser = ci32.hUser;
    ci16.hConvPartner = ci32.hConvPartner;
    ci16.hszSvcPartner = ci32.hszSvcPartner;
    ci16.hszServiceReq = ci32.hszServiceReq;
    ci16.hszTopic = ci32.hszTopic;
    ci16.hszItem = ci32.hszItem;
    ci16.wFmt = ci32.wFmt;
    ci16.wType = ci32.wType;
    ci16.wStatus = ci32.wStatus;
    ci16.wConvst = ci32.wConvst;
    ci16.wLastError = ci32.wLastError;
    ci16.hConvList = ci32.hConvList;

    map3216_conv_context(&ci16.ConvCtxt, &ci32.ConvCtxt);

    memcpy(lpConvInfo, &ci16, lpConvInfo->cb);
    return lpConvInfo->cb;
416
}