473,396 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

What to do when numeric resource ID is required in .NET?

Several attributes and interface methods I'm using refer to resources (such
as strings or icons) by a numeric ID. This was the only way to refer to
resources in unmanaged code (C++, for example), but I'm writing in C# now,
and it seems that resources are named with string identifiers.

Visual Studio doesn't seem to like resource names such as "100", so I'm
wondering how this could work. Is it absolutely necessary for me to have a
satellite DLL project which uses the old .res (unmanaged) resource format?

Confused...

-Scott
Oct 3 '05 #1
1 4107
"Scott Smith" <paul@nospam_colton.net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Several attributes and interface methods I'm using refer to resources
(such as strings or icons) by a numeric ID. This was the only way to
refer to resources in unmanaged code (C++, for example), but I'm writing
in C# now, and it seems that resources are named with string identifiers.

Visual Studio doesn't seem to like resource names such as "100", so I'm
wondering how this could work. Is it absolutely necessary for me to have
a satellite DLL project which uses the old .res (unmanaged) resource
format?

(snip)

OK, I think I've resolved this. For those who are curious, here's a
clarification of the problem, followed by the resolution...

There is an attribute that you can apply to your
Microsoft.VisualStudio.Shell.Package derived class:

[Microsoft.VisualStudio.Shell.PackageRegistrationAt tribute(UseManagedResourcesOnly
= true)]

This says that you're not going to be referring to resources such as strings
in an unmanaged satellite DLL. Instead, strings, icons, bitmaps, what have
you, are going to be in your assembly as managed resources.

So then, when you implement the IVsInstalledProduct interface in your
Package-derived class, you're faced with implementing methods such as the
following:

public int IdIcoLogoForAboutbox(out uint pIdIco)

....but managed resources are identified by strings. Perhaps the caller of
this method (or the resource loader that it's using) will convert this
integer into a string (e.g loading a resource named "101").

This seemed reasonable, and the "...\Visual Studio 2005
SDK\2005-09\VisualStudioIntegration\Samples\IDE\CSharp\Refe rence.Package"
sample does exactly this. It has several string resources, a bitmap and an
icon, all named using a number like "101".

Whenever I tried to name a resource with an identifier like "101" in my
solution, it generated an error saying something like "the identifier must
start with an alpha character, or underline". I even tried copying the XML
contents of the .resx file from the sample project into my Project's .resx
file. I still got the errors.

I was convinced at that point that there must be some kind of flag or
setting in one project that wasn't present in the other. After a
side-by-side comparison, looking at the properties for my .resx file, I
found it in the "Custom Tool" property:

Custom Tool ResXFileCodeGenerator

Not sure whether this is something new to VS 2005, but this creates a new
class ("{your-resx-filename}.Designer.cs") with type-safe properties to
retrieve every resource in your .resx file, e.g.:

internal static string _101 {
get {
return ResourceManager.GetString("101", resourceCulture);
}
}

....the property name ("_101") is based on the resource name, and as you can
see, if your resource name is numeric, the result is an invalid C# property
name. If you set the "Custom Tool" property to empty, the generated
....Designer.cs file goes away, and Dev Studio doesn't complain about the
resource names any more.

-Scott Smith
Oct 4 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: entoone | last post by:
I have a field called pword, whenever someone enters anything but numeric, i.e. mixed alpha with numeric, or even just alpha.. the following error appears. Warning: mysql_numrows(): supplied...
5
by: lkrubner | last post by:
I have a webserver through Rackspace. I create a domain. I create an FTP user. I upload some files. I create a database called testOfSetupScript and then I create a database user named setup. I...
226
by: Stephen C. Waterbury | last post by:
This seems like it ought to work, according to the description of reduce(), but it doesn't. Is this a bug, or am I missing something? Python 2.3.2 (#1, Oct 20 2003, 01:04:35) on linux2 Type...
39
by: Holly | last post by:
I'm trying to validate my code and I can't figure out what kind of doctype I have. The validator can't tell me anything because it can't move beyond the doctype declaration. ...
7
by: BBFrost | last post by:
I'm receiving decimal values from database queries and placing them on a report page. The users want to see the following .... Db Value Display Value 123.3400 123.34...
3
by: Saradhi | last post by:
How to get the names of all the Resources embedded in a Resource File? -SARADHI
7
by: Wysiwyg | last post by:
Is there any way to add an embedded resource to a project without copying it to the project's directory? I have shared resources and don't want each project using the images, xml files, etc. to...
1
by: Scott Smith | last post by:
Several attributes and interface methods I'm using refer to resources (such as strings or icons) by a numeric ID. This was the only way to refer to resources in unmanaged code (C++, for example),...
6
by: CSharper | last post by:
I have following code, if you cut and paste it in VS and compile it you see only an answer of 0. I was expecting values from o through 2999 using System; using System.Collections.Generic;...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.