GlobalAlloc verursacht einen Programmstop (Fehler)
Paula
Gesendet: 26.07.24 20:48
Betreff: GlobalAlloc verursacht einen Programmstop (Fehler)


Regular

Beiträge: 50
2525

Hallo!
Ich finde den Grund nicht warum mein Programm bei Access 2010 (leider finde ich keine Versionsnr.) hier abbricht und bei meinen Rechner (PC und Notebook) mit Access 2019 tadellos läuft.
Um was gehts:
Um Text in die Zwischenablage kopieren zu können, habe ich mir eine Routine aus dem Internet "geklaut"

#If Win64 Then
Declare PtrSafe Function GlobalUnlock Lib "kernel32" (ByVal hMem As LongPtr) As Long
Declare PtrSafe Function GlobalLock Lib "kernel32" (ByVal hMem As LongPtr) As LongPtr
Declare PtrSafe Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As LongPtr
Declare PtrSafe Function CloseClipboard Lib "user32" () As Long
Declare PtrSafe Function OpenClipboard Lib "user32" (ByVal hWnd As LongPtr) As Long
Declare PtrSafe Function EmptyClipboard Lib "user32" () As Long
Declare PtrSafe Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, ByVal lpString2 As Any) As LongPtr
Declare PtrSafe Function SetClipboardData Lib "user32" (ByVal wFormat As Long, ByVal hMem As LongPtr) As LongPtr
#End If

Public Const GHND = &H42
Public Const CF_TEXT = 1
Public Const MAXSIZE = 4096

Function Inzwischenablage(MyString As String)
Dim hGlobalMemory As LongPtr, lpGlobalMemory As LongPtr
Dim hClipMemory As LongPtr, X As Long
hGlobalMemory = GlobalAlloc(GHND, Len(MyString) + 1) 'hier stoppt das Programm (????)
lpGlobalMemory = GlobalLock(hGlobalMemory)
lpGlobalMemory = lstrcpy(lpGlobalMemory, MyString)

If GlobalUnlock(hGlobalMemory) <> 0 Then
MsgBox "Speicherplatz konnte nicht entsperrt werden. Kopie abgebrochen."
GoTo OutOfHere2
End If
If OpenClipboard(0& = 0 Then
MsgBox "Die Zwischenablage konnte nicht geöffnet werden. Kopieren abgebrochen."
Exit Function
End If

X = EmptyClipboard()
hClipMemory = SetClipboardData(CF_TEXT, hGlobalMemory)

OutOfHere2:
If CloseClipboard() = 0 Then
MsgBox "Zwischenablage konnte nicht geschlossen werden."
End If
End Function


Wenn ich das Programm auf meinen Computer laufen lasse klappt es vorzuüglich, nicht aber auf einem PC mit A 2010

Die Fehlermeldung lautet das die Variable unbekannt sei!

Bei mir läuft Win 10 Pro und Win11, am fremden PC Win 10 Enterprise

Kann mir wer einen Tipp geben, wie ich das hinbekomme?

PS: Sorry, wenn ich zuviel Listing gesendet habe!!

 

Paula



Edited by Paula 26.07.24 18:52
Top of the page Bottom of the page