module win32.ddeml;

// Translated from Microsoft Platform SDK August 2001 Edition
// by Y.Tomino

import win32.windef;

// #ifndef _INC_DDEMLH
// #define _INC_DDEMLH

// #ifdef __cplusplus
// extern "C" {
// #endif /* __cplusplus */

alias void* HCONVLIST;
alias void* HCONV;
alias void* HSZ;
alias void* HDDEDATA;
// #define EXPENTRY CALLBACK

struct tagHSZPAIR {
  HSZ hszSvc;
  HSZ hszTopic;
}
alias tagHSZPAIR HSZPAIR;

alias HSZPAIR* PHSZPAIR;

struct tagCONVCONTEXT {
  UINT cb;
  UINT wFlags;
  UINT wCountryID;
  int iCodePage;
  DWORD dwLangID;
  DWORD dwSecurity;
  SECURITY_QUALITY_OF_SERVICE qos;
}
alias tagCONVCONTEXT CONVCONTEXT;

alias CONVCONTEXT* PCONVCONTEXT;

struct tagCONVINFO {
  DWORD cb;
  DWORD_PTR hUser;
  HCONV hConvPartner;
  HSZ hszSvcPartner;
  HSZ hszServiceReq;
  HSZ hszTopic;
  HSZ hszItem;
  UINT wFmt;
  UINT wType;
  UINT wStatus;
  UINT wConvst;
  UINT wLastError;
  HCONVLIST hConvList;
  CONVCONTEXT ConvCtxt;
  HWND hwnd;
  HWND hwndPartner;
}
alias tagCONVINFO CONVINFO;

alias CONVINFO* PCONVINFO;

enum : uint { XST_NULL = 0 }
enum : uint { XST_INCOMPLETE = 1 }
enum : uint { XST_CONNECTED = 2 }
enum : uint { XST_INIT1 = 3 }
enum : uint { XST_INIT2 = 4 }
enum : uint { XST_REQSENT = 5 }
enum : uint { XST_DATARCVD = 6 }
enum : uint { XST_POKESENT = 7 }
enum : uint { XST_POKEACKRCVD = 8 }
enum : uint { XST_EXECSENT = 9 }
enum : uint { XST_EXECACKRCVD = 10 }
enum : uint { XST_ADVSENT = 11 }
enum : uint { XST_UNADVSENT = 12 }
enum : uint { XST_ADVACKRCVD = 13 }
enum : uint { XST_UNADVACKRCVD = 14 }
enum : uint { XST_ADVDATASENT = 15 }
enum : uint { XST_ADVDATAACKRCVD = 16 }

enum : uint { CADV_LATEACK = 0xFFFF }

enum : uint { ST_CONNECTED = 0x0001 }
enum : uint { ST_ADVISE = 0x0002 }
enum : uint { ST_ISLOCAL = 0x0004 }
enum : uint { ST_BLOCKED = 0x0008 }
enum : uint { ST_CLIENT = 0x0010 }
enum : uint { ST_TERMINATED = 0x0020 }
enum : uint { ST_INLIST = 0x0040 }
enum : uint { ST_BLOCKNEXT = 0x0080 }
enum : uint { ST_ISSELF = 0x0100 }

enum : uint { DDE_FACK = 0x8000 }
enum : uint { DDE_FBUSY = 0x4000 }
enum : uint { DDE_FDEFERUPD = 0x4000 }
enum : uint { DDE_FACKREQ = 0x8000 }
enum : uint { DDE_FRELEASE = 0x2000 }
enum : uint { DDE_FREQUESTED = 0x1000 }
enum : uint { DDE_FAPPSTATUS = 0x00ff }
enum : uint { DDE_FNOTPROCESSED = 0x0000 }

const uint DDE_FACKRESERVED = ~(DDE_FACK | DDE_FBUSY | DDE_FAPPSTATUS);
const uint DDE_FADVRESERVED = ~(DDE_FACKREQ | DDE_FDEFERUPD);
const uint DDE_FDATRESERVED = ~(DDE_FACKREQ | DDE_FRELEASE | DDE_FREQUESTED);
const uint DDE_FPOKRESERVED = ~(DDE_FRELEASE);

enum : uint { MSGF_DDEMGR = 0x8001 }

