Heap crash accessing clipboard via DLL using OpenEdge

Status
Not open for further replies.
U

user3270728

Guest
I need to pass a string longer than 32/64KiB to the clipboard from my program and since the built in CLIPBOARD function in OpenEdge has that as a limit I have to resort to using DLL calls.

The strange thing is that everything works fine... once.. but if I try to do it twice in a program then the program crashes. I'm using OpenEdge 11.3.1.

I have tried moving things around, not emptying the clipboard (according to MS I shouldn't empty, but without emptying it doesn't work), changing the OpenClipboard function to use CURRENT-WINDOW:HWND instead of 0 and nothing changes.

As I said everything works fine once and the clipboard is filled with my text.. but if I try to OpenClipboard again the same program then it crashes without fail.

If I comment out just the single line with the SetClipboardData function then it doesn't crash, so the problem isn't opening and closing the clipboard multiple times but something with the memory pointers.

I tried adding a GlobalUnlock but that made no difference.

Anyone have any ideas? My actual code has more error checking but this is a stripped down version that behaves exactly the same.

/* Clipboard Crash Test */

PROCEDURE OpenClipboard EXTERNAL 'user32.dll':
DEFINE INPUT PARAMETER hWndNewOwner AS LONG NO-UNDO.
DEFINE RETURN PARAMETER lRet AS LONG NO-UNDO.
END PROCEDURE.

PROCEDURE CloseClipboard EXTERNAL 'user32.dll':
DEFINE RETURN PARAMETER lRet AS LONG NO-UNDO.
END PROCEDURE.

PROCEDURE EmptyClipboard EXTERNAL 'user32.dll':
DEFINE RETURN PARAMETER lRet AS LONG NO-UNDO.
END PROCEDURE.

PROCEDURE SetClipboardData EXTERNAL 'user32.dll':
DEFINE INPUT PARAMETER uFormat AS LONG NO-UNDO.
DEFINE INPUT PARAMETER hMem AS LONG NO-UNDO.
DEFINE RETURN PARAMETER uRet AS LONG NO-UNDO.
END PROCEDURE.

DEFINE VARIABLE iRet AS INT64 NO-UNDO.
DEFINE VARIABLE mRet AS MEMPTR NO-UNDO.
DEFINE VARIABLE lRet AS LOGICAL NO-UNDO.
DEFINE VARIABLE cText AS LONGCHAR NO-UNDO.

ASSIGN cText = 'Text'.

RUN OpenClipboard(0, OUTPUT iRet).
RUN EmptyClipboard(OUTPUT iRet).
SET-SIZE(mRet) = LENGTH(cText,'RAW') + 1.
PUT-STRING(mRet,1) = cText.
RUN SetClipboardData(1, GET-POINTER-VALUE(mRet), OUTPUT iRet).
SET-SIZE(mRet) = 0.
RUN CloseClipboard(OUTPUT iRet).

MESSAGE "This next line crashes the program" VIEW-AS ALERT-BOX.

RUN OpenClipboard(0, OUTPUT iRet).
RUN CloseClipboard(OUTPUT iRet).

Continue reading...
 
Status
Not open for further replies.
Top