|
Heath Stewart wrote:
Microsoft MVP
Congratulation Heath.
Mazy
"Improvisation is the touchstone of wit." - Molière
|
|
|
|
|
|
Thanks for your response, but this only changes the icon that is displayed in the "Add/Remove Programs" (unless I am doing something wrong), I was looking for a way to add a "Uninstall" shortcut to the user's "Start / Programs" menu.
But thanks anyway for a detailed response!
rado
Radoslav Bielik
http://www.neomyz.com/poll [^] - Get your own web poll
|
|
|
|
|
Sorry for the misunderstanding.
Windows Installer recommends that you DO NOT add an Uninstall shortcut to the start menu. In fact, IIRC, this violates Windows Installer guidelines and you cannot certify your application for Windows.
If this is not a big deal, you could do so by making a shortcut to msiexec.exe and use "/x [ProductCode]" as the command-line parameter.
Unfortunately, the crappy Windows Installer project in VS.NET won't let you do this (as well as MANY other things, which is why I never use it and either use Wise for Windows Installer or from scratch with Orca). You need to download the Windows Installer SDK, part of the Platform SDK, which includes an install for a handy utility called Orca. This opens the MSI package as it is - a relational database. You can find more information about the Platfrom SDK from http://msdn.microsoft.com/platformsdk[^].
Once you do this, you need to enter the following information into the Shortcut table:
(Column: Description)
Shortcut: Unique key - type anything
Directory_: Key to a directory in the Directory table for your program group
Name: Name of the shortcut (i.e., title)
Component_: Key to a component in the Component table for which this shortcut is associated
Target: [SystemFolder]msiexec.exe
Arguments: /x [ProductCode]
Description: Description of the shortcut
Hotkey: Leave empty
Icon_: Key to an icon to use in the Icon table
IconIndex: 0-based index for icon if Icon_ points to an executable
ShowCmd: 1 for normal, 3 for maximized, 7 minimized/not active If you like, I could also probably send you Orca since the EULA seems to allow it so long as I send you the entire installation (which isn't bit). If you would rather me do that, send me a direct email (you can get my email from the message sent to you if you configured your settings for notification of replies).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I was learning array and came to a problem I ...
I have a struct containing some info:
public struct SomeInfo
{
public string Value1;
public int Value2;
public SomeClass Type1;
}
And an array of SomeInfo: public SomeInfo[] SomeArray;
So by now I should have an array that every item has 3 properties (Value1, Value2, Type1) and I can access them by doing like this: SomeArray[1].Value1 = ... Right ?
The only problem here is that the size of SomeArray array if fixed (I cannot add any more items if the array is full). I also cannot use ArrayList, because that way I cannot access the array item's properties (Value1, Value2, Type1), right ? So what to do ?
Think of as of the classical addressbook example - You have a struct named Person with 3 fields - Name, Age, and a class for some reason. Also a array that contains the list of Persons.
Regards, Desmond
|
|
|
|
|
desmond5 wrote:
I also cannot use ArrayList, because that way I cannot access the array item's properties (Value1, Value2, Type1), right ? So what to do ?
I guess that you can access the item properties in a similar way when using ArrayList , but you must cast the type of the item to SomeInfo like this. I'm not 100% sure but I think it works like this:
((SomeInfo)SomeArrayList[i]).Value1 ...
Let me know if this helps
rado
Radoslav Bielik
http://www.neomyz.com/poll [^] - Get your own web poll
|
|
|
|
|
I can't try right now, but isn't there any other way ?
|
|
|
|
|
I can't try right now, but isn't there any other way ? What else could I do ?
|
|
|
|
|
The previous post isn't correct.
When you instantiate an array, the elements Types of that array are not instantiated. All you have is an array of your Type, in which the array is derived by the CLR from System.Array . In order to instantiate each element in the array, you must do so by iterating through each element:
public SomeInfo[] SomeArray = new SomeInfo[3];
for (int i=0; i<SomeArray.Length; i++)
SomeArray[i] = new SomeArray(); If you want to make your struct easier to use, you can add a constructor that takes params of the Types you need for your members. The only restriction when declaring constructors is that - for structs - you cannot declare the default constructor (parameterless constructor):
public struct SomeInfo
{
public SomeInfo(string value1, int value2, SomeClass value3)
{
this.Value1 = value1;
this.Value2 = value2;
this.Value3 = value3;
}
public string Value1;
public int Value2;
public SomeClass Value3;
} Then you can either instantiate a default instance (all member types use their default values and reference members (like Value3 ) are null) or an initialized struct when you're looping through (assuming you had a source you could iterate through and pull values from):
string[] names = {"One", "Two", "Three"};
SomeClass theOneInstance = new SomeClass();
SomeInfo[] SomeArray = new SomeInfo[3];
for (int i=0; i<SomeArray.Length; i++)
SomeArray[i] = new SomeInfo(names[i], i, theOneInstance);
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
This works only this way:
string someValue = ( (SomeInfo)SomeArrayList[0] ).Value1;
.. but not this way wich is what I really need (the value in object in array gets a new value):
( (SomeInfo)SomeArrayList[0] ).Value1 = someValue;
P.S. Someinfo is a struct.
How to solve that ?
|
|
|
|
|
You're running into problems because of the value copying. You should be able to solve your problems by changing your struct to a class.
Regards,
Jeff Varszegi
|
|
|
|
|
I was trying to translate a unit from Delphi to C#. What to do with a record type ?
MyRecord = record
Name: string; // String value
Age: integer; // Int value
Proc: TMyProc; // A type
... ....
end;
Should I use use a enum or something ?
Regards, Desmond
|
|
|
|
|
Sounds like a new reference type... which at its most elemental is simply a class that contains public properties:
public class myRecordType {
public string name;
public int age;
public myRecordType {
}
}
somewhere else, you get to say:
myRecordType newRecord = new myRecordType();
newRecord.name = "My Name";
newRecord.age = 24;
is that what you are thinking of?
|
|
|
|
|
Technically, those aren't properties they're fields. The difference is that you can include validation code in property getters and setters (as well as other useful code, like recreating a native window handle or refreshing a drawing surface). With fields, you only get type safety.
To the original poster, you could always use a property to validate a param like so:
private int age;
public int Age
{
get { return this.age; }
set
{
if (age < 18) throw new ArgumentException("You're too young!", "value");
this.age = value;
}
} Both structs and classes can use properties. If you do use properties (and you typically should), make sure you declare the fields as protected or private. If you're going to validate values using properties, make sure you force callers.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I know nomenclature is important, so thanks for the clarification on the distinction between properties and fields... I often make the mistake of over-simplifying these issues... and you provide an amazing level of detail in your posts.
|
|
|
|
|
The one thing I was concerned of was that in Delphi there are both, records and classes (Borland Delphi in basicly Object Pascal). As far as I know, record in Delphi is just a "field-container", it cannot contain any methods or functions, cannot assign any values and etc.
|
|
|
|
|
Yeah, that sounds pretty close to a struct, even though it can contains methods and do several things similar to classes.
To know for sure, you could probably answer yourself better than I (since like I mentioned before I don't know Delphi). If records are allocated on the stack, then they are definitely closer to structs.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I'm not familiar with Delphi, but it seems more like you have a class or struct here. The big difference between the two is that structs are allocated on the stack while classes are allocated on the heap. Classes are reference types so passing instances of classes as parameters passes a reference, where passing a struct passes a copy of the object (unless using the out or ref keywords).
In this case, you might be better of with a struct like:
public struct MyRecord
{
public string Name;
public int Age;
public TMyProc Proc;
} The only thing I'm not sure about is that last member. You say it's a "type" but it almost seems like a function pointer? In that case, you'll want to look up information on delegates in the .NET Framework SDK. If it's just any type, declare it as an object , which is the base class for ALL classes, structs, etc., in .NET.
An enum is more like a grouping of constants that provides type-safe access to such constants in .NET. For example, you could declare a bunch of constants like so:
public const int One = 1;
public const int Two = 2;
public const int Three = 3;
public void SomeMethod(int value)
{
if (value != 1 && value != 2 && value != 3)
throw new ArgumentException("Invalid value.", "value");
} For SomeMethod , it can take any int so unless you want to hard-code and document the possible values, this isn't very type-safe. After all, any int could be supplied. If you only want this to accept certain values, then you should declare it like the following:
public enum MyEnum
{
One = 1,
Two,
Three
}
public void SomeMethod(MyEnum value)
{
if (!Enum.IsDefined(value.GetType(), value))
throw new ArgumentException("Not defined.", "value");
} You still have to validate the param to be sure, but as you can see that's much easier and more flexible that checking it against hard-coded values. It also gives the caller some idea of what he or she can actually pass.
If you're new to the .NET Framework and the C# language (which is just one of many languages that target the Common Language Runtime, or CLR), you should definitely read the .NET Framework SDK to get an overview and review what's available in the base class library. It should've been installed with VS.NET and is also available online at http://msdn.microsoft.com/netframework[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Yes, I think struct is what I need. Thanks.
|
|
|
|
|
how to use CreateProcess function (like in c++) in c#? I found EnvironmentVariable method to access windows environment var but it only has read only property, I cannot set new environment var.
I use CreateProcess to execute wincgi file like php.exe to run PHP file with it's querystring and post data manually.
Thx anyway!!!
laurent
|
|
|
|
|
See the documentation for the System.Diagnostics.Process class in the .NET Framework SDK. If you want to set additional environment variables used by the process, you can initialize a ProcessStartInfo and provide extra string key/value pairs in the EnvironmentVariables property. After assigning a few more properties of ProcessStartInfo , just pass it to a call to Process.Start . See the documentaton for more information and examples.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
1. Process.Start()
2. You can use DllImport and use win32 functions in C# , for more informatiom about it check MSDN and search this site.
Mazy
"Art is life, life is life, but to lead life artistically is the art of life." - Peter Altenberg
|
|
|
|
|
Hi Folks
Hope you all are having a good knowldze on C#.
Here i want to know one thing , At runtime how runtime will decide what to use I mean either virtual one or overrided one.
two more Question
What is the difference between Abstract class and interface
We know some basic differences.
when to use structures and when to use classes
Praveen Chintamani.
|
|
|
|
|
praveenc80 wrote:
At runtime how runtime will decide what to use I mean either virtual one or overrided one.
That is polymorphism, the compiler will take care of that for you. Whatever your object "is a" instance of will be called.
praveenc80 wrote:
What is the difference between Abstract class and interface
Abstract class can't be instantiated. Interface is good to use if you want to enforce a method on certain objects, but those objects might not have a base->child relationship. For example, look at IDisposable, Microsoft classes that implemenet this interface support the Dispose() method to cleanup resources.
praveenc80 wrote:
when to use structures and when to use classes
Your call really. Structures are stored on the stack and classes are on the heap. Strcutures are not as powerful as classes, but are more quickly accessed from memory. I could imagine using structs for something not so object oriented.
Hope this gives you a starting point.
R.Bischoff
.NET, Kommst du mit?
|
|
|
|
|
Soliant wrote:
Abstract class can't be instantiated.
Interfaces are also nice because a class can only extend one other class. If you use abstract classes and need to inherit additional functionality (say, from Control ), you won't be able to because you're already extending one abstract base class. This is where interfaces come in handy because you an implement more than one interface.
Soliant wrote:
I could imagine using structs for something not so object oriented.
Structures should really only be used for small amounts of short-lived data, such as a Size or a Point (both used to position and size a control, but then aren't needed again things change).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|