enum : uint { CP_WINANSI = 1004 }
enum : uint { CP_WINUNICODE = 1200 }
// #ifdef UNICODE
alias CP_WINUNICODE CP_WINNEUTRAL;
// #else  // !UNICODE
// #...
// #endif // !UNICODE

enum : uint { XTYPF_NOBLOCK = 0x0002 }
enum : uint { XTYPF_NODATA = 0x0004 }
enum : uint { XTYPF_ACKREQ = 0x0008 }

enum : uint { XCLASS_MASK = 0xFC00 }
enum : uint { XCLASS_BOOL = 0x1000 }
enum : uint { XCLASS_DATA = 0x2000 }
enum : uint { XCLASS_FLAGS = 0x4000 }
enum : uint { XCLASS_NOTIFICATION = 0x8000 }

const uint XTYP_ERROR = 0x0000 | XCLASS_NOTIFICATION | XTYPF_NOBLOCK ;
const uint XTYP_ADVDATA = 0x0010 | XCLASS_FLAGS ;
const uint XTYP_ADVREQ = 0x0020 | XCLASS_DATA | XTYPF_NOBLOCK ;
const uint XTYP_ADVSTART = 0x0030 | XCLASS_BOOL ;
const uint XTYP_ADVSTOP = 0x0040 | XCLASS_NOTIFICATION;
const uint XTYP_EXECUTE = 0x0050 | XCLASS_FLAGS ;
const uint XTYP_CONNECT = 0x0060 | XCLASS_BOOL | XTYPF_NOBLOCK;
const uint XTYP_CONNECT_CONFIRM = 0x0070 | XCLASS_NOTIFICATION | XTYPF_NOBLOCK;
const uint XTYP_XACT_COMPLETE = 0x0080 | XCLASS_NOTIFICATION ;
const uint XTYP_POKE = 0x0090 | XCLASS_FLAGS ;
const uint XTYP_REGISTER = 0x00A0 | XCLASS_NOTIFICATION | XTYPF_NOBLOCK;
const uint XTYP_REQUEST = 0x00B0 | XCLASS_DATA ;
const uint XTYP_DISCONNECT = 0x00C0 | XCLASS_NOTIFICATION | XTYPF_NOBLOCK;
const uint XTYP_UNREGISTER = 0x00D0 | XCLASS_NOTIFICATION | XTYPF_NOBLOCK;
const uint XTYP_WILDCONNECT = 0x00E0 | XCLASS_DATA | XTYPF_NOBLOCK;

enum : uint { XTYP_MASK = 0x00F0 }
enum : uint { XTYP_SHIFT = 4 }

enum : uint { TIMEOUT_ASYNC = 0xFFFFFFFF }

enum : uint { QID_SYNC = 0xFFFFFFFF }

// #ifdef UNICODE
const wchar[] SZDDESYS_TOPIC = "System";
const wchar[] SZDDESYS_ITEM_TOPICS = "Topics";
const wchar[] SZDDESYS_ITEM_SYSITEMS = "SysItems";
const wchar[] SZDDESYS_ITEM_RTNMSG = "ReturnMessage";
const wchar[] SZDDESYS_ITEM_STATUS = "Status";
const wchar[] SZDDESYS_ITEM_FORMATS = "Formats";
const wchar[] SZDDESYS_ITEM_HELP = "Help";
const wchar[] SZDDE_ITEM_ITEMLIST = "TopicItemList";
// #else
// #...
// #...
// #...
// #...
// #...
// #...
// #...
// #...
// #endif

// typedef HDDEDATA CALLBACK FNCALLBACK(UINT wType, UINT wFmt, HCONV hConv, HSZ hsz1, HSZ hsz2, HDDEDATA hData, ULONG_PTR dwData1, ULONG_PTR dwData2);
extern(Windows) alias HDDEDATA function(UINT wType, UINT wFmt, HCONV hConv, HSZ hsz1, HSZ hsz2, HDDEDATA hData, ULONG_PTR dwData1, ULONG_PTR dwData2) PFNCALLBACK;

const HDDEDATA CBR_BLOCK = cast(HDDEDATA)-1;

extern(Windows) export UINT DdeInitializeA(   LPDWORD pidInst,  PFNCALLBACK pfnCallback,
         DWORD afCmd,  DWORD ulRes);
