Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

AHK DDE, FINALLY HERE!! (well... almost... ) Dll param help!


  • Please log in to reply
3 replies to this topic
Joy2DWorld
  • Members
  • 562 posts
  • Last active: Jun 30 2014 07:48 PM
  • Joined: 04 Dec 2006
Seems like MS has made this ridiculously complex to figure out,
but once did that... it's actually ridiculously simple and...

if can just get it to actually work... can do some amazing cool things.


think that I am not converting the right size params in the final DLL call... (see below)


the bones of my DDE function for AHK look like this:

; trying to figure out the DLLCALL equivalence...
;
; PLEASE LET ME KNOW IF THIS IS WRONG ?!


LPDWORD := "UIntP"
PFNCALLBACK := "UInt"     ; or should that be Int ?
DWORD  := "UInt"
HSZ := "UInt"   ; is that right ?
UINTc := "UShort"  ;   Can this be right ?  is it UInt ?? Int ??
NULL := "Int"
LPTSTR := "str"
INTc :=  "short"   ; maybe Int ???    SEE BELOW FOR MS DEFS...


APPCLASS_STANDARD :=  0
CP_WINANSI   := 1004
CF_TEXT := 1
XTYP_EXECUTE  = 0x0050  
XTYP_POKE   = 0x0090 
XTYP_REQUEST    = 0x00B0 

VarSetCapacity(ddeServer, 256,0)
VarSetCapacity(ddeDataE, 256,0)
VarSetCapacity(ddeData,33000)
VarSetCapacity(ReturnV1,33000)

