|
Thanks heath.
Just tell me, am I on the right track for handling a buffer? I take it I am constructing a space in memory that will have the file path written to it.
It's not an out, or ref call is it? I just need to retain the pointer to the buffer so that once it has been written, I can read it.
How do I go about this? Using a pointer to a string?
Cheers
Cata
Edit: Thanks dude! I got it figured, switched the string into a pointer, and forwarded the pointer, pulled it out, converted it back... and bingo!
Gratz. My experimentation with COM goes very well indeed
|
|
|
|
|
Did you ever read all that stuff on marshaling I gave you links for before? ref and out should only be used for [out] value types and pointers to pointers as declared in native code. If you need the address to a string, you simply do something like this:
IntPtr ptr = Marshal.StringToCoTaskMemAuto(myString); If your method declaration expects a pointer, this is how you can get it. If you're passing a char[] array, the array itself is a reference type (even though Char is a value type) so you don't need ref or out . The address is what's already being passed since the array is a reference type.
It all just depends on the implementation, for which you've given no specifics. If you need help with something specifically, please provide the signature of the method you're trying to call or something similar.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Yeah, sorted it all.
Thanks mate, probably posted too soon. Got it figured.
Gratz.
Cata
|
|
|
|
|
I have one form that is subscribing as an EventHandler to an event on the parent form.
It is possible for the user to close this form but still have the parent open.
Is there a way that I can remove myself as a delegate to that event? You know...like a "parent.EventType -= this.EventHandler;"
_____________________________________________
Of all the senses I could possibly lose, It is most often the one called 'common' that gets lost.
|
|
|
|
|
Yeah, same way you add it - you were close:
parent.Event -= new EventHandler(this.handler_Method); You don't even need to hold a reference because a delegate is a managed function pointer and the function (actually, method) doesn't move.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks Heath.
I thought about doing that....but it seems a bit counter-intuitive that you tell the parent to remove a new EventHandler.
Later,
Michael
_____________________________________________
Of all the senses I could possibly lose, It is most often the one called 'common' that gets lost.
|
|
|
|
|
It is only a new delegate but the delegate references the same method (of the same instance), so it will get removed. You can keep a reference to your delegate you added initially if you don't believe me, but trust that it works this way.
As far as who removes event handler is up to your design. If the child form is hooking into its parent form, then the child should remove the event handler for a better OO design. You could do this in the Closing or Closed event if you like, but know that the event handler will be nullified and garbaged collected if the child reference gets destroyed. It really isn't necessary in such a case.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Is there a way to validate a file name in C#?
I know I could easily code this up myself, but this is something everyone always needs, so I am in total denial that there is no function like that in C# libraries.
Thanks,
Elena
|
|
|
|
|
What do you mean validate a file name? Validate how? That it matches some naming scheme, is a certain length? Then the answer is no.
|
|
|
|
|
Try creating a file using an invalid file name and see if an exception happens, and handle the exception.
|
|
|
|
|
After playing with XML Web Services a little bit, it looks like all the data members of any custom object that need to be serialized across should be marked as public. This seems so non O-Oish or is this a limitation of the WSDL that gets generated automatically that it only supports public data members.
For e.g.
[Serializable]<br />
public class SomeData <br />
{<br />
public string _id;
<br />
public string Id <br />
{<br />
get { return _id; }<br />
}<br />
}<br />
Is there a way around this?
Chen Venkataraman
|
|
|
|
|
It's due to the way xml serialization works. It doesn't actually remote the object like you would think. What happens is that wsdl.exe creates a class on the client that is serialziation comatible with your class, with none of the methods. It will just be a simple struct with data fields only.
|
|
|
|
|
Only the property needs to be public. Your field that stores the actual value should be marked private. You want WSDL to ignore it and only pay attention to the public property. After all, why include values for both _id and Id, which actually are the same object?
If you want more control over the WSDL that's generated, see the attributes in the System.Xml.Serialization namespace, as well as those in the System.Web.Services and System.Web.Services.Protocols namespaces.
There is plenty of documentation about these in the .NET Framework SDK.
Besides, remember that the Web Service is just another class that code can call via a proxy. Classes can only access public members of other classes unless they're derived from that class. This is how code access is supposed to work.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
XML Serialization only serializes public data.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpovrSerializingObjects.asp
Chen Venkataraman wrote:
Is there a way around this? Yes
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemRuntimeSerializationISerializableClassTopic.asp
Or you can do a binary serialization to a MemoryStream and send it as a byte array. I have used this method successfully with an intermediate compression/encryption pass.
|
|
|
|
|
What I'm trying to do is have a tree view on the left of my SDI view, and depending on what's selected in that, display a different "form" or view on the right hand side. I'll want to have a dynamic amount of views, depending on how many items are in the tree view. All the data in the different views will be updated constantly, but only the selected one will display.
Any ideas how to accomplish this?
The Tab Control looks promising, but I'm wondering if there's another way, and I don't want the actual tab, because selection will be done via the tree control.
Thanks,
Peter
|
|
|
|
|
All you need to do is associate a Type with your TreeNode and create an instance of that when needed. You could also instantiate an instance with each TreeNode , but that would make memory consumption very high (depending on how many TreeNode s you have).
For example, derive from TreeNode with your own class and add a ControlType property (or whatever you want to call it) of type Type . In the handler for the TreeView.AfterSelect method, you can do something like this:
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
Type t = ((MyTreeNode)e.Node).ControlType;
Control c = (Control)Activator.CreateInstance(t);
containerControl.Controls.RemoveAt(0);
containerControl.Controls.Add(c);
} The containerControl represents the Panel or whatever hosts the control to be created in your form on the right side. Please note that this is a very simplistic example but should give you some idea.
There's also a few articles here on CodeProject that use a similar approach for tree-driven preference dialogs/controls. For one example, see A Designable PropertyTree for VS.NET[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks, that's exactly what I needed.
Peter
|
|
|
|
|
But is there a way of preventing the tab from drawing?
(I have a similar problem that has to do with the CrystalReportViewer. I'm trying to customize the control more than it allows. It would be great if I can just take the control and parent it to a panel, but part of the implementation is in the tabcontrol so that didn't work out.)
|
|
|
|
|
You could override WndProc and pretty much change the behavior of the TabControl to work like multiple Panel s (after all, you're just making each TabPage work like it's parent class, ScrollableControl , which is the parent class for Panel ). Why not just move the implementation? Most of the code I'm sure you could copy and paste, unless you mean you're actually using the tab-related methods for things (like for a wizard), in which case there's always another way.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
The problem here is that I don't want to go trough the pain of redoing the implementation. I can modify the properties of the provided CrystalReportViewer control. Thanks for the suggestion. I'll just implement a message filter and do the needed work myself.
The components that make up the CrystalReportViewer controls are public. It's just that I don't know enough about the internal implementation to create my own implementation. If there is an example of a custom implementation please give me a pointer.
|
|
|
|
|
I know this belongs in the VS IDE forum, but it appears no questions get answered there.
I have a Visual Studio solution that contains 2 projects. ProjectA is a Windows Control library, while projectB is a Windows Forms application project. In projectB, I add a reference to projectA and place the control (projectA) on the Windows Form (projectB). All is fine and dandy. However, when I make a change to the control in projectA, it doesn't update the control instance on the form of projectB, unless I remove the reference to projectA and then add it again.
What do I need to do so that projectB (the form) always has the latest version of projectA (the control)?
The graveyards are filled with indispensible men.
|
|
|
|
|
When you make a change to the control, build the solution, or at least ProjectB (the app). Close (if not already) the form that contains the control and reopen it.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Yeah for some reason that doesn't work. I've done an easy test: setting the .BackColor of the control, rebuilding the solution, then opening the form designer for the app, yet the back color of the control remains the same.
The only way the back color gets updated is if I remove the reference to the control, then add it again...bizarre.
I think it may be related to another problem I'm having - during a solution rebuild, some of the other libraries output "Could not copy xyz to run directory. The file was in use by another process." Oddly, there shouldn't be any processes using these files.
The graveyards are filled with indispensible men.
|
|
|
|
|
Ahh yes, that problem. We have that problem a lot too. The process that's using the file is VS.NET itself. This mostly happens when you debug an app, but happens sometimes when simply building files. This is a problem both in VS.NET 2002 and 2003. The only way to fix the problem is to restart VS.NET (devenv.exe). When you're not having this open file handle problem, the solution I posted before should work well; it's also mentioned somewhere in the VS.NET product documentation, but I've been unable to find that or the step required to automatically see UserControls in the toolbox (which was arduous in VS.NET 2002).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
Ahh yes, that problem. We have that problem a lot too.
Good to know I'm not alone. That problem seems to be fixed (temporarily?) if I change the output path for the assemblies in question. I've also been able to get around it by restarting VS (like you mentioned), but rebuilding the solution would often cause these files to be reported "in use" by VS. Hopefully Whidbey will address this.
And whaddya know, that did the trick - soon as the "file in use" errors go away and a solution rebuild works completely, projectB sees projectA's updates.
As always, thanks Heath for your help (and speedy responses, 2 quick replies and a a resolution to my problem within 5 minutes. A new record! )
The graveyards are filled with indispensible men.
|
|
|
|