get file path to image loaded on clipboard

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).
ray_marikAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mccarlIT Business Systems Analyst / Software DeveloperCommented:
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ray_marikAuthor Commented:
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.
mccarlIT Business Systems Analyst / Software DeveloperCommented:
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?
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

ray_marikAuthor Commented:
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.
ray_marikAuthor Commented:
I've requested that this question be deleted for the following reason:

No solution offered, cannot be done.
mccarlIT Business Systems Analyst / Software DeveloperCommented:
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?
ray_marikAuthor Commented:
"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.
mccarlIT Business Systems Analyst / Software DeveloperCommented:
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?
ray_marikAuthor Commented:
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).
mccarlIT Business Systems Analyst / Software DeveloperCommented:
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.
mccarlIT Business Systems Analyst / Software DeveloperCommented:
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.
ray_marikAuthor Commented:
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.
mccarlIT Business Systems Analyst / Software DeveloperCommented:
> 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.
ray_marikAuthor Commented:
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.