|
You should read the documentation for the IntPtr . First, you only need the GCHandle to get the address of the byte[] array. For any other numbers you need to pass where the param Type is an IntPtr (processor-dependent bit width), just use create a new IntPtr passing the number into the constructor, like:
IntPtr ptr = new IntPtr(p.Handle); If the Handle was 12345, then the IntPtr created with this as a param would be:
0x00003039
0x0000000000003039 This is not the address of the numeric variable, merely the number wrapped in a platform-dependent numeric type. The only place you need the address is for the byte[] array. Using the GCHandle is just the easiest way in the .NET CF to get it's address (the address of the first element which the rest of the elements allocated on the stack, which is why you pass the number of bytes in the array as the next param to Toolhelp32ReadProcessMemory .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I've done as you said,since I need a IntPtr for BaseAddress I did
<br />
IntPtr q = new IntPtr(p.BaseAddress);<br />
but for p.Handle that in ToolHelp32ProcessMemory is uint and I've a IntPtr how do I get the uint value?
have u got some good link to understand marshalling/pinvoke?
thanks
|
|
|
|
|
If you look at the documentation for IntPtr , it should be obvious:
uint id = (uint)p.Handle.ToInt32(); ...assuming p.Handle is declared as an IntPtr .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
i've built a UserControl which has a panel in it, I wish to be able to add
controls into it at design-time. I've tried to do it simple; just built
the control, compiled it into a DLL and add it to the ToolBox, then i've drag it to my WinForm. The control is visible and all its properties are working
great. but when i try to add a control into it (say a link labal), the control
does not get added! i see the outlines selections, with nothing inside (i.e. the text, color etc.) and when compiling and running the WinForm, the link does not appear. any idea?
thanks guys
|
|
|
|
|
Hi guys, it me again.
I've looked at MS KB 813450, and it didn't fix my problem.
which is realy weird... maybe i'm doing something wrong?
|
|
|
|
|
Hi guys,
I've identified the problem.
In my UserControl, i have a panel which is fill-docked on it.
when i remove it and try the KB 813450 solution, it works.
but i want to keep that panel. any idea?
thanks
|
|
|
|
|
hai there,
I think the above mentioned steps are that you following to build your application.
am i right ?. If yes it won't show any unexpected out put. The way that you are following is correct.
I think the problem is because of properties of controls that you are using here.
I tried this same thing and i never found any problem.
If you want code block that i tried.then please let me know.
hai, enjoy coding
Sreejith SS Nair
|
|
|
|
|
The Panel should be either protected or public (by default, the VS.NET designer makes these private). If it is not, it is not a separately designable container - it's just another part of your UserControl .
If you find that it does not work, you need to attribute your UserControl with a ParentControlDesigner derivative that allows controls to be added. You can find out more about this designer class in the .NET Framework SDK.
Both suggestion should work, however. I helped another guy with a similar problem about a month ago and the problem was resolved using one (or both) of these methods. You could always try searching the comments (see the "Search comments" link ago) for keywords like "ParentControlDesigner" for more information on that discussion.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks guys for the quick help.
the fixed the problem by removing the panel that was fill-docking my user control and adding the ParentControlDesigner attribute.
Now the controls are being added into the user control and not to one of its controls (i.e. the panel i wanted it to be added to).
thanks.
|
|
|
|
|
Hi,
I have a Windows Application for which I must create installation package. But this application also has a web reference to a web service.
During the installation, I must allow the user to enter the URL to the Web Service and based on that the Web Reference must be updated to the new URL. This problem is because the Web Service can be installed anywhere.
Any suggestion is welcome
Praveen Nayak
|
|
|
|
|
hi,
I would suggest you not to add a web reference in your windows proj. Instead create a proxy class for the web service you are using using "wsdl.exe" tool which can be run from .NET command prompt.
Now once the proxy class is created add it to your windows proj. and whereever you are calling the web service in your code change it and make an instance of this proxy class and call the web method.
If you open the proxy class you will find a line
"this.Url = "[the web service URL]";
externalise this by taking this web service path into your configuration file (app.exe.config) and use System.Configuration namespace to access the configuration file.
This way you can externalise the webservice call...
hope this helps you
regards,
Aryadip.
Cheers !! and have a Funky day !!
|
|
|
|
|
Hi Aryadip,
Thanks a lot man. The solution you have suggensted is simple and straightforward.
Truly a help.
Thanks,
Praveen
Think of it as evolution in action
|
|
|
|
|
You can add the URL to the Web Service to your .config file, for example. You can actually do this in the PropertyGrid of VS.NET under Bindings, (Advanced); or programmatically by setting the Url property of the Web Service proxy.
As far as changing that, you could extend the Installer class and in your derivative get the path to the .config file as well as the URL from the Context.Parameters property (Context is an inheritted property from the Installer class). You would have your Installer derivative use the XML DOM to change/add the URL to your .config file (perhaps in the appSettings section). You'd pass the two parameters by adding your assembly with the Installer class (attributed with the RunInstallerAttribute ) as a Custom Action, and modify the command-line with the switches you specified as the keys to get the parameter values from Context.Parameters . To get the path to your .config file, pass something like [INSTALLDIR]MyApp.exe.config. [INSTALLDIR] will be replaced by the installation directory and the trailing \. In decent Windows Installers development environments, you could actually specify the path to the file itself using a file key property, but VS.NET's project automatically generates these at compile time so you'd have to make such a change with a tool like Orca after it's compiled, which requires knowledge of the MSI database.
Another option - though I don't recommend it - may be easier. Just write the URL to the registry (a UI for registry entries is provided in the VS.NET Windows Installer project editor) and read it in your application. I don't recommend this since .NET applications really shouldn't use the registry. It makes touchless deployments impossible. In your case, however, this really doesn't seem to be a problem (though you should consider defaulting to some URL, like a public instance of this Web Service, if available).
So, how does the user put this URL in? In both cases, go to the UI editor and add a new form to the installation with a single text box. Give this text box a property name in the PropertyGrid. It's this property name (as [MYPROPNAME] - use the square backets) that you'd pass to your Installer derivative or write to the registry key. Again, you should consider a default (or make sure your app handles the absence of a URL correctly and in a user-friendly manner.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks Heath,
Aryadip helped with the first part and you with the second. The installation package is done.
Praveen
|
|
|
|
|
I seem to be having a problem with threads. I have modified the main function, so that i can run one application first, then when it disposes itself it will jump to the next line in the main function and finally i run the second application. I get errors with window handlers and controls not showing any graphics although i have invoked them. Am i missing something important here?
[STAThread]
static void Main()
{
try
{
Client c = new Client();
GameClient g;
Application.Run(c);
while(!SHUTDOWN)
{
if (!SHUTDOWN)
{
g = new GameClient(c.connection.Socket,c.connection.Username,c.connection.Table,c.connection.Users);
Application.Run(g);
Thread.Sleep(1000);
//c = new Client();
//c = new Client(c.connection.Socket,c.connection.User);
//Application.Run(c);
SHUTDOWN = true;
}
}
}
catch(Exception ex)
{
MessageBox.Show("Client.Main " + ex.Message);
}
}
|
|
|
|
|
Hi,
I'm developing a component to use in a project i'm part of, and i'm experiencing some troubles regarding the control position:
In design mode i create the control, locate it in the win form, but when i run the application the control changes it's position and size (and some other properties) to default values.
Can anyone help with this?
Best Regards,
Anfernius
|
|
|
|
|
hi,
this should not happen in normal senario. You need to check your "OnPreRender" code to make sure you are not reinitializing the property values. Did you set the default value of the properties by using "DefaultValue" attribute??... if not then do that and check.
regards,
Aryadip.
Cheers !! and have a Funky day !!
|
|
|
|
|
Thanks for the reply, well i don't implement OnPreRender, so i belive the compiler calls for the base.OnPreRender.
I did notice something, the only values that are changed before runing the aplication are the ones enherited from UserControl, namely Position, BackColor and ForeColor.
Another strange thing happened when I used the DefaultValue applyed to BackColor, here is the situation:
private Color m_cBackColor = Color.DimGray;<br />
<br />
[Category("TS Colors"), DefaultValue("Color.Green")]<br />
public override Color BackColor<br />
{ (...) }<br />
So here's the problem, I don't seem to be able to define a DefaultValue for color, since DefaultValue needs a constant value, but the fun thing is that it works, though strangely.
If i dont put something in defaultValue, the changed color draw back to Color.DimGray, by doing DefaultValue("Color.Green") (although its not valid) it works...
Regards,
Anfernius
|
|
|
|
|
The DefaultValueAttribute takes a value of the property Type. "Color.Green" is a string - BackColor is a property.
Since Color.Green is not a constant value, you can not use it in the DefaultValueAttribute . Instead, set the BackColor of your control (which you really don't need to attribute like you are, or even override it) in your constructor or something.
To make it work like it had a default value, define methods called ShouldSerializeBackColor and ResetBackColor like so:
public class MyControl : Control
{
public static readonly Color DefaultBackColor = Color.Green;
public MyControl()
{
BackColor = DefaultBackColor;
}
protected bool ShouldSerializeBackColor()
{
return BackColor != DefaultBackColor;
}
protected void ResetBackColor()
{
BackColor = DefaultBackColor;
}
} The designer uses these two methods via Reflection (seemingly) in a similar fashion as using a DefaultValueAttribute .
One other option is to use the DefaultValueAttribute overload which takes a Type and string like so:
public class MyControl : Control
{
public static readonly Color DefaultBackColor = Color.Green;
public MyControl()
{
BackColor = DefaultBackColor;
}
[DefaultValue(typeof(Color), "Green")]
public override BackColor
{
get { return base.BackColor; }
set { base.BackColor = value; }
}
} The latter example you may find easier, but only works for Types that have a TypeConverter associated with them. Use whichever you prefer. In either case, though, you must still set the default BackColor during initialization.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks very much, problem solved!
Regards,
Anfernius
|
|
|
|
|
OnPreRender is only for ASP.NET, which the user gave no indication of using.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I get this error "DragDrop registration failed" when setting the AllowDrop property in a control. Im accessing a control from a different thread than the one that created the control. I use invoke when adding and removing,, the problem is i dont know if i have to invoke the dragdrop event or how it should be done.
|
|
|
|
|
Drag and drop registration must be performed on the STA thread, so it must be called from the thread on which the control was created. If you're setting the AllowDrop property from a different thread, use Invoke for that as well, getting the get accessor using Reflection and creating a delegate that matches the signature. Call Control.Invoke using that delegate that references the get accessor method.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Dear All,
i have a problem as the following :
i have draw some shapeson a control then i would like to stor the result in an image object but i could not do you have any information about this problem ??
Thanks for help
Mhmoud Rawas
------------
Software Eng.
|
|
|
|
|
check out here. Some of the explanations are in vb, but you can see the processes.
|
|
|
|
|