Platform SDK Shell >> Create file from clipboard data.

by Willy van Vroenhoven » Tue, 26 Apr 2005 18:00:53 GMT

Hello,

Is there a way to create a file from the data on the clipboard.

In the Windows Explorer resultpane there is a "Paste" option. This
menuoption is available or grayed out depending on the content of the
clipboard.
If the menuoption is available a new file is created and the content of the
clipboard is written to the new file. The filename is extracted from the
clipboard data. If the filename is not found then a default filename is
used.

I would like to create a COM wrapper that implements the following
function.(pseudocode)

Public Function SaveClipboardData(Byval FolderPath as string, Byval FileName
as string) as Boolean
Dim FullFileName as String
Dim FileExtension as String

If (data on the clipboard contains an object that can be pasted as a
file)then
FileExtension = Get file extension from clipboard data
FullFileName = FolderPath & "/" & FileName & "." & FileExtension

Create a new file
Write the data from the clipboard to the file
Close the file

SaveClipboardData = True
Else
SaveClipboardData = False
End If

End Function

Is it possible to implement this function with the use of VB 6?

Kind Regards

Willy van Vroenhoven




Platform SDK Shell >> Create file from clipboard data.

by Jim Barry » Tue, 26 Apr 2005 19:22:11 GMT





You can paste files on the clipboard to anywhere you want using ShellExecuteEx, like this:

SHELLEXECUTEINFO info = {sizeof(info)};
info.fMask = SEE_MASK_INVOKEIDLIST;
info.lpFile = _T("c:\\wherever");
info.lpVerb = _T("Paste");
ShellExecuteEx(&info);

I leave the translation to VB as an exercise for the reader ;-)

--
Jim Barry, MVP for Windows SDK



Platform SDK Shell >> Create file from clipboard data.

by Willy van Vroenhoven » Tue, 26 Apr 2005 21:09:19 GMT

Hi Jim,

I have tried to translate your example to VB with the following result

Option Explicit

Private Declare Function ShellExecuteEx Lib "shell32.dll" (ShellExExInfo As
SHELLEXECUTEINFO) As Long

Const SEE_MASK_INVOKEIDLIST = &HC

Private Type SHELLEXECUTEINFO
cbSize As Long
fMask As Long
hwnd As Long
lpVerb As String
lpFile As String
lpParameters As String
lpDirectory As String
nShow As Long
hInstApp As Long
lpIDList As Long
lpClass As String
hkeyClass As Long
dwHotKey As Long
hIcon As Long
hProcess As Long
End Type

Private Function SaveClipboardData(Byval Filename as String) as Long
Dim ShInfo As SHELLEXECUTEINFO

With ShInfo
.fMask = SEE_MASK_INVOKEIDLIST
.lpFile = Filename
.lpVerb = "Paste"
End With

SaveClipboardData = ShellExecuteEx(ShInfo)
Debug.print Err.LastDllError
End Sub

If I call the function however I keep receiving a 0 as result and the
lastDllError in de debug window is 5.

What am I doing wrong.

Greeting,
Willy van Vroenhoven






You can paste files on the clipboard to anywhere you want using
ShellExecuteEx, like this:

SHELLEXECUTEINFO info = {sizeof(info)};
info.fMask = SEE_MASK_INVOKEIDLIST;
info.lpFile = _T("c:\\wherever");
info.lpVerb = _T("Paste");
ShellExecuteEx(&info);

I leave the translation to VB as an exercise for the reader ;-)

--
Jim Barry, MVP for Windows SDK




Create file from clipboard data.

by Timo Kunze » Tue, 26 Apr 2005 21:26:39 GMT

Willy van Vroenhoven schrieb:
You didn't translate this line:
SHELLEXECUTEINFO info = {sizeof(info)};

Try ".cbSize = LenB(ShInfo)". Also the String members of your
SHELLEXECUTEINFO may cause trouble. If they do, change them to Long and
pass string pointers instead of plain strings.

HTH
Timo
--
www.TimoSoft-Software.de - the home of ExplorerTreeView
Stop software patents!