ddeServer =  excel
ddeTopic = 
ddeData = [formula(\"SWI-Prolog\",\"r1c1\")]


pidInst := 0 


if ( DllCall("DdeInitialize" 
	, LPDWORD,  pidInst
	, PFNCALLBACK, 0
	, DWORD, APPCLASS_STANDARD
	, DWORD, 0 ) )
	
	msgbox ERROR with DDEInitialze !

	
HddeServer := DllCall("DdeCreateStringHandle" 
			, DWORD,  pidInst
			, LPTSTR,  ddeServer
			, INTc,  CP_WINANSI )
			
HddeTopic := DllCall("DdeCreateStringHandle" 
			, DWORD,  pidInst
			, LPTSTR,  ddeTopic
			, INTc,  CP_WINANSI )

ddeDataE = 
HddeDataE := DllCall("DdeCreateStringHandle" 
			, DWORD,  pidInst
			, LPTSTR,  ddeDataE
			, INTc,  CP_WINANSI )


HddeConversation := DllCall("DdeConnect" 
				, DWORD,  pidInst
				, HSZ, HddeServer
				, HSZ, HddeTopic
				, Null, 0 )


ddeData =  [formula(\"SWI-Prolog\",\"r1c1\")]
BddeData := StrLen(ddeData) + 1
ddeResult  = 0


;
; THIS IS NOT SEEMING TO WORK
;
ReturnV1 := DllCall("DdeClientTransaction" 
			, STR, ddeData 
			, DWORD, BddeData
			, Uintc,  HddeConversation
			, DWORD , HddeDataE
			, UINTc, CF_TEXT  ; NOTE: should be ZERO with execute
			, UINTc, XTYP_EXECUTE
			, DWORD, 1000
			, LPDWORD, ddeResult ) ;
			

compare := 0x4000 + 0
msgbox 32,, % DllCall("DdeGetLastError",      DWORD,  idInst)  " :"  compare
	
	
exitapp


note to try this, need to DDE server such as MS excel,




the 'rules' at Microsoft's MSDN
[Moderator's note: I put this super-long link in an URL tag to avoid horizontal scrolling of page]


Syntax

HDDEDATA DdeCreateDataHandle( DWORD idInst,
LPBYTE pSrc,
DWORD cb,
DWORD cbOff,
HSZ hszItem,
UINT wFmt,
UINT afCmd
);
Parameters

idInst
[in] Specifies the application instance identifier obtained by a previous call to the DdeInitialize function.
pSrc
[in] Pointer to a buffer that contains data to be copied to the DDE object. If this parameter is NULL, no data is copied to the object.
cb
[in] Specifies the amount of memory, in bytes, to copy from the buffer pointed to by pSrc. (include the terminating NULL, if the data is a string). If this parameter is zero, the pSrc parameter is ignored.
cbOff
[in] Specifies an offset, in bytes, from the beginning of the buffer pointed to by the pSrc parameter. The data beginning at this offset is copied from the buffer to the DDE object.
hszItem
[in] Handle to the string that specifies the data item corresponding to the DDE object. This handle must have been created by a previous call to the DdeCreateStringHandle function. If the data handle is to be used in an XTYP_EXECUTE transaction, this parameter must be 0L.
wFmt
[in] Specifies the standard clipboard format of the data.
afCmd
[in] Specifies the creation flags. This parameter can be HDATA_APPOWNED, which specifies that the server application calling the DdeCreateDataHandle function owns the data handle this function creates. This flag enables the application to share the data handle with other Dynamic Data Exchange Management Library (DDEML) applications rather than creating a separate handle to pass to each application. If this flag is specified, the application must eventually free the shared memory object associated with the handle by using the DdeFreeDataHandle function. If this flag is not specified, the handle becomes invalid in the application that created the handle after the data handle is returned by the application's DDE callback function or is used as a parameter in another DDEML function.
Return Value


If the function succeeds, the return value is a data handle.

If the function fails, the return value is 0L.

The DdeGetLastError function can be used to get the error code, which can be one of the following values:


DMLERR_DLL_NOT_INITIALIZED
DMLERR_INVALIDPARAMETER
DMLERR_MEMORY_ERROR
DMLERR_NO_ERROR



Remarks

Any unfilled locations in the DDE object are undefined.

After a data handle has been used as a parameter in another DDEML function or has been returned by a DDE callback function, the handle can be used only for read access to the DDE object identified by the handle.



ps: the error code ("6") is 'improper paramaters' on the last DLL call...


WHAT IS THE DLLCALL EQUIVALENCE FOR:

MSoft's ":

HCONV (UINT or USHORT ?)

UINT (is this ahk's uint ... or is a SHORT ??)

HSZ (handle is short or UINT ??)

LPBYTE (STR ?? UINT + &Var ?? USHORT + & VAR ? STR* ??)


ps2: have also seen def's as "
void FAR* pData,
DWORD cbData,
HCONV hConv,
HSZ hszItem,
UINT uFmt,
UINT uType,
DWORD dwTimeout,
DWORD FAR* pdwResult

but am not sure that I have the AHK equivalents correct...

this or... missing something else ?
Joyce Jamce

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005

WHAT IS THE DLLCALL EQUIVALENCE FOR:

MSoft's ":

HCONV (UINT or USHORT ?)

UINT (is this ahk's uint ... or is a SHORT ??)

HSZ (handle is short or UINT ??)

LPBYTE (STR ?? UINT + &Var ?? USHORT + & VAR ? STR* ??)

See Windows Data Types lookup tool...
As a general rule, most (all?) types whose name starts with H are handle, unsigned 32bit types.
Chris indeed made his UInt the same as MS' UINT, seems logical...
LPBYTE is likely to be a Long Pointer to a BYTE. There is some logic in MS' crazy names... A Str should do the job, but indeed it is the same as UInt &Var (a pointer is a 32bit value, at least in Win32! Different stuff in Win64...).
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

netfun81
  • Members
  • 58 posts
  • Last active: Feb 21 2010 09:32 AM
  • Joined: 28 Oct 2006
Several years ago Tdewolf a Geoshell dev, figured out how to access the Microsoft DDE server when not using explorer as the shell. Almost all ALT shells now have this code built in so that DDE support is the same as when using Explorer as shell.

Here is a link to the code, it might help you figure out how to do the same for AutoHotkey:

<!-- m -->http://www.freelists... ... 00020.html<!-- m -->

BoBo
  • Guests
  • Last active:
  • Joined: --

Here is a link to the code, it might help you figure out how to do the same for AutoHotkey:

I guess that code is C++, right? Thx for sharing this! Much appreciated. 8)

So, as you said, it shouldn't be to tough to be implemented within AHK.
Even that it's an old fashioned way to communicate with Excel, Winword & Co. - it would be worth it (IMHO). 8)