|
For one, you don't need to ref the IDropTarget in RegisterDragDrop - it's already a reference Type so passing an instantiated instance. This could be one of the problems.
Second, in your IDropTarget , are you using the IDataObject defined in the .NET base class library, or an interop'd one that you'd have to define like you are with IDropTarget . Though the OLE interfaces are used internally by .NET, the IDropTarget interfaces are vastly different.
As far as the error, returning int should be no problem. An HRESULT is a 32-bit signed integer. Preserving the signatures of all the IDropTarget methods isn't necessary, either. This really is only helpful if you need to return a success code that isn't S_OK (0). Even in this case, though, you can always throw a COMException with the error code (or success code), which is the correct way (at least for errors). This can provide additional information to the caller if they support IErrorInfo . This behavior is provided in part by the CLR.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks Heath,
1.I have started without ref in the IDropTarget didnot help.
2.Have defined the IdataObject locally in the file as [ComImport(),ComInterface]
3.My actual problem is compilation error at static extern int<- RegisterDragDrop
changing the retcode to void,enum etc is not changing the error.
Even DllImport("ole32.dll",PreserveSig=false"} still gives the same error at
the same place.
hope i have explained the problem. Appreciate your help anyway. thanks again
|
|
|
|
|
Regardless of whether or not the ref was a problem, it still shouldn't be there. Now, if this was a pointer to a pointer (i.e., IDropTarget **), then you should use ref . A pointer to a value type (i.e., numeric, boolean, byte, char, struct, enum) would require ref or out .
As far as the error goes, let me introduce you to ildasm.exe - the IL disassembler that comes with the .NET Framework SDK. As I mentioned before - and which should be evident since .NET supports drag-n-drop with native Windows - .NET uses the OLE drag-n-drop internally. Logically, you should think to look into the assembly that would use it (just trying to introduce a thought process here). Logically, this is in the System.Windows.Forms.dll assembly.
So, run ildasm.exe and open that assembly (or use something like .NET Reflector). Find the UnsafeNativeMethods class (typical name in base class libraries). There'll you'll find the defnition used by Microsoft (which obviously works). you'll also find reference to IOleDropTarget , which is what they use internally for IDropTarget (the name doesn't matter - only the IID and methods / dispids depending on inheritence). If ever you have problems determining how something should be defined, changes are that the base class libraries are using them internally somewhere.
The method should be defined as:
[DllImport("ole32.dll", CallingConvention=CallingConvention.Winapi)]
static extern int RegisterDragDrop(HandleRef hWnd, IOleDropTarget target); See nested interfaces for definitions of the interfaces, too. They use "Ole" in the interface name and prefix the method names with it (to help distinguish it from implementations), but it doesn't matter so long as the vtable order for IUnknown-inherited interfaces and DISPIDs for IDispatch-inherited interfaces remain the same (for dual interfaces, both order and DISPIDs should be the same).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks Heath.
You have been helpful, I would follow your advice. Thanks again..
|
|
|
|
|
Hi, I am trying to use ILAsm and ILDasm inside an application and I need to be able to run the programs and intercept any errors and/or output that they create. Are there FxCL classes to do this or is there another way? (I'm using C#). I searched around on the articles on the site but couldn't find anything relating to this. Maybe I just don't have the right keywords. Any links or advice would be great. Thanks.
-Noah Fields
|
|
|
|
|
Take a look at the System.Diagnostics namespace, especially the Process and ProcessStartInfo classes.
Searching for those two classes on the net should lead you to lots of examples on how to start applications and redirect their output to yourself.
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|
|
Great! thanks for your help
|
|
|
|
|
is dataset and recordset the same thing? how r they different?
CODER
|
|
|
|
|
A DataSet is a disconnected recordset. All the data is contained in the DataSet so you don't need to fetch from the server again. This makes serialization (either to a file or for Web Services / Remoting) easy, as well as using diffgrams (change records in a DataSet ) to update a data source using a DataAdapter ( or handling it yourself ).
See the section on ADO.NET in the .NET Framework SDK for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hello all,
Its a well known fact that Panels in ASP.NET can be controlled using <asp:linkbutton> control. My questions is if we could control those same Panels using the <asp:radiobutton> control.
Now this should be done in this way:
1. Lets say there are 4 RadioButtons(of the same group) and 4 corresponding panels.
2. User chooses a RadioButton.
3. The corresponding panel opens up.
NOT in this way:
1. There are 4 RadioButtons(of the same group), 4 corresponding panels and a regular button.
2. User chooses a RadioButton.
3. User clicks on the regular button (lets say its the "Submit" button).
3. The corresponding panel opens up.
Any input is appreciated.
Regards,
Tiruvan
|
|
|
|
|
This has little to nothing to do with ASP.NET - this requires client-side scripting. ASP.NET is a service that runs on the server. Without fetching a new page, ASP.NET isn't involved (this is the nature of HTTP). You can generate a class that exhibits this behavior by emiting a script that reacts to the 4 radio buttons and uses scripting and CSS styles to show and hide the panels (all of which must be written to the HTML writer) appropriately.
Fortunately, Microsoft has already unofficially done this. See the Microsoft IE WebControls at http://www.asp.net/ControlGallery/default.aspx?Category=38&tabindex=2[^]. The MultiPage and TabStrip controls are what you would want.
BTW, this question would be more appropriate in the ASP.NET forum.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I've got an annoying problem happening. I'm trying to design my user interface and I've got various controls which dock this way and that, and when i compile and run the app, while the window resizes smoothly, the controls that should be sizing to match the window size seem to trying to snap to an invisible grid as they go, which means the distance between the edge of the control and the border of the window keeps changing when the window is resized. It doesn't affect the functionality of course, but it's kinda ugly the way it happens and doesn't really look very elegant. Does anyone have a way around this? Note that I haven't even written any code yet, this is the very start of the app, and all i've done is added some controls and set their docking properties.
NATHAN RIDLEY
Web Application Developer
email: nathan @ netlab.com.au
[remove the spaces before and after the @ symbol]
|
|
|
|
|
Hmm docking, what docking control are you using?
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
actually I made a mistake, I needed to set the integralHeight property of the child control to false. Confused the hell out of me until I noticed it sitting there in the properties box!
NATHAN RIDLEY
Web Application Developer
email: nathan @ netlab.com.au
[remove the spaces before and after the @ symbol]
|
|
|
|
|
Mabey you should use
listView.Items.Clear();
Hope it helps
Thomas
|
|
|
|
|
I thought that you had found the solution, but no. I still get the same problem.
|
|
|
|
|
Doubtful. I use this all the time in a module I created for the application I architected at work. And calling ListView.Items.Clear clears only the items - not the columns as well like ListView.Clear would - which happens on many events in my application and all four views retain their behavior when doing so.
What else are you doing in your ListView ? Something else is garbling the list items.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I drop files onto the listView control, and the fullpath to each file is stored into a member ArrayList, the listView shows the file names and their associated icon which is extracted at runtime and placed into an imageList. The index's for the listView, ArrayList and imageList are all kept in sync.
Here's my code, first the InitializeComponent part for the listView:
this.listView1.AllowDrop = true;<br />
this.listView1.CheckBoxes = true;<br />
this.listView1.LabelWrap = false;<br />
this.listView1.LargeImageList = this.imageList1;<br />
this.listView1.Location = new System.Drawing.Point(24, 24);<br />
this.listView1.Name = "listView1";<br />
this.listView1.Size = new System.Drawing.Size(224, 224);<br />
this.listView1.SmallImageList = this.imageList1;<br />
this.listView1.TabIndex = 2;<br />
this.listView1.View = System.Windows.Forms.View.SmallIcon;<br />
this.listView1.DragDrop += new System.Windows.Forms.DragEventHandler(this.listView1_DragDrop);<br />
this.listView1.DragEnter += new System.Windows.Forms.DragEventHandler(this.listView1_DragEnter);
then the two events for Drag 'n' Drop:
private void listView1_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)<br />
{<br />
if(e.Data.GetDataPresent(DataFormats.FileDrop))<br />
e.Effect = DragDropEffects.All;<br />
else<br />
e.Effect = DragDropEffects.None;<br />
}<br />
<br />
private void listView1_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)<br />
{<br />
string[] s = (string[]) e.Data.GetData(DataFormats.FileDrop, false);<br />
for(int i = 0; i < s.Length; i++)<br />
{<br />
<br />
if (!m_szFullFilePaths.Contains (s[i]))<br />
{<br />
<br />
int j = listView1.Items.Count;<br />
m_szFullFilePaths.Capacity = j+1;<br />
m_szFullFilePaths.Add (s[i]);<br />
Regex reg = new Regex (@"\\");<br />
string[] p = reg.Split (s[i]);<br />
listView1.Items.Add(p[p.Length - 1]);<br />
<br />
Icon ico = ExtractIcon.GetIcon (s[i],true, false);<br />
imageList1.Images.Add (ico);<br />
listView1.Items[j].ImageIndex = j;<br />
}<br />
}<br />
}
And finally the button click event for the "Clear" button, so that a fresh selection of files can be made:
private void btnClearLV_Click(object sender, System.EventArgs e)<br />
{<br />
listView1.Items.Clear ();<br />
m_szFullFilePaths.Clear ();<br />
m_szFullFilePaths.Capacity = 0;<br />
imageList1.Images.Clear ();<br />
}
Heres hoping someone can spot the problem, cause I can't.
|
|
|
|
|
One important module of our application that I wrote uses this concept - only in a much better way. Instead of storing the paths in a separate ArrayList , just use the ListViewItem.Tag property. It's there for any use you need. Second, design your icon/filetype lookup so that it caches the information. Why use SHGetFileInfo (well, that's what I use anyway) for files you have already discovered? In fact, the Windows shell does this very thing with a system image list that caches all the icon for file types. If you want, I could send you my implementation. It works on the same principals as what Windows Explorer does and is incredibly fast.
Also, quit messing with the ArrayList.Capacity . This is only used to determine when the capacity should be increased. The default behavior is to double the capacity (best deterministic algorithm) when the count is the same as ahte capacity.
The reason you're probably seeing this "sparsly" placed icons is because you have LabelWrap set to false . The ListView class (and the List View common control it encapsulates) uses fixed-width columns to display items. If an item's text go beyond that, the item's text is spanned however many columns is required to show the full text. This virtual column is not pushed to make room. You'll see this behavior in Windows Explorer as well, for like I mentioned, the ListView class encapsulates the List View common control that Windows Explorer uses.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for the very helpful advice, I will put it into action latter. I am sure this will resolve the issue.
Thanks
|
|
|
|
|
I am populating a listView with items, and associating each item with an image in an imageList. The listView.View property is set as:
listView.View = View.SmallIcon;
When I add the initial set of items all is fine and the items are listed down the control, but when I use:
listView.Clear();
and re-populate the listView with the same method as before, the items are not listed down the control but are all over the place! Is there a bug or have I not set a property somewhere?
H E L P please
|
|
|
|
|
Hello,
I need to pass an array of strings to a COM object implemented in VB. The Interop interface wants a ref System.Array. How can I convert my String[] to this format in the fastest way possible?
Rickard
|
|
|
|
|
Its already an array:
string[] strs = "a d g v g r d".Split(' ');
Array a = strs;
Mazy
"Improvisation is the touchstone of wit." - Molière
|
|
|
|
|
Take a look at this post. I think it solves your problem.
|
|
|
|
|
I want to open a DAO Recordset
Database tempDB;
Recordset rstbl;
rstbl = tempDB.OpenRecordset("SELECT Name FROM myTblNames", DAO.RecordsetTypeEnum.dbOpenTable, DAO.RecordsetOptionEnum.dbReadOnly , DAO.LockTypeEnum.dbPessimistic );
Error is Invalid argument
|
|
|
|