extern(Windows) export UINT DdeInitializeW(   LPDWORD pidInst,  PFNCALLBACK pfnCallback,
         DWORD afCmd,  DWORD ulRes);
// #ifdef UNICODE
alias DdeInitializeW DdeInitialize;
// #else
// #...
// #endif // !UNICODE

enum : uint { CBF_FAIL_SELFCONNECTIONS = 0x00001000 }
enum : uint { CBF_FAIL_CONNECTIONS = 0x00002000 }
enum : uint { CBF_FAIL_ADVISES = 0x00004000 }
enum : uint { CBF_FAIL_EXECUTES = 0x00008000 }
enum : uint { CBF_FAIL_POKES = 0x00010000 }
enum : uint { CBF_FAIL_REQUESTS = 0x00020000 }
enum : uint { CBF_FAIL_ALLSVRXACTIONS = 0x0003f000 }

enum : uint { CBF_SKIP_CONNECT_CONFIRMS = 0x00040000 }
enum : uint { CBF_SKIP_REGISTRATIONS = 0x00080000 }
enum : uint { CBF_SKIP_UNREGISTRATIONS = 0x00100000 }
enum : uint { CBF_SKIP_DISCONNECTS = 0x00200000 }
enum : uint { CBF_SKIP_ALLNOTIFICATIONS = 0x003c0000 }

enum : uint { APPCMD_CLIENTONLY = 0x00000010 }
enum : uint { APPCMD_FILTERINITS = 0x00000020 }
enum : uint { APPCMD_MASK = 0x00000FF0 }

enum : uint { APPCLASS_STANDARD = 0x00000000 }
enum : uint { APPCLASS_MASK = 0x0000000F }

extern(Windows) export BOOL DdeUninitialize(  DWORD idInst);

extern(Windows) export HCONVLIST DdeConnectList(  DWORD idInst,  HSZ hszService,  HSZ hszTopic,
         HCONVLIST hConvList,  PCONVCONTEXT pCC);
extern(Windows) export HCONV DdeQueryNextServer(  HCONVLIST hConvList,  HCONV hConvPrev);
extern(Windows) export BOOL DdeDisconnectList(  HCONVLIST hConvList);

extern(Windows) export HCONV DdeConnect(  DWORD idInst,  HSZ hszService,  HSZ hszTopic,
         PCONVCONTEXT pCC);
extern(Windows) export BOOL DdeDisconnect(   HCONV hConv);
extern(Windows) export HCONV DdeReconnect(  HCONV hConv);
extern(Windows) export UINT DdeQueryConvInfo(  HCONV hConv,  DWORD idTransaction,   PCONVINFO pConvInfo);
extern(Windows) export BOOL DdeSetUserHandle(  HCONV hConv,  DWORD id,  DWORD_PTR hUser);
extern(Windows) export BOOL DdeAbandonTransaction(  DWORD idInst,  HCONV hConv,  DWORD idTransaction);

extern(Windows) export BOOL DdePostAdvise(  DWORD idInst,  HSZ hszTopic,  HSZ hszItem);
extern(Windows) export BOOL DdeEnableCallback(  DWORD idInst,  HCONV hConv,  UINT wCmd);
extern(Windows) export BOOL DdeImpersonateClient(  HCONV hConv);

enum : uint { EC_ENABLEALL = 0 }
alias ST_BLOCKNEXT EC_ENABLEONE;
alias ST_BLOCKED EC_DISABLE;
enum : uint { EC_QUERYWAITING = 2 }

extern(Windows) export HDDEDATA DdeNameService(  DWORD idInst,  HSZ hsz1,  HSZ hsz2,  UINT afCmd);

enum : uint { DNS_REGISTER = 0x0001 }
enum : uint { DNS_UNREGISTER = 0x0002 }
enum : uint { DNS_FILTERON = 0x0004 }
enum : uint { DNS_FILTEROFF = 0x0008 }

extern(Windows) export HDDEDATA DdeClientTransaction(  LPBYTE pData,  DWORD cbData,
         HCONV hConv,  HSZ hszItem,  UINT wFmt,  UINT wType,
         DWORD dwTimeout,  LPDWORD pdwResult);

