GetClipboardData always returns NULL
I have the following code:
Public Declare Function GetClipboardData Lib "user32" (ByVal wFormat As Long) As Long
Public Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function CloseClipboard Lib "user32" () As Long
Sub test()
Dim wat As String
OpenClipboard (0&)
wat = GetClipboardData(CF_TEXT)
MsgBox wat
CloseClipboard
End Sub
This always returns 0 (NULL) in the msgbox. Could somone tell me what is wrong with this code?
vba clipboard api
|
show 1 more comment
I have the following code:
Public Declare Function GetClipboardData Lib "user32" (ByVal wFormat As Long) As Long
Public Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function CloseClipboard Lib "user32" () As Long
Sub test()
Dim wat As String
OpenClipboard (0&)
wat = GetClipboardData(CF_TEXT)
MsgBox wat
CloseClipboard
End Sub
This always returns 0 (NULL) in the msgbox. Could somone tell me what is wrong with this code?
vba clipboard api
I would presume the problem is your call toOpenClipboard
, what boolean value does it return? Edit your question to include this vital information
– Ramhound
Jan 7 at 12:18
@Ramhound how would I know that (in the sense how do I verify that)?
– Noir
Jan 7 at 12:26
The same way you verified the other method was returning 0. Use a variable to capture the return value.
– Ramhound
Jan 7 at 12:40
@Ramhound doesn't seem to be the brightest of days for me. Indeed I can confirm that the Boolean is 1.
– Noir
Jan 7 at 12:43
@Ramhound I think the code does actually work, it just doesn't return what I would expect it to. If the clipboard is empty, it returns 0, if it is not empty it returns a seemingly random number of integers (e.g. "*" returns 791549112). I would have expected it does return the actual copied text.
– Noir
Jan 7 at 12:56
|
show 1 more comment
I have the following code:
Public Declare Function GetClipboardData Lib "user32" (ByVal wFormat As Long) As Long
Public Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function CloseClipboard Lib "user32" () As Long
Sub test()
Dim wat As String
OpenClipboard (0&)
wat = GetClipboardData(CF_TEXT)
MsgBox wat
CloseClipboard
End Sub
This always returns 0 (NULL) in the msgbox. Could somone tell me what is wrong with this code?
vba clipboard api
I have the following code:
Public Declare Function GetClipboardData Lib "user32" (ByVal wFormat As Long) As Long
Public Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function CloseClipboard Lib "user32" () As Long
Sub test()
Dim wat As String
OpenClipboard (0&)
wat = GetClipboardData(CF_TEXT)
MsgBox wat
CloseClipboard
End Sub
This always returns 0 (NULL) in the msgbox. Could somone tell me what is wrong with this code?
vba clipboard api
vba clipboard api
asked Jan 7 at 12:14
NoirNoir
434
434
I would presume the problem is your call toOpenClipboard
, what boolean value does it return? Edit your question to include this vital information
– Ramhound
Jan 7 at 12:18
@Ramhound how would I know that (in the sense how do I verify that)?
– Noir
Jan 7 at 12:26
The same way you verified the other method was returning 0. Use a variable to capture the return value.
– Ramhound
Jan 7 at 12:40
@Ramhound doesn't seem to be the brightest of days for me. Indeed I can confirm that the Boolean is 1.
– Noir
Jan 7 at 12:43
@Ramhound I think the code does actually work, it just doesn't return what I would expect it to. If the clipboard is empty, it returns 0, if it is not empty it returns a seemingly random number of integers (e.g. "*" returns 791549112). I would have expected it does return the actual copied text.
– Noir
Jan 7 at 12:56
|
show 1 more comment
I would presume the problem is your call toOpenClipboard
, what boolean value does it return? Edit your question to include this vital information
– Ramhound
Jan 7 at 12:18
@Ramhound how would I know that (in the sense how do I verify that)?
– Noir
Jan 7 at 12:26
The same way you verified the other method was returning 0. Use a variable to capture the return value.
– Ramhound
Jan 7 at 12:40
@Ramhound doesn't seem to be the brightest of days for me. Indeed I can confirm that the Boolean is 1.
– Noir
Jan 7 at 12:43
@Ramhound I think the code does actually work, it just doesn't return what I would expect it to. If the clipboard is empty, it returns 0, if it is not empty it returns a seemingly random number of integers (e.g. "*" returns 791549112). I would have expected it does return the actual copied text.
– Noir
Jan 7 at 12:56
I would presume the problem is your call to
OpenClipboard
, what boolean value does it return? Edit your question to include this vital information– Ramhound
Jan 7 at 12:18
I would presume the problem is your call to
OpenClipboard
, what boolean value does it return? Edit your question to include this vital information– Ramhound
Jan 7 at 12:18
@Ramhound how would I know that (in the sense how do I verify that)?
– Noir
Jan 7 at 12:26
@Ramhound how would I know that (in the sense how do I verify that)?
– Noir
Jan 7 at 12:26
The same way you verified the other method was returning 0. Use a variable to capture the return value.
– Ramhound
Jan 7 at 12:40
The same way you verified the other method was returning 0. Use a variable to capture the return value.
– Ramhound
Jan 7 at 12:40
@Ramhound doesn't seem to be the brightest of days for me. Indeed I can confirm that the Boolean is 1.
– Noir
Jan 7 at 12:43
@Ramhound doesn't seem to be the brightest of days for me. Indeed I can confirm that the Boolean is 1.
– Noir
Jan 7 at 12:43
@Ramhound I think the code does actually work, it just doesn't return what I would expect it to. If the clipboard is empty, it returns 0, if it is not empty it returns a seemingly random number of integers (e.g. "*" returns 791549112). I would have expected it does return the actual copied text.
– Noir
Jan 7 at 12:56
@Ramhound I think the code does actually work, it just doesn't return what I would expect it to. If the clipboard is empty, it returns 0, if it is not empty it returns a seemingly random number of integers (e.g. "*" returns 791549112). I would have expected it does return the actual copied text.
– Noir
Jan 7 at 12:56
|
show 1 more comment
1 Answer
1
active
oldest
votes
GetClipboardData will deliver a handle to the global memory block.
You will have to lock this block and retrieve the String from there.
Based on windows-api/retrieve-information-from-the-clipboard a quick an dirty example based on your question:
Public Declare Function GetClipboardData Lib "user32" (ByVal wFormat As Long) As Long
Public Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function CloseClipboard Lib "user32" () As Long
Public Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Public Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
Public Declare Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, ByVal lpString2 As Any) As Long
Public Const CF_TEXT = 1
Public Const MAXSIZE = 4096
Sub test()
Dim wat As String
Dim hClipMemory As Long
Dim lpClipMemory As Long
Dim Dummy As Long
If OpenClipboard(0&) <> 0 Then
hClipMemory = GetClipboardData(CF_TEXT)
If Not IsNull(hClipMemory) Then
lpClipMemory = GlobalLock(hClipMemory)
If Not IsNull(lpClipMemory) Then
wat = Space$(MAXSIZE)
Dummy = lstrcpy(wat, lpClipMemory)
GlobalUnlock (hClipMemory)
End If
End If
MsgBox wat
CloseClipboard
End If
End Sub
Thank you @bummi. I am very new to calling the user32 and kernel32 libraries, consequently it seems I fully failed to understand how this code should have been executed. I awarded you the solution as what you posted actually does do what I would have wanted it to do. And thank you for the link I will examine the full code and documentation to get a better understanding of what is actually going on.
– Noir
Jan 7 at 13:16
@bummi.... That's an interesting website for devworx for the type of work they do and using the peppers, plants, etc. for the image work on the site. Cool, I like peppers, and especially the hot ones!!
– Pimp Juice IT
1 hour ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1391473%2fgetclipboarddata-always-returns-null%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
GetClipboardData will deliver a handle to the global memory block.
You will have to lock this block and retrieve the String from there.
Based on windows-api/retrieve-information-from-the-clipboard a quick an dirty example based on your question:
Public Declare Function GetClipboardData Lib "user32" (ByVal wFormat As Long) As Long
Public Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function CloseClipboard Lib "user32" () As Long
Public Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Public Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
Public Declare Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, ByVal lpString2 As Any) As Long
Public Const CF_TEXT = 1
Public Const MAXSIZE = 4096
Sub test()
Dim wat As String
Dim hClipMemory As Long
Dim lpClipMemory As Long
Dim Dummy As Long
If OpenClipboard(0&) <> 0 Then
hClipMemory = GetClipboardData(CF_TEXT)
If Not IsNull(hClipMemory) Then
lpClipMemory = GlobalLock(hClipMemory)
If Not IsNull(lpClipMemory) Then
wat = Space$(MAXSIZE)
Dummy = lstrcpy(wat, lpClipMemory)
GlobalUnlock (hClipMemory)
End If
End If
MsgBox wat
CloseClipboard
End If
End Sub
Thank you @bummi. I am very new to calling the user32 and kernel32 libraries, consequently it seems I fully failed to understand how this code should have been executed. I awarded you the solution as what you posted actually does do what I would have wanted it to do. And thank you for the link I will examine the full code and documentation to get a better understanding of what is actually going on.
– Noir
Jan 7 at 13:16
@bummi.... That's an interesting website for devworx for the type of work they do and using the peppers, plants, etc. for the image work on the site. Cool, I like peppers, and especially the hot ones!!
– Pimp Juice IT
1 hour ago
add a comment |
GetClipboardData will deliver a handle to the global memory block.
You will have to lock this block and retrieve the String from there.
Based on windows-api/retrieve-information-from-the-clipboard a quick an dirty example based on your question:
Public Declare Function GetClipboardData Lib "user32" (ByVal wFormat As Long) As Long
Public Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function CloseClipboard Lib "user32" () As Long
Public Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Public Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
Public Declare Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, ByVal lpString2 As Any) As Long
Public Const CF_TEXT = 1
Public Const MAXSIZE = 4096
Sub test()
Dim wat As String
Dim hClipMemory As Long
Dim lpClipMemory As Long
Dim Dummy As Long
If OpenClipboard(0&) <> 0 Then
hClipMemory = GetClipboardData(CF_TEXT)
If Not IsNull(hClipMemory) Then
lpClipMemory = GlobalLock(hClipMemory)
If Not IsNull(lpClipMemory) Then
wat = Space$(MAXSIZE)
Dummy = lstrcpy(wat, lpClipMemory)
GlobalUnlock (hClipMemory)
End If
End If
MsgBox wat
CloseClipboard
End If
End Sub
Thank you @bummi. I am very new to calling the user32 and kernel32 libraries, consequently it seems I fully failed to understand how this code should have been executed. I awarded you the solution as what you posted actually does do what I would have wanted it to do. And thank you for the link I will examine the full code and documentation to get a better understanding of what is actually going on.
– Noir
Jan 7 at 13:16
@bummi.... That's an interesting website for devworx for the type of work they do and using the peppers, plants, etc. for the image work on the site. Cool, I like peppers, and especially the hot ones!!
– Pimp Juice IT
1 hour ago
add a comment |
GetClipboardData will deliver a handle to the global memory block.
You will have to lock this block and retrieve the String from there.
Based on windows-api/retrieve-information-from-the-clipboard a quick an dirty example based on your question:
Public Declare Function GetClipboardData Lib "user32" (ByVal wFormat As Long) As Long
Public Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function CloseClipboard Lib "user32" () As Long
Public Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Public Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
Public Declare Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, ByVal lpString2 As Any) As Long
Public Const CF_TEXT = 1
Public Const MAXSIZE = 4096
Sub test()
Dim wat As String
Dim hClipMemory As Long
Dim lpClipMemory As Long
Dim Dummy As Long
If OpenClipboard(0&) <> 0 Then
hClipMemory = GetClipboardData(CF_TEXT)
If Not IsNull(hClipMemory) Then
lpClipMemory = GlobalLock(hClipMemory)
If Not IsNull(lpClipMemory) Then
wat = Space$(MAXSIZE)
Dummy = lstrcpy(wat, lpClipMemory)
GlobalUnlock (hClipMemory)
End If
End If
MsgBox wat
CloseClipboard
End If
End Sub
GetClipboardData will deliver a handle to the global memory block.
You will have to lock this block and retrieve the String from there.
Based on windows-api/retrieve-information-from-the-clipboard a quick an dirty example based on your question:
Public Declare Function GetClipboardData Lib "user32" (ByVal wFormat As Long) As Long
Public Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function CloseClipboard Lib "user32" () As Long
Public Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Public Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
Public Declare Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, ByVal lpString2 As Any) As Long
Public Const CF_TEXT = 1
Public Const MAXSIZE = 4096
Sub test()
Dim wat As String
Dim hClipMemory As Long
Dim lpClipMemory As Long
Dim Dummy As Long
If OpenClipboard(0&) <> 0 Then
hClipMemory = GetClipboardData(CF_TEXT)
If Not IsNull(hClipMemory) Then
lpClipMemory = GlobalLock(hClipMemory)
If Not IsNull(lpClipMemory) Then
wat = Space$(MAXSIZE)
Dummy = lstrcpy(wat, lpClipMemory)
GlobalUnlock (hClipMemory)
End If
End If
MsgBox wat
CloseClipboard
End If
End Sub
answered Jan 7 at 13:06
bummibummi
1,48031422
1,48031422
Thank you @bummi. I am very new to calling the user32 and kernel32 libraries, consequently it seems I fully failed to understand how this code should have been executed. I awarded you the solution as what you posted actually does do what I would have wanted it to do. And thank you for the link I will examine the full code and documentation to get a better understanding of what is actually going on.
– Noir
Jan 7 at 13:16
@bummi.... That's an interesting website for devworx for the type of work they do and using the peppers, plants, etc. for the image work on the site. Cool, I like peppers, and especially the hot ones!!
– Pimp Juice IT
1 hour ago
add a comment |
Thank you @bummi. I am very new to calling the user32 and kernel32 libraries, consequently it seems I fully failed to understand how this code should have been executed. I awarded you the solution as what you posted actually does do what I would have wanted it to do. And thank you for the link I will examine the full code and documentation to get a better understanding of what is actually going on.
– Noir
Jan 7 at 13:16
@bummi.... That's an interesting website for devworx for the type of work they do and using the peppers, plants, etc. for the image work on the site. Cool, I like peppers, and especially the hot ones!!
– Pimp Juice IT
1 hour ago
Thank you @bummi. I am very new to calling the user32 and kernel32 libraries, consequently it seems I fully failed to understand how this code should have been executed. I awarded you the solution as what you posted actually does do what I would have wanted it to do. And thank you for the link I will examine the full code and documentation to get a better understanding of what is actually going on.
– Noir
Jan 7 at 13:16
Thank you @bummi. I am very new to calling the user32 and kernel32 libraries, consequently it seems I fully failed to understand how this code should have been executed. I awarded you the solution as what you posted actually does do what I would have wanted it to do. And thank you for the link I will examine the full code and documentation to get a better understanding of what is actually going on.
– Noir
Jan 7 at 13:16
@bummi.... That's an interesting website for devworx for the type of work they do and using the peppers, plants, etc. for the image work on the site. Cool, I like peppers, and especially the hot ones!!
– Pimp Juice IT
1 hour ago
@bummi.... That's an interesting website for devworx for the type of work they do and using the peppers, plants, etc. for the image work on the site. Cool, I like peppers, and especially the hot ones!!
– Pimp Juice IT
1 hour ago
add a comment |
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1391473%2fgetclipboarddata-always-returns-null%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I would presume the problem is your call to
OpenClipboard
, what boolean value does it return? Edit your question to include this vital information– Ramhound
Jan 7 at 12:18
@Ramhound how would I know that (in the sense how do I verify that)?
– Noir
Jan 7 at 12:26
The same way you verified the other method was returning 0. Use a variable to capture the return value.
– Ramhound
Jan 7 at 12:40
@Ramhound doesn't seem to be the brightest of days for me. Indeed I can confirm that the Boolean is 1.
– Noir
Jan 7 at 12:43
@Ramhound I think the code does actually work, it just doesn't return what I would expect it to. If the clipboard is empty, it returns 0, if it is not empty it returns a seemingly random number of integers (e.g. "*" returns 791549112). I would have expected it does return the actual copied text.
– Noir
Jan 7 at 12:56