Hi Patrice,
Thanks for your reply - I use the CopyData message in my Sailwave application to communicate with some enhancements that I've added to it that are written in PowerBasic. Sailwave itself is written in Clarion, and I use the CopyData to communicate in both directions between the two. Out of curiosity I just had a look at your sample to see how it compared to mine. But there seems to be something wrong with yours if I'm correct (Please forgive me if I wrong)
This is your calling code
. CASE %WM_COPYDATA
' wParam holds the string length
' lParam holds the Byte array address
dwData = zGetPrivateMsg(sDataString, wParam, lParam)
szFileName = ""
IF dwData = %ZM_STRINGDATA THEN
IF LEN(sDataString) THEN szFileName = LCASE$(PARSE$(sDataString, $zLim, 1))
END IF
CALL CheckMovieName(szFileName)
FUNCTION = 1: EXIT FUNCTION
Your comment says that wParam holds the length of the string and the code works on this assumption, but according to MSDN it holds a handle to the window passing the data
Parameters
wParam
A handle to the window passing the data.
lParam
A pointer to a COPYDATASTRUCT structure that contains the data to be passed.
Yours does work but it creates a very large string the size of handle of the calling program and then it parses it which can take a long time.
This is my sample version of your zGetPrivateMsg which I think works as a direct replacement for yours but I note that wParam is not used or needed, but I put it in this sample to make it a drop in replacement for yours
FUNCTION zGetPrivateMsg(BYREF sPrivateMsg AS STRING, BYVAL wParam AS LONG, BYVAL lParam AS LONG) AS LONG
local pRecData AS CopyDataStruct POINTER
pRecData = lParam
REDIM Buf(@pRecData.cbData) AS BYTE
Memory COPY @pRecData.lpData, VARPTR(buf(0)), @pRecData.cbData
sPrivateMsg = PEEK$(VARPTR(buf(0)), @pRecData.cbData)
FUNCTION = @pRecData.dwData
END FUNCTION
Here is your original just for easy comparison
FUNCTION zGetPrivateMsg(BYREF sPrivateMsg AS STRING, BYVAL wParam AS LONG, BYVAL lParam AS LONG) AS LONG
LOCAL cds AS COPYDATASTRUCT
REDIM Buf(wParam) AS BYTE
CALL MoveMemory(cds, BYVAL lParam, SIZEOF(cds))
CALL MoveMemory(buf(0), BYVAL cds.lpData, cds.cbData)
sPrivateMsg = PEEK$(VARPTR(buf(0)), wParam)
FUNCTION = cds.dwData
END FUNCTION
Make I take this opportunity to say how much I admire some of you work - you are very talented and creative.
I would still love to do it with Com but the CopyData message will have to do for now
Jon