Solved

get file path to image loaded on clipboard

Posted on 2012-03-13
16
525 Views
Last Modified: 2012-06-21
How do I get local or actual file path to an image of type CF_BITMAP, CF_DIB, CF_TIFF, and CF_ENHMETAFILE currently loaded on the clipboard? I know how to get the actual image but I need to know the file path (If CF_HDROP is not specified as a loaded file type).
0
Comment
Question by:ray_marik
  • 7
  • 7
16 Comments
 
LVL 35

Accepted Solution

by:
mccarl earned 500 total points
ID: 37717918
I would think that you can't. If the type is one of those CF_BITMAP, etc. then it is ONLY the image data that is on the clipboard, not the file. Hence, there is no file name there for you to retrieve.
0
 

Author Comment

by:ray_marik
ID: 37718092
Well, if it's CF_BITMAP and CF_HDROP loaded, there's a filename you can retrieve, so I would think you could retrieve a file name from other formats also loaded on clipboard along with CF_BITMAP, for example, OLE PRIVATE DATA or UniformResourceLocatorDataW.
0
 
LVL 35

Expert Comment

by:mccarl
ID: 37718107
You said in the original post that
If CF_HDROP is not specified as a loaded file type
so that's what I was assuming.

How are these items getting on to the clipboard? Are you talking about, eg. hitting Ctrl+C on an image file in the filesystem? Or otherwise?
0
 

Author Comment

by:ray_marik
ID: 37720120
What I was referring to is that a number of formats are loaded each time, not just what you normally would expect, ie for an image CF_BITMAP is specified but also something like CF_HDROP and a load of others.
Nevermind though, I guess it can't be done.
0
 

Author Comment

by:ray_marik
ID: 37726405
I've requested that this question be deleted for the following reason:

No solution offered, cannot be done.
0
 
LVL 35

Expert Comment

by:mccarl
ID: 37723297
Nevermind though, I guess it can't be done.

While that may well be he final outcome, but I hadn't really finished working this through with you. Are you able to answer the question that I asked?

How are these items getting on to the clipboard? Are you talking about, eg. hitting Ctrl+C on an image file in the filesystem? Or otherwise?
0
 

Author Comment

by:ray_marik
ID: 37723306
"How are these items getting on to the clipboard? Are you talking about, eg. hitting Ctrl+C on an image file in the filesystem? Or otherwise?"

Right click, then copy.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 35

Expert Comment

by:mccarl
ID: 37723318
Right click, then copy.

But in what context? Right click on a file in the filesystem? Richt click on an image on a webpage? In a particular program, such as Word, Excel?
0
 

Author Comment

by:ray_marik
ID: 37724862
Right clicking on images inside IE and loading to clipboard is the problem. I thought that was implied bec/ right clicking inside Win Explorer just passes the file as CF_HDROP, (in other words drag and drop and not of type CF_BITMAP).
0
 
LVL 35

Expert Comment

by:mccarl
ID: 37726383
Ok, yeah, I was just making sure that that is the case before saying this...

I guess it can't be done

True, but not because of some limitation of the code or the clipboard, but simply because there is no file path to retrieve! Images in a browser are just image data retrieved from a URL, and they are at no point a file in the filesystem.
0
 
LVL 35

Expert Comment

by:mccarl
ID: 37726406
Moderators,

I don't believe that this should be deleted. I agree that there was no solution, but there is still a correct answer, "that there is no file path to retrieve". I believe that that is still worthy of an answer being accepted, and points awarded.
0
 

Author Comment

by:ray_marik
ID: 37726902
There IS a file path to retrieve:

"Right clicking on images inside IE and loading to clipboard" should give a path and a file name leading to the original image inside the IE temp folder. That's how IE retrieves the images. We can argue till the cows come home but there is a file path and name to retrieve.
0
 
LVL 35

Expert Comment

by:mccarl
ID: 37727249
> the original image inside the IE temp folder

What makes you think there is a physical file in the temp folder? Are talking about when you go to C:\Documents and Settings\XXXXX\Local Settings\Temporary Internet Files and you see entries in there for all the cached items, such as images, etc? That is just Windows trying to confuse you, it is presenting the browsers cahced items as though they are files but they aren't actually stored on the disk as files (I not saying that the info is not on the hard drive somewhere, just not as files and not in that directory). It is a view that Windows is making it "look" like there are physical files.

Here is some simple test code to illustrate my point... (go to your view of your Temporary Internet Files directory and pick out a file, put the path to that file as the constructor arg for file2, and put a path to a known file outside of the Temporary Internet Files directory for file1)

import java.io.File;
import java.io.IOException;

public class TestTemporaryInternetFileRetrieval {
	public static void main(String[] args) throws IOException {
		File file1 = new File("C:\\Documents and Settings\\XXXXX\\Local Settings\\test.txt");
		File file2 = new File("C:\\Documents and Settings\\XXXXX\\Local Settings\\Temporary Internet Files\\blank.gif");
		
		System.out.println("file1 exists: " + file1.exists() + " (" + file1.getAbsolutePath() + ")");
		System.out.println("file2 exists: " + file2.exists() + " (" + file2.getAbsolutePath() + ")");
	}
}

Open in new window


You should see that the file outside Temporary Internet Files "exists" and the one inside doesn't, ie. they aren't real files that can be accessed by a file path.
0
 

Author Comment

by:ray_marik
ID: 37727669
IE caches image files inside temp folder for easier access later, that's the whole point.

In fact, back to the point I made in the second comment, assuming that CF_BIMAPT AND CF_HDROP are BOTH specified as loaded clipboard formats, then you can retrive the complete path to the image that points to the IE temp internet file. I have this code and it works as expected.

But what I was trying to do was get image path back to this IE temp folder assuming CF_BITMAP is specified but CF_HDROP is not, which is what happens with some images.

What I've ended up doing here is explain more to you than it's worth to me and my time. Judging by the Java code you cite for a C/C++ question and the fact you keep arguing to win 500 points, I'm led to believe that you do not understand clipboard and its formats and so I'm going to asks the moderators again to delete this question. You have not posted a solution and you do not deserve any points. Good day.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now