extern(Windows) export HDDEDATA DdeCreateDataHandle(  DWORD idInst,  LPBYTE pSrc,  DWORD cb,
         DWORD cbOff,  HSZ hszItem,  UINT wFmt,  UINT afCmd);
extern(Windows) export HDDEDATA DdeAddData(  HDDEDATA hData,  LPBYTE pSrc,  DWORD cb,  DWORD cbOff);
extern(Windows) export DWORD DdeGetData(  HDDEDATA hData,  LPBYTE pDst,  DWORD cbMax,  DWORD cbOff);
extern(Windows) export LPBYTE DdeAccessData(  HDDEDATA hData,  LPDWORD pcbDataSize);
extern(Windows) export BOOL DdeUnaccessData(  HDDEDATA hData);
extern(Windows) export BOOL DdeFreeDataHandle(   HDDEDATA hData);

enum : uint { HDATA_APPOWNED = 0x0001 }

extern(Windows) export UINT DdeGetLastError(  DWORD idInst);

enum : uint { DMLERR_NO_ERROR = 0 }

enum : uint { DMLERR_FIRST = 0x4000 }

enum : uint { DMLERR_ADVACKTIMEOUT = 0x4000 }
enum : uint { DMLERR_BUSY = 0x4001 }
enum : uint { DMLERR_DATAACKTIMEOUT = 0x4002 }
enum : uint { DMLERR_DLL_NOT_INITIALIZED = 0x4003 }
enum : uint { DMLERR_DLL_USAGE = 0x4004 }
enum : uint { DMLERR_EXECACKTIMEOUT = 0x4005 }
enum : uint { DMLERR_INVALIDPARAMETER = 0x4006 }
enum : uint { DMLERR_LOW_MEMORY = 0x4007 }
enum : uint { DMLERR_MEMORY_ERROR = 0x4008 }
enum : uint { DMLERR_NOTPROCESSED = 0x4009 }
enum : uint { DMLERR_NO_CONV_ESTABLISHED = 0x400a }
enum : uint { DMLERR_POKEACKTIMEOUT = 0x400b }
enum : uint { DMLERR_POSTMSG_FAILED = 0x400c }
enum : uint { DMLERR_REENTRANCY = 0x400d }
enum : uint { DMLERR_SERVER_DIED = 0x400e }
enum : uint { DMLERR_SYS_ERROR = 0x400f }
enum : uint { DMLERR_UNADVACKTIMEOUT = 0x4010 }
enum : uint { DMLERR_UNFOUND_QUEUE_ID = 0x4011 }

enum : uint { DMLERR_LAST = 0x4011 }

extern(Windows) export HSZ DdeCreateStringHandleA(  DWORD idInst,  LPCSTR psz,  int iCodePage);
extern(Windows) export HSZ DdeCreateStringHandleW(  DWORD idInst,  LPCWSTR psz,  int iCodePage);
// #ifdef UNICODE
alias DdeCreateStringHandleW DdeCreateStringHandle;
// #else
// #...
// #endif // !UNICODE
extern(Windows) export DWORD DdeQueryStringA(  DWORD idInst,  HSZ hsz,   LPSTR psz,  DWORD cchMax,  int iCodePage);
extern(Windows) export DWORD DdeQueryStringW(  DWORD idInst,  HSZ hsz,   LPWSTR psz,  DWORD cchMax,  int iCodePage);
// #ifdef UNICODE
alias DdeQueryStringW DdeQueryString;
// #else
// #...
// #endif // !UNICODE
extern(Windows) export BOOL DdeFreeStringHandle(  DWORD idInst,   HSZ hsz);
extern(Windows) export BOOL DdeKeepStringHandle(  DWORD idInst,   HSZ hsz);
extern(Windows) export int DdeCmpStringHandles(  HSZ hsz1,  HSZ hsz2);

// #ifndef NODDEMLSPY

struct tagDDEML_MSG_HOOK_DATA {
  UINT_PTR uiLo;
  UINT_PTR uiHi;
  DWORD cbData;
  DWORD Data[8];
}
alias tagDDEML_MSG_HOOK_DATA DDEML_MSG_HOOK_DATA;
alias tagDDEML_MSG_HOOK_DATA* PDDEML_MSG_HOOK_DATA;

