|
Are you closing both the input and output streams after each file? It's possible that you're using the maximum amount of remote, open file handles (not sure about this, though). A good way to develop your IO code is to use a try-catch-finally block like so:
Stream inStream = null;
String outStream = null;
try
{
inStream = open image file;
outStream = create output image file;
}
catch (Exception e)
{
}
finally
{
if (inStream != null) inStream.Close();
if (outStream != null)
{
outStream.Flush();
outStream.Close();
}
} The finally block is always executed - even if you return (or transfer control out of your block another way) from your try or catch block. The only time the finally block is NOT executed is when you use Environment.Exit , which unloads the CLR unconditionally.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Just working on the Drag drop problem now, i've looked back over your post and I'm slightly unclear on some things.
Firstly, you said all I needed to do was pack up the object data in .NET using a windows recognised format, which makes sense. But then you say that to send a pointer to a stream I need to use the win32 IObjectData and platform invoke a number of methods.
I'm actualy not sure which is the best option. The desired effect is to create an object with <name>.<extention> and the object data internal to it.
I've discovered the IDataObject in COM, which I have not even looked at, and do not even know what it is. I shall look at COM, but what do I have to do to set up an application to use it?
Can you give me some pointers as to which direction I should be heading now?
I really think I need the source code and documentation for all the shell objects too...
Cata
|
|
|
|
|
The_Catalyst wrote:
I really think I need the source code and documentation for all the shell objects too...
Take a look at the source Tool for viewing Drag and Drop and Clipboard formats[^], at least until Heath can read your post.
-Nick Parker
Last time I checked, all programmers have selective ignorance. I know nothing about 3D graphics. I know a lot about COM. VB gets under people's skin because one can be ignorant of computer architecture and ASM and still get a lot done. - Don Box
|
|
|
|
|
I don't need to do that, I can read them all by putting a break point in and looking at the e.Data() object in the variable viewer in .NET.
I've got no problems with D'n'D, got it all working internaly, and from desktop into program. The problem is interfacing with the API to pass a handle to a stream to the OS so that I can make a file.
I could do it so that I right click on something and open and export dialog box, but i'm one of those stubborn b*****ds that wants things "just so" and won't rest until it's done.
(btw, I intend to know a lot about everything... it's all fascinating to me, just wish i had started programming when I was fifteen, instead of early last year )
Cata
|
|
|
|
|
You don't need the source to any of the COM classes, and all the interfaces are defined either in IDL or header files. Rather than downloading and installing the Platform SDK (or, it can also be installed - and is by default - with VS.NET, though this is an older version but contains what you need), you can look at the definition for the IDataObject interface from MSDN. You'll need to create the interfaces and structs I mentioned in the previous thread.
You just need to create those interface in .NET, using the same signatures (marshaling when necessary). Several attributes - including StructLayoutAttribute and MarshalAsAttribute in the System.Runtime.InteropServices namespace can help you. If you know anything about IDL, you can also create an IDL file that contains forward declarations for the interfaces and struct you need. You compile that IDL file to a TLB (see the documentation for the midl.exe compiler, which is part of the Platform SDK), then use tlbimp.exe (part of the .NET SDK) to import the typelib to a .NET interop assembly. That'll save you from having to define the interfaces from scratch.
Implement COM's IDataObject in a class and pack your information in that. A decent understand of COM is practically necessary to accomplish this.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
This is so far over my head it's unreal. I could really use some example code if you have any.
In the mean time, I will have to begin looking at COM, and finding out what IDL is.
I really have no idea what these executables are, or much of anything else.
I always find it easier to learn something when I know some of the ground work, but this... I have never touched on any of it before.
I will begin a systematic look at what you have given me so far, but as I said, any source code you could provide as an example (working or not), would be greatly appreicated on this matter.
One question I have is, how do I set the IDataObject to the object that is being portrayed by the mouse event, once I have constructed one? I think I can manage the interfaces and structures, but it will take a while.
Cheers for the help
Cata
|
|
|
|
|
I don't have any examples to give you, but as far as packing information for the selected control, just get the control that is passed as the sender for the MouseUp or MouseDown command. It will probably be easiest if you set a boolean flag in the MouseDown event, then in the MouseMove event do the drag-n-drop code if the boolean flag is set. In the MouseUp event, reset the boolean flag so that just passing over the control with the mouse doesn't begin a drag operation. Understand how drag and drop works will definitely help.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
That is exactly how I made my first drag and drop feature, before I learned about the drag / drop methods. Well, almost exactly.
I had a "CarryingItem" boolean, or something, this was a few months ago.
But that doesn't help with asigning a different type of IDataObject to the drag event. Can I just declare the object that I am dragging as IDataObject?
<br />
DragDropEffects dragArgs <br />
= DoDragDrop(dragData, DragDropEffects.All);<br />
where dragData is the customised IDataObject.
Or will this object just be packed into a conventional C# IDataObject, and still be rendered useless outside the C# enviroment?
I know how Drag and Drop works in the C# enviroment, but not in the native windows, is that what I need to understand?
Cata
|
|
|
|
|
Like I said in a previous post, you have to implement Win32's IDataObject and use that class. You'll have to P/Invoke DoDragDrop also, since .NET's method refers to the .NET IDataObject interface.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Right, I've looked at the methods and structures in COM, and I believe I can produce some managed counterparts with a little more work. The list of what I need follows:
Unmanaged Side:
Structures / Objects / methods:
1) Construct Managed IdropSource
2) Construct Managed FORMATETC structure
3) Construct Managed STGMEDIUM structure
4) Construct Managed IDataObject COM Object (All methods? Or only those that I will require?
5) Construct Managed DoDragDrop COM Object
Then, I will need to implement this in my C# enviroment, however, I'm not sure about handling these methods I have created, they strike me as one side managed, as in, the side that is transmitting is managed, but the recieving side (which in theory could be my own form) would not be, and this could cause some issues.
So I am looking at two possibilities as far as I understand. Now, while the first one looks easier, i am not sure it can actualy be done, when the mouse leaves form1, it could just enter a sub container / panel or whatever. So I am guessing I will have to implement the second one.
C# Side:
Options:
1) Construct C# DragDrop for internal drag and drop operations, and add Event upon mouse leaving the Form1 enviroment to switch the IdataObject to the managed COM version.
2) Use managed COM version of DragDrop method to begin with, and handle the COM functionality when dropped into other containers within the Form1 enviroment.
3) Any others?
Are there any other structures I will need to construct or handle? Will i need to handle the DragEnter and DragLeave events in COM and implement them in my form to use the second method, or can i leave them unhandled and let the OS take care of things? And are there any other options I am overlooking on the implementation side?
Thanks again Heath
Cata
(Maybe when i get this working I'll post some code and make it easy for everyone )
|
|
|
|
|
Why COM? I don't know extactly what he's doing here, but usually .NET's built-in DataObject[^](which implements IDataObject) works just fine. For example, to drag the file "c:\test.txt", you can do:
DataObject data=new DataObject();
data.SetData(DataFormats.FileDrop,new string[]{@"c:\test.txt"});
controlobject.DoDragDrop(data,DragDropEffects.All);
|
|
|
|
|
Spoke too soon. I looked farther down and found out that he needs to do a data stream.
|
|
|
|
|
Well If I could drop an object that the OS recognises and can convert to a file, that would work too...
It just makes more sense to use a stream as that seems to be the way apps communicate, and it requires minimal casting. A file drop should work fine. Please tell me more.
Cata
|
|
|
|
|
I tried to play with it, but I get the error:
"Cannot move file: Cannot read from then source file or disk"
So i take it, that my C# app is not compatible with windows.... or... something... *tired*
Will try tomorrow, but I think i'm going down with a severe case of man flu (runny nose = imobalisation for weeks, fatigue, and a life saving labotamy)
Cheers
Cata
|
|
|
|
|
The_Catalyst wrote:
I tried to play with it, but I get the error:
"Cannot move file: Cannot read from then source file or disk"
Umm... maybe you don't have a "c:\test.txt"?* Or did you forget to make it be @"c:\test.txt" or "c:\\test.txt"?
*I always have a "c:\test.txt" because that's such a convenient test filename.
|
|
|
|
|
I guess it's as Heath says, this won't work for me.
Oh well... time to go the hard way
Cata
|
|
|
|
|
Well, there's a number of different things you can do, provided that you have control of the application it's dropped to. Whether you have that control or not, I would have to have more details about what the circumstances are - what's being dragged and dropped, and to where, etc.
|
|
|
|
|
He wants to use an IStream that is a COM object so that the shell understands it. The IDataObject interface in .NET is much different than the IDataObject that is defined in objidl.h. The internals of how the .NET version is "marshaled" to the COM version is hidden in the System.Windows.Forms assembly (if memory serves me correctly), and it does basically what I've been telling Cata to do.
To my knowledge and from experience, the above code only sends filenames so the shell copies or moves those filenames (based on the allowed action). This person wants to know what the drop target is and apparently wants to do something when the target starts accessing the file(s). The only good way I could think of - since there aren't any notification interfaces I could find (in all my research and development with COM over the last many years) - was to use a stream because Cata would then know when the target was attempting to access the files.
If there is a better way to get notification that the object has been dropped (like, before the targets starts accessing the data object), I'm all ears. I've been looking for a solution for a couple years to this specific problem - even googling for discussions or samples - and have never found a good solution.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Sorry, didn't see your reply to yourself (I just use the emails I get to jump right to the topic and yours was off the screen.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Heath, I've got a lot of things I want to do.
But yeah, i'd like to be able to drag an object from my listview, which will then produce the drag drop object from the data associated with the listview object that is dragged.
That is the simple part, as I can do it. But to get outside... there is where the real challenge is
I might even have to change the way I store the information in my program, which is a simple structure with Name, Type (File Extention), Data (the object). That's the thing i've packed up.
I'll look to basicaly write the object data to disk via the stream, and callit: <name>.<extention>
Then, when reversed, I can simply disect the file name back to my format, and drop the object data into my ObjectData object.
At least, that's the plan.
Cata
|
|
|
|
|
Hi,
How can I create from the outlook bar written in C++ by Dheth a control witch I can directly use in C#?
See: http://www.codeproject.com/miscctrl/outbar2.asp?target=outlook
Thanks in advance.
Gaby
|
|
|
|
|
Gaby,
I would suggest that you take a look at Marc Clifton's article: An Outlook Bar Implementation[^] written in C#, it is truely a great article from the ground up.
-Nick Parker
VB gets under people's skin because one can be ignorant of computer architecture and ASM and still
get a lot done. -Don Box
|
|
|
|
|
Hi,
Is there a simple way to print the current form to the default printer? I am working on a project for school and want to use a button on my form which does a "print screen"
|
|
|
|
|
Please search the comments for this forum. I just gave some advice to one person a few days ago about this. Basically, it's not very easy at all on C# but I gave some function reference that you should know and understand. The tips are there, but you have to figure out the solution. Besides, obviously, this is a homework question and we don't answer those in this - or any other - forum on CP. We'll give you tips and help if you're having a specific problem though.
It's just not right, and you won't learn anything by being given the answer.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I think there needs to be a message added to this board advising people to search the message board before posting and also trying msdn or google.
|
|
|
|
|