|
I have to determine what is control x and y global position in screen, not local position, to show up dialog on top of the control - is there normal known way to do that?
|
|
|
|
|
hi oskars!
you can use the PointToScreen method to convert the Location value into a screen coordinate value.
hope that helps!
microsoc
|
|
|
|
|
I have a tray Icon that doesn't disappear at the time of application closing.
How do I get it to disappear?
|
|
|
|
|
Normally an app icon remains when an application terminates improperly. This happens often in the VS IDE when you Stop Debugging during the program execution. If this is the case, there is no real fix. To remove "dead" icons, simply move the mouse cursor over the icons in the sys tray and Windows will update itself.
If this is not the case, you should look at whether your application is terminating properly.
|
|
|
|
|
I want to protect my class specially some methods. I have do some steps:
1. Create a library project using C# named "protected"
2. Use sn.exe to create new strong name. Named key.snk
3. Use sn -p key.snk key.publickey to get the public key and token hexcode.
4. Use sn -tp key.publickey to view the public key of snk file.
5. Create class and method that will be protected. The code are :
using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Permissions;
using System.Security;
using System.Reflection;
namespace Protecting
{
[StrongNameIdentityPermissionAttribute(SecurityAction.Deny, PublicKey = "00240000048000009400000006020000002400005253413100040000010001004B1C3C045DC354" +
"E3284168F3664C5447649A3F2969AFC60D52F9C65BA6DC95A5F3A5EC673F47999D99F6EE7B632CB9" +
"B7DA1E56FF6DFB3944A267D6E7D4F2E4BDAF294EEDC960CD9A4C22D358922FF5E92838C3439A0F83" +
"40C003F6E4D43AD1FAEF5E6A80D31D02C50EAB3D845F384E7CE8CBE5FDA4E9154223A4FF50424F7D" +
"B5")]
public class Class1 // <-This is protected class.
{
[StrongNameIdentityPermissionAttribute(SecurityAction.Deny, PublicKey = "00240000048000009400000006020000002400005253413100040000010001004B1C3C045DC354" +
"E3284168F3664C5447649A3F2969AFC60D52F9C65BA6DC95A5F3A5EC673F47999D99F6EE7B632CB9" +
"B7DA1E56FF6DFB3944A267D6E7D4F2E4BDAF294EEDC960CD9A4C22D358922FF5E92838C3439A0F83" +
"40C003F6E4D43AD1FAEF5E6A80D31D02C50EAB3D845F384E7CE8CBE5FDA4E9154223A4FF50424F7D" +
"B5")]
public void WhoSaid(string Name) // <- This is protected method.
{
Console.WriteLine(Name + " say Hello World");
}
}
}
6. I also add the snk file to the project propertied at signing tab.
7. Build the library.
8. View the library using secutil to check if assembly have been signed. And the result is same.
By the code we can know the theory that any application that want to access this class even have been signed with the same key will not grant access to use this class and method.
For testing I use console application, with steps:
1. Create a console project using C#.
2. Reference to the "protected.dll" that been created.
3. Write code that execute protected method on protected.dll
using System;
using System.Collections.Generic;
using System.Text;
namespace Call_protected
{
class Program
{
static void Main(string[] args)
{
Protecting.Class1 a = new Protecting.Class1();
a.WhoSaid("Ariston");
Console.ReadKey();
}
}
}
4. Build the application.
5. Run it.
6. Whoala it still can execute the protected methods on library. The console will display:
Ariston say Hello World
I use VS 2005 to build both and use Framework 2.0. So what wrong with my code, I don't have any ways to resolve this problem.
PS: The tester console application is not signed by any strong name key.
Thanks.
Simple mind programmers, I don't need a complicated mind.
-- modified at 21:16 Sunday 26th February, 2006
|
|
|
|
|
Hi!
I think you should not use SecurityAction.Deny for your class and method but SecurityAction.LinkDemand .
That way, only the direct caller has to satisfy the strong name identity with the given public key, but callers further up the line don't have to.
If you use SecurityAction.Demand , then you'll always get a SecurityException because mscorlib (which is the top-most caller in the end) doesn't have the required strong name identity.
Hope this helps...
Regards,
mav
--
Black holes are the places where god divided by 0...
|
|
|
|
|
Well I have change the SecurityAction into SecurityAction.LinkDemand but still the console application that I use to test can access the class and the method. At application console I didn't set any Strong Name Key. So the theory is that the console application doesn't have any Strong Name Key (not the same key too) will caught an exception while access the library class that have been set a public key. Its that right or not. Because I want to protect my library that contains class and methods so that only I can use the class not the other people that want to reference my assembly.
Do you know how to solve this ?
PS: Can do this at Debug Mode for building the library ?
Thanks.
Simple mind programmers, I don't need a complicated mind.
|
|
|
|
|
I created a test solution with VS2003/.NET 1.1 to experiment with the attributes and get exactly the same behavior with an Windows Forms application and a console application.
When I specify LinkDemand as action, then every caller that's not signed or does not expose the given public key will throw a security exception when trying to access the protected class.
Regards,
mav
--
Black holes are the places where god divided by 0...
|
|
|
|
|
Well it seem that everyone that use VS 2003 and FW 1.1 always success. But I don't close the conversation only for VS 2003.
Well if you have any solution or links to protect the assembly over FW 2.0 please tell me. I don't want to go back into VS 2003 because many of my jobs writen over VS 2005.
Thanks for you support.
Happy coding, ya..
Simple mind programmers, I don't need a complicated mind.
|
|
|
|
|
Ok, it seems to be an issue with .NET 2.0 indeed.
I've converted the VS 2003 test solution to VS 2005 and tried again. I could reproduce the failure to check the StringNameIdentityPermissionAttribute with .NET 2.0 - the very same application that threw a SecurityException with 1.1 ran without problems in 2.0!
I think it's time to contact MS...
Regards,
mav
--
Black holes are the places where god divided by 0...
-- modified at 12:57 Tuesday 28th February, 2006
I just found some additional information that might be of interest:
In the microsoft.public.dotnet.security newsgroup I found a statement that in .NET 2.0 fully trusted code will automatically bypass all identity permission demands.
Heaven knows why this decision has been made, but this seems to explain the behaviour.
-- modified at 13:12 Tuesday 28th February, 2006
And another piece of wisdom from Eugene Bobukh:
http://blogs.msdn.com/eugene_bobukh/archive/2005/05/06/415217.aspx[^]
|
|
|
|
|
I'm writing some C++ code that I'd like to prepare for simple interop. To make things as easy as possible on the .NET side of things, how should I declare a C++ function that:
1. takes an array as a parameter? Is int* ok?
2. returns a UTF8 string. Is LPSTR ok? Should I use an output parameter instead of a return value?
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Connor's Christmas Spectacular!
Judah Himango
|
|
|
|
|
How do you intend to interop it, managed C++ or COM ? If managed C++, you'll end up writing methods that take .NET types anyhow.
I guess there is also pinvoke.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Yeah I was planning PInvoke simply because there is an existing codebase (I'm trying to port some Java JNI code into the .NET world). I considered using C++/CLI to make it simpler, and may end up going that way, but for now I've just declared the methods as described in my first post.
So any thoughts on how to define a C method that takes an int[] and returns a string so that it can be used easily from a .NET language?
|
|
|
|
|
Judah Himango wrote: 1. takes an array as a parameter? Is int* ok?
Yes.
Judah Himango wrote: 2. returns a UTF8 string. Is LPSTR ok? Should I use an output parameter instead of a return value?
It is ok, as long as the calling application doesn't have to free or delete the memory.
I don't see dead pixels anymore...
Yes, even I am blogging now!
|
|
|
|
|
Thanks Daniel. The calling app would have to free the memory, so I think what I'll do instead is have the method take a 2nd LPSTR parameter which will be the output. That way I can feed in a StringBuilder and have it work without issue.
|
|
|
|
|
Will an event be raised when all the controls in a form has been drawn?
I have a form with many buttons with BGpics in it. Can I set the form to invisible, let it load all the pic, and then show it instead of it showing it and loading the pic at the same time (this makes it look really laggy)
|
|
|
|
|
If a control is not visible, and its background image is changed, will the image actually change? or will it only change only when it becomes visible?
|
|
|
|
|
That depends on how you specify "the image".
If the control is not visible, there is no background image drawn. If you change the property for the background image, the property changes, but as the property is not used as an image, the image can't change.
---
b { font-weight: normal; }
|
|
|
|
|
If a tree falls in the woods, and no-one is there to hear it...
If the control is not rendered, then no image is drawn.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Yes it will. But you won't see the change until you make the control visible.
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
That means that if I have a number of pictures changed but not visible, it has potential to slow down the foreground performance right?
|
|
|
|
|
Yes, your app will take a performance hit every time you change (i.e. read) a new image (assuming you're reading them from a file).
A simple work-around would be to only remember the new image name everytime you "change" it. Then, when the control shows itself, it should load the current image (if it hasn't already done so) and set it as its background.
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
How would I go about creating my own file format for an application?
Any help is appreciated
Wacky waving inflateable arm flailing tube man!
- Family Guy
|
|
|
|
|
Come up with three letters that are not commonly used ( not .doc for example ), then write the code to store relevant data to a file, and read it again.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Sean89 wrote: How would I go about creating my own file format for an application?
Like Christian said, pick an uncommon extension, and use any file reading and writing mechanisms you want. For maximum efficiency, pick a file type that has lots of existing library support (like Xml or MDB), and use that file type with an uncommon extension.
Your files look like "ABC" files in explorer, but your app knows that they're really XML or Access database files when it goes to read and write them.
Share and enjoy.
Sean
|
|
|
|