|
I am working on a C# .NET Winforms project, and I'm stuck on an obscure issue relating to COM and .NET. No one in the company I work at is particularly experienced in COM / .NET interop, and I've already spent too many hours searching books and internet sources for good information on the topic. I was hoping that some person with experience could shed some light on how I should proceed.
Here's the issue:
I am rewriting legacy code that was written in C and C++. The purpose of one piece of legacy code is to display all COM libraries in the registry and allow the user to select the name of the COM library they want and the name of the COM object (in that library) that they want. It then saves information about the COM object (library GUID, interface GUID, and class GUID) of this COM object into a database for further use.
It accomplishes this task by creating an ITypeLib object, which is used to open the library and extract the introspection data from the library. *(note: the COM "introspection" concept is known as "reflection" in .NET)
The System.Runtime.InteropServices.ComTypes namespace (in C#) has an ITypeLib interface (and other interfaces that I need), but I can find no example of anyone implementing this interface in a usable way, and if I knew how to implement that interface to extract the data I need, I wouldn't have a problem in the first place.
Using C#, I can already extract the COM library information I need from the registry (all the library GUID's, descriptions, and full paths), but after that I'm stuck, as I cannot read these libraries for their introspection data.
Does anyone have a clue as to what I need to do next? If so, thanks a lot in advance.
|
|
|
|
|
After a lot of pain and searching, it seems that no one has a class that implements these interfaces in System.Runtime.InteropServices.ComTypes, so for the sake of the project timeline, I'm just going to write my own COM library with a function that does what I want that I will P/Invoke in my C# code (and ignore the ComTypes namespace alltogether).
|
|
|
|
|
Hi,
Im just searching a good class to get info from a Jpeg file without loading it usign c# LoadFromFile,
Anybody knows a good class for it ?
Im asking before trying to write one on my own.
thx in advance
|
|
|
|
|
What's wrong with LoadFromFile?? If you're referring to the fact that it locks the file for the life of the Image object, here's[^] another way to load the file without locking it.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Thx i knew and im currently using it,
But the problem is than im reading info from about 450.000 images and I dont need to show them just i need to read image headers to get info about size, bitdepth, etc...
|
|
|
|
|
Marcos Hernandez wrote: I dont need to show them just i need to read image headers to get info about size, bitdepth, etc...
Well, the problem with that is some of the information isn't in the headers, but generated from the image data itself. Also, some file formats put metadata in the header of the image data, some at the tail of the image, and still others at both ends.
I don't know of any library that will get you just the metadata without reading the entire image file.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I have a class that reads a JPEG file into memory, scans the byte array sequentially,
recognizes the major blocks ("markers") in it and extracts the width, height and pixel depth
from a SOF0/.../SOF15 block. It is 300 lines long, and would need some adaptations
to suit your needs.
When I look at the images from my Olympus camera, the file size typically is 800 KB,
and the metadata you want is located around 16 KB from the start.
If interested send me an e-mail.
Luc Pattyn
|
|
|
|
|
Thanx mate,
Im gonna work today on it,
thanx for your help
|
|
|
|
|
waiting for e-mail, so I can reply with attachment...
Luc Pattyn
|
|
|
|
|
I have created a custom web control and I've added a property that will display a list of given values. I created a enum type and set my enumerators list values, but I can't have any white spaces in my list. How can I show list values that have white spaces using the enum type?
Any suggestions would be appreciated! Thanks in advance.
MVPenn
|
|
|
|
|
You can't. Enums are for your code to understand. Essentially like giving a code-usable name to a value, kind of like a variable. They're not meant for use as a UI element.
What are trying to do with this?
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I wanted to show a more "user friendly" description in the listbox on my web control property.
For example:
public enum Diseases { Hepatitis A, Hepatitis B, ...}
public enum fonts {Arial Black, Arial Narrow, Arial, ...}
I'm not sure if I should be using the enum type to populate a list property on a custom web control. Is there a better solution to accomplish this? I'm relatively new to development and would appreciate any suggestions that you might have on this.
Thanks for your response.
MVPenn
|
|
|
|
|
MVPenn wrote: I'm not sure if I should be using the enum type to populate a list property on a custom web control.
Obviously you can't, at least not the way you want to.
MVPenn wrote: Is there a better solution to accomplish this?
The easiest thing that comes to my mind is declaring a simple string array:
public string[] Diseases = new string[] { "Hepatitis A", "Hepatitis B" };
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Try this:
public static string EnumHelper(Enum value)
{
description = value.ToString();
MemberInfo[] mi = value.GetType().GetMember(value.ToString());
if (mi != null && mi.Length > 0)
{
object[] att = mi[0].GetCustomAttributes(typeof(Description), false);
if (att != null && att.Length > 0)
description = ((Description)att[0]).Text;
}
return description;
}
Then, in your enumeration all you need to do is:
public enum Diseases
{
[Description("Hepatitis A")]
HepatitisA,
Eczema,
}
Then, in your code you will do the following:
string hepA = EnumHelper(Diseases.HepatitisA);
This returns Hepatitis A.
string ex = EnumHelper(Diseases.Eczema);
returns Eczema.
I hope this helps.
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
MVPenn wrote: public enum Diseases { Hepatitis A, Hepatitis B, ...}
public enum fonts {Arial Black, Arial Narrow, Arial, ...}
In the past I've done something like this:
public enum Diseases { Hepatitis_A, Hepatitis_B, ...}
And when you need to display the "friendly" values just use the String.Replace function to get rid of the underscores.
|
|
|
|
|
I've never hard coded anything in a enum like this. I've always put my options like this is a database or XML file. It's easier to modify that file than it is to modify the code and deploy a new app if the options change.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi MVPenn,
Create your own attribute (you may wish to call it EnumDescription).
You can find some examples over the net. For example:
Example
Recall that if you want to display friendly names for property name - you can use the "DisplayName" attribute.
Unfortunately, this attribute can not be applied for enum members. Hence (as i said before) have to create your own enum description attribute.
elaj
|
|
|
|
|
Hello everybody,
I have a problem which needs to get all the links on a web page. I am able to get the html source code from a web page in astring. I want a regular expression Which gives all the links (href attributes' values from that code). If Any body could help me in that aspect,Please provide it soon,
Thanking You.
|
|
|
|
|
|
hi i have a small problem.
how can i have 2 forms that i can controll at the same time ?
so if i make Form.Show() <-- the other form is not available.
greeting gigo
|
|
|
|
|
Please explain the problem a bit better.
Creating an instance of Form2 in Form1 and calling form2.Show() should work just fine.
|
|
|
|
|
Could you explain a little more clearly what you mean. You want two forms to display at the same time?
Form1.Show();
From2.Show();
These are not modal calls and will cause both forms to display, though one may be covered by the other.
only two letters away from being an asset
|
|
|
|
|
ok thanks ..
but this doesnt fix my problem
the problem is the same (the form2 is working and block the hole application and also form1)
greeting gigo
|
|
|
|
|
How did you show the second form? Using .Show() or .ShowDialog() . THe problem your describing says your used ShowDialog() to display the second form.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
How to Maintains performance while rows are added to the DataGridView one at a time by preventing the control from drawing until the EndUpdate method is called?
|
|
|
|