struct tagMONMSGSTRUCT {
  UINT cb;
  HWND hwndTo;
  DWORD dwTime;
  HANDLE hTask;
  UINT wMsg;
  WPARAM wParam;
  LPARAM lParam;
  DDEML_MSG_HOOK_DATA dmhd;
}
alias tagMONMSGSTRUCT MONMSGSTRUCT;
alias tagMONMSGSTRUCT* PMONMSGSTRUCT;

struct tagMONCBSTRUCT {
  UINT cb;
  DWORD dwTime;
  HANDLE hTask;
  DWORD dwRet;
  UINT wType;
  UINT wFmt;
  HCONV hConv;
  HSZ hsz1;
  HSZ hsz2;
  HDDEDATA hData;
  ULONG_PTR dwData1;
  ULONG_PTR dwData2;
  CONVCONTEXT cc;
  DWORD cbData;
  DWORD Data[8];
}
alias tagMONCBSTRUCT MONCBSTRUCT;
alias tagMONCBSTRUCT* PMONCBSTRUCT;

struct tagMONHSZSTRUCTA {
  UINT cb;
  BOOL fsAction;
  DWORD dwTime;
  HSZ hsz;
  HANDLE hTask;
  CHAR str[1];
}
alias tagMONHSZSTRUCTA MONHSZSTRUCTA;
alias tagMONHSZSTRUCTA* PMONHSZSTRUCTA;

struct tagMONHSZSTRUCTW {
  UINT cb;
  BOOL fsAction;
  DWORD dwTime;
  HSZ hsz;
  HANDLE hTask;
  WCHAR str[1];
}
alias tagMONHSZSTRUCTW MONHSZSTRUCTW;
alias tagMONHSZSTRUCTW* PMONHSZSTRUCTW;

// #ifdef UNICODE
alias MONHSZSTRUCTW MONHSZSTRUCT;
alias PMONHSZSTRUCTW PMONHSZSTRUCT;
// #else
// ...
// #endif // UNICODE

enum : uint { MH_CREATE = 1 }
enum : uint { MH_KEEP = 2 }
enum : uint { MH_DELETE = 3 }
enum : uint { MH_CLEANUP = 4 }

struct tagMONERRSTRUCT {
  UINT cb;
  UINT wLastError;
  DWORD dwTime;
  HANDLE hTask;
}
alias tagMONERRSTRUCT MONERRSTRUCT;
alias tagMONERRSTRUCT* PMONERRSTRUCT;

struct tagMONLINKSTRUCT {
  UINT cb;
  DWORD dwTime;
  HANDLE hTask;
  BOOL fEstablished;
  BOOL fNoData;
  HSZ hszSvc;
  HSZ hszTopic;
  HSZ hszItem;
  UINT wFmt;
  BOOL fServer;
  HCONV hConvServer;
  HCONV hConvClient;
}
alias tagMONLINKSTRUCT MONLINKSTRUCT;
alias tagMONLINKSTRUCT* PMONLINKSTRUCT;

struct tagMONCONVSTRUCT {
  UINT cb;
  BOOL fConnect;
  DWORD dwTime;
  HANDLE hTask;
  HSZ hszSvc;
  HSZ hszTopic;
  HCONV hConvClient;
  HCONV hConvServer;
}
alias tagMONCONVSTRUCT MONCONVSTRUCT;
alias tagMONCONVSTRUCT* PMONCONVSTRUCT;

enum : uint { MAX_MONITORS = 4 }
enum : uint { APPCLASS_MONITOR = 0x00000001 }
const uint XTYP_MONITOR = 0x00F0 | XCLASS_NOTIFICATION | XTYPF_NOBLOCK;

enum : uint { MF_HSZ_INFO = 0x01000000 }
enum : uint { MF_SENDMSGS = 0x02000000 }
enum : uint { MF_POSTMSGS = 0x04000000 }
enum : uint { MF_CALLBACKS = 0x08000000 }
enum : uint { MF_ERRORS = 0x10000000 }
enum : uint { MF_LINKS = 0x20000000 }
enum : uint { MF_CONV = 0x40000000 }

enum : uint { MF_MASK = 0xFF000000 }
// #endif /* NODDEMLSPY */

// #ifdef __cplusplus
// }
// #endif  /* __cplusplus */

// #endif /* _INC_DDEMLH */

