|
Thanks Mike.
Doesn't "[MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPStr)] string lParam"
tell .Net how to marshall strings?
Also I tried to call SendMessage() in-process and I am getting the same exception.
Does that make sense? Thank you.
|
|
|
|
|
I'm working on a Graph grid that is it's own region on the form. I want the OnMouseMove event to display the x and y coords. in text boxes, if the mouse goes inside this grid area.
I was getting pretty far by myself until I ran into a problem... I'll just print the code so you'll know what I mean.
if(region.GetBounds().Right >= MousePosition.X && region.GetBounds().Left <= MousePosition.X))
{
txtXcoord.Text = MousePosition.X.ToString();
}
it keeps giving me an exception if I stick a graphics object in the GetBounds(). Please help me, I dunno what to do.
If someone's got a simpler way of doing this, that would be awesome too.
|
|
|
|
|
What is region defined as? A Region struct? In what class is this code contained (the one that declares region )? What's the access on the region field?
What is the exception that is thrown (type)? What does the exception text read?
Please be specific and verbose when asking for help. We don't know your code (and what you posted isn't nearly enough to help diagnose the problem) nor the circumstances under which your code is called.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Sorry. I am new at this.
Region is defined in the main form, at the top (private Region region;)
with graphics as a class variable. (private Graphics g;)
Graph is a .cs file that holds the region data, and the Override Paint event instances the method and tells it to paint itself.
Here's more code:
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
Graph gr = new Graph();
}
gr.DrawGraph(toolBarMain.Location.X+5,toolBarMain.Size.Height+5,500,500,g);
}
protected override void OnMouseMove(MouseEventArgs e)
{
Graph gr = new Graph();
region = gr.GetRegion();
if(region.GetBounds(g). >= MousePosition.X && region.GetBounds(g).Left <= MousePosition.X)
{
txtXcoord.Text = MousePosition.X.ToString();
}
base.OnMouseMove (e);
}
I didn't call it in OnPaintArgs, but does that matter?
It paints my grid fine, but I want to display the x/y coordinates of my mouse in two text boxes.
I didn't put the 2nd text box in yet because I wanted to make sure that it was working properly.
is this enough info?
|
|
|
|
|
Hey There,
Why are you instatiating the Graph() object both in OnPaint and again in onmousemove. Shouldn't you be using the same object?
|
|
|
|
|
Never store a Graphics object as a field. You either create a temporary Graphics object with CreateGraphics or - when overring OnPaint or handling the Paint event of a different control - use PaintEventArgs.Graphics . Do not store these ever.
The other reply is asking the right question: why are you re-instantiating Graph ? It's that object you should be referencing in a field.
The other thing you need to do is read about the MousePosition static property. This returns the screen position - not the client (your control) position, i.e. relative to your control's upper-left coordinate (always 0,0). To translate the coordinates, call Control.PointToClient (reads the SDK documentation that was installed by default when you install VS.NET or the .NET Framework SDK; it's also available online at http://msdn.microsoft.com/library[^]) the compare the coordinates.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thank you for setting me straight on that. And thank you for your time, patience and help!
You guys are the best!
|
|
|
|
|
No there isnt. .NET Framework has to be installed in the computer for any .NET based app to be able to run.
|
|
|
|
|
The Visual Studio .NET Setup project does not install the .NET Framework, as is documented in the Visual Studio Product Documentation. You can create your own bootstrapper to install it, however. Read HOW TO: Distribute the .NET Framework with a Visual Studio .NET Deployment Project[^]. Specifically, you'll want to read about and download the sample bootstrapper from MSDN at http://msdn.microsoft.com/library/default.asp?url=/downloads/list/netdevframework.asp[^].
The Framework does have to be installed because it is the runtime that JITs and executes the assemblies, as well as defines the methods that you use to write your app (the BCL). That's no different than a Java application requiring the Java Runtime Environment (JRE) or applications built against Microsoft Visual C Runtime v7.1 to require msvcr71.dll. This isn't limited to the Windows platform, either, but to all platforms.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Right, I see.
Ok thanks for the help
|
|
|
|
|
C# requires the dot net framework to run, dotnetFX.exe is teh installation file for the framework so yes, you do need it. Every single C# application requires this framework to be installed. I used to work as an admin at a school and personally i would have installed it for you if it was neccesary for a class then uninstalled it after. Ask your admin to install it for you, the worst they can do is say no.
Kev
|
|
|
|
|
Moochie5 wrote:
Does dotnetfx always need to be installed on a computer that doesn't have the .NET Framework on it?
Yes
Moochie5 wrote:
s there anyway around that?
No.
Moochie5 wrote:
I find it hard to believe that for every program that one creates one needs to install dotnetfx on the computer for it to run
Why is it so hard to believe? Where do you think all those neat features come from? Did you see the size of a "hello, world" program compared to a C++ one with the libraries statically linked?
BTW, it's not "every program", it's only the first .NET program.
Yes, even I am blogging now!
|
|
|
|
|
I have finished created a setup for my program using the setup wizard in Visual Studio .NET 2003. The setup works fine on my computer and the program works perfect. However, when I go to install the program on other computers it says I need the .NET Framework Redistribution package installed, which I believe is "dotnetfx" when I looked this up on msdn.
The problem is I need to run this program at school and demonstrate it to the class. But I cannot install dotnetfx on the computer it because an administrator must do this, students to not have the right access.
Does dotnetfx always need to be installed on a computer that doesn't have the .NET Framework on it? Is there anyway around that? I find it hard to believe that for every program that one creates one needs to install dotnetfx on the computer for it to run. Is there any way around that?
|
|
|
|
|
Hi,
I looking to storing some datas to a combobox with for each datas a would like to store a Tag value.
Best regrads
youssef
|
|
|
|
|
Create a custom object collection where your objects show all the info u need through properties. Then set the collection as ur combo's datasource and set the displaymember and valuemember to your object's properties (Name and Tag for example).
If u dont want to go through all that, it might be easier to just store all objects + info in the necessary fields of a datatable (that would solve ur custom object collection) and proceed the same way as before.
|
|
|
|
|
For more information and an example of what Skynyrd mentioned, read about the MappingName Property[^] for the DataGridTableStyle class in the .NET Framework SDK.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
You can add any object as an item to a ComboBox , and to display it, the ComboBox calls the object's ToString method.
So, create a MyComboItem class that contians two (or more) properties, Text and Tag , and override ToString to return the contents of the Text property. When you get an item from the ComboBox 's Items collection, don't forget to do the appropiate cast.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
I cant dynamically invoke a method on a remote object. Code is as follows (tested on a dummy class with same method and works perfectly but wont run on the remote object)
public void RunMethod(Type methodType,string methodName,object[] arguments)
{
object proxy=GetProxy (returns a transparent proxy of a singlecall remote object)
Delegate dlg=Delegate.CreateDelegate(methodType,proxy,methodName); throws a System.ArgumentException
dlg.DynamicInvoke(arguments);
}
Is it possible to invoke a remote object through it's proxy this way? If not, how can it be done?
|
|
|
|
|
Please be specific and verbose. What is the message for the ArgumentException ? What is the stack trace? Please be sure to also describe the method signature that you're trying to invoke as well.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi Heath,
Sorry, i'm running VS in spanish so I'm not sure how to exactly translate any exception messages without confusing things any more :p
The calling code is as follows:
public delegate string TestMethod();
...
SingleCallManager manager=new SingleCallManager(typeof(IDataLayerTool),"tcp://localhost:8086/DataLayerTool.rem");
manager.RunMethod(typeof(TestMethod),"GetAssetsMenuLayout",null);
...
Complete info on exception is the following: The message would translate to "Error linking to target method." more or less.
[System.ArgumentException]: {"Error al enlazar con el método de destino." }
System.Object: {System.ArgumentException}
_className: null
_COMPlusExceptionCode: -532459699
_exceptionMethod:
_exceptionMethodString: null
_helpURL: null
_HResult: -2147024809
_innerException: { }
_message: "Error al enlazar con el método de destino."
_remoteStackIndex: 0
_remoteStackTraceString: null
_source: null
_stackTrace: {System.Array}
_stackTraceString: " at System.Delegate.InternalCreate(Object target, String method, Boolean ignoreCase)\r\n at System.Delegate.CreateDelegate(Type type, Object target, String method)\r\n at Vigila.Objects.SingleCallManager.RunMethod(Type methodType, String methodName, Object[] arguments) in d:\\proyectos .net\\código aplicaciones\\vigila 2\\vigila objects\\singlecallmanager.cs:line 128\r\n at Vigila.Client.VigilaStartUp.loadUpIniData() in d:\\proyectos .net\\código aplicaciones\\vigila 2\\vigila client\\vigilastartup.cs:line 63\r\n at Vigila.Objects.ThreadWorker.workingEnvelope() in D:\\Proyectos .NET\\Código Aplicaciones\\Vigila 2\\Vigila objects\\ThreadWorker.cs:line 153"
_xcode: -532459699
_xptrs: 0
HelpLink: null
HResult: -2147024809
InnerException: { }
Message: "Error al enlazar con el método de destino."
Source: "mscorlib"
StackTrace: " at System.Delegate.InternalCreate(Object target, String method, Boolean ignoreCase)\r\n at System.Delegate.CreateDelegate(Type type, Object target, String method)\r\n at Vigila.Objects.SingleCallManager.RunMethod(Type methodType, String methodName, Object[] arguments) in d:\\proyectos .net\\código aplicaciones\\vigila 2\\vigila objects\\singlecallmanager.cs:line 128\r\n at Vigila.Client.VigilaStartUp.loadUpIniData() in d:\\proyectos .net\\código aplicaciones\\vigila 2\\vigila client\\vigilastartup.cs:line 63\r\n at Vigila.Objects.ThreadWorker.workingEnvelope() in D:\\Proyectos .NET\\Código Aplicaciones\\Vigila 2\\Vigila objects\\ThreadWorker.cs:line 153"
TargetSite: {System.Reflection.RuntimeMethodInfo}
I repeat, if I implement a non-remote object and try the code, it works perfectly:
public class DummyTest
{
public DummyTest()
{
}
public string GetAssetsMenuLayout()
{
return "Succesful";
}
}
The GetAssetsMenuLayout of the IDataLayerTool has the exact same signature as the dummy class written above but I still cant link to it, and of course the remote object DataLayerTool implements the IDataLayerTool interface. (The transparent proxy getter would fail anyway if that weren't the case)
public interface IDataLayerTool
{
...
string GetAssetsMenuLayout();
...
}
|
|
|
|
|
The MSDN documentation says the following about the function Delegate.CreateDelegate(Type objType,Object target,string method) method.
A System.ArgumentException is thrown when objType does not inherit from either Delegate or MulticastDelegate OR method is not an instance method. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdelegateclasscreatedelegatetopic.asp[^]
I'm a little confused about your question: Is it possible to invoke a remote object through it's proxy this way?
When you have a remote objet you use its proxy to call its method exactly the same way you would call other objects. For example, say I have an object called myRemoteObject
<br />
using System;<br />
using System.Runtime.Remoting;<br />
<br />
namespace myRemoteService<br />
{<br />
public class myRemoteObject : MarshalByRefObject<br />
{<br />
public String myRemoteMethod() <br />
{<br />
return "Hello World";<br />
}<br />
}<br />
}<br />
You can then call the remote object via it's proxy using the following code:
<br />
using System;<br />
using System.Runtime.Remoting;<br />
using myRemoteService;<br />
<br />
public class Client<br />
{<br />
static void Main(string[] args)<br />
{<br />
String filename = "client.exe.config";<br />
RemotingConfiguration.Configure(filename);<br />
<br />
myRemoteObject obj = new myRemoteObject();<br />
Console.WriteLine(obj.myRemoteMethod());<br />
obj = null;<br />
<br />
Console.WriteLine("Done...");<br />
}<br />
}<br />
This will use a generated proxy to call your method.
Did this help at all?
~javier lozano
(blog)
|
|
|
|
|
Hi javier,
thanks for the info.
I can call any method I want of my remote object through its transparent proxy without any problems.
The problem is that I want to localize in one piece of code all the exception handling of the SocketException that gets thrown when the server where the remote object lives is not accessible to the client app that calls one if its methods.
There r two ways around it that I could find right now:
1) Implement the exception handling on all remote calls throughout my code.
2) Create a SingleCallManager object with a generic RunMethod method that will dinamycally link any method calls to the remoteobject (loss of performance is not an issue) dynamically invoking the call to its proxy like you would with any other object. The problem is, that the same piece of code will link perfectly to a dummy non remote class but it will not link to the remote object throwing the exception i've included in the reply to Heath's post. Through this RunMethod method I would be able to localize all excpetion handling of any method call due to a connection failure to the server in one place.
|
|
|
|
|
Hi Skynyrd,
I think I solved your problem or at least came up with an example for you to see. I created a simple remote object with a client and server to host it. Then, I created a delegate so I could call the remote object's method via that delegate. This is what I came up with:
WARNING THIS IS A LONG POST
RemoteObject.cs
using System;
namespace RemoteNamespace
{
public class RemoteObject : MarshalByRefObject
{
public string MyTypeString()
{
return this.GetType().ToString();
}
}
}
Server.cs
using System;
using System.Runtime.Remoting;
namespace RemoteServer
{
class Server
{
[STAThread]
static void Main(string[] args)
{
RemotingConfiguration.Configure("RemoteServer.exe.config");
Console.WriteLine("Hit <ENTER> to exit.");
Console.ReadLine();
}
}
}
Client.cs
using System;
using System.Runtime.Remoting;
using System.Reflection;
using RemoteNamespace;
namespace RemoteTest
{
public delegate string del_void();
class Client
{
[STAThread]
static void Main(string[] args)
{
RemotingConfiguration.Configure("RemoteTest.exe.config");
RemoteObject ro = new RemoteObject();
MethodInfo m = ro.GetType().GetMethod("MyTypeString",BindingFlags.Instance | BindingFlags.Public | BindingFlags.InvokeMethod);
try
{
Delegate d = Delegate.CreateDelegate(typeof(del_void),ro,m.Name);
object o = d.DynamicInvoke(null);
Console.WriteLine(o);
}
catch(TargetInvocationException tie)
{
Console.WriteLine(tie.StackTrace);
}
catch(Exception e)
{
Console.WriteLine(e.StackTrace);
}
Console.ReadLine();
}
}
}
Server.exe.config -- For remoting object config
<configuration>
<system.runtime.remoting>
<application>
<service>
<wellknown
mode="SingleCall" objectUri="RemoteObject.rem"
type="RemoteNamespace.RemoteObject, RemoteLibrary"/>
</service>
<channels>
<channel ref="tcp" port="8080"/>
</channels>
</application>
</system.runtime.remoting>
</configuration>
Client.exe.config -- For remote object config
<configuration>
<system.runtime.remoting>
<application>
<channels>
<channel ref="tcp" port="0">
<clientProviders>
<formatter
ref="binary"
/>
</clientProviders>
</channel>
</channels>
<client>
<wellknown
url="tcp://localhost:8080/RemoteObject.rem"
type="RemoteNamespace.RemoteObject, RemoteLibrary"
/>
</client>
</application>
</system.runtime.remoting>
</configuration>
The key for this to work was to use the following line:
MethodInfo m = ro.GetType().GetMethod("MyTypeString",BindingFlags.Instance | BindingFlags.Public | BindingFlags.InvokeMethod);
For some reason when you passed the full name of the method, the object couldn't bind. However, I just tried this, if you pass the name of the method MyTypeString instead of m.Name into the CreateDelegate method, it also works.
Take a look at this code and tell me what you think.
~javier lozano
(blog)
|
|
|
|
|
Skynyrd wrote:
The problem is that I want to localize in one piece of code all the exception handling of the SocketException that gets thrown when the server where the remote object lives is not accessible to the client app that calls one if its methods.
Could you elaborate a little more? No offense, but the grammar is getting in the way of the problem, specifically "thrown when the server where the remote object lives". If I'm correct, you're trying to say that you want to localize the exception message that the server throws, and you want to localize it on the client?
If so, just catch that exception type and display a localized error message to the user, or if this is for a library (never lets your users see exceptions - there's simply no excuse for that in an application, but in a library it's common since your library gets used by applications) localize the text and throw a new exception with the original exception as the InnerException .
Sorry if I'm wrong, but like I said I have problems parsing and understanding your sentance. Again, no offense meant. It's usually not a problem but in this case - in order to hopefully help you with the true problem - I need to be sure I understand you correctly.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi Skynyrd,
I think I solved your problem or at least came up with an example for you to see. I created a simple remote object with a client and server to host it. Then, I created a delegate so I could call the remote object's method via that delegate. This is what I came up with:
WARNING THIS IS A LONG POST
RemoteObject.cs
using System;
namespace RemoteNamespace
{
public class RemoteObject : MarshalByRefObject
{
public string MyTypeString()
{
return this.GetType().ToString();
}
}
}
Server.cs
using System;
using System.Runtime.Remoting;
namespace RemoteServer
{
class Server
{
[STAThread]
static void Main(string[] args)
{
RemotingConfiguration.Configure("RemoteServer.exe.config");
Console.WriteLine("Hit <ENTER> to exit.");
Console.ReadLine();
}
}
}
Client.cs
using System;
using System.Runtime.Remoting;
using System.Reflection;
using RemoteNamespace;
namespace RemoteTest
{
public delegate string del_void();
class Client
{
[STAThread]
static void Main(string[] args)
{
RemotingConfiguration.Configure("RemoteTest.exe.config");
RemoteObject ro = new RemoteObject();
MethodInfo m = ro.GetType().GetMethod("MyTypeString",BindingFlags.Instance | BindingFlags.Public | BindingFlags.InvokeMethod);
try
{
Delegate d = Delegate.CreateDelegate(typeof(del_void),ro,m.Name);
object o = d.DynamicInvoke(null);
Console.WriteLine(o);
}
catch(TargetInvocationException tie)
{
Console.WriteLine(tie.StackTrace);
}
catch(Exception e)
{
Console.WriteLine(e.StackTrace);
}
Console.ReadLine();
}
}
}
Server.exe.config -- For remoting object config
<configuration>
<system.runtime.remoting>
<application>
<service>
<wellknown
mode="SingleCall" objectUri="RemoteObject.rem"
type="RemoteNamespace.RemoteObject, RemoteLibrary"/>
</service>
<channels>
<channel ref="tcp" port="8080"/>
</channels>
</application>
</system.runtime.remoting>
</configuration>
Client.exe.config -- For remote object config
<configuration>
<system.runtime.remoting>
<application>
<channels>
<channel ref="tcp" port="0">
<clientProviders>
<formatter
ref="binary"
/>
</clientProviders>
</channel>
</channels>
<client>
<wellknown
url="tcp://localhost:8080/RemoteObject.rem"
type="RemoteNamespace.RemoteObject, RemoteLibrary"
/>
</client>
</application>
</system.runtime.remoting>
</configuration>
The key for this to work was to use the following line:
MethodInfo m = ro.GetType().GetMethod("MyTypeString",BindingFlags.Instance | BindingFlags.Public | BindingFlags.InvokeMethod);
For some reason when you passed the full name of the method, the object couldn't bind. However, I just tried this, if you pass the name of the method MyTypeString instead of m.Name into the CreateDelegate method, it also works.
Take a look at this code and tell me what you think.
~javier lozano
(blog)
|
|
|
|
|