|
How would i exposs a class library as a COM object. i look through the SDK Docs and still a little lost.
[ ...what to put in here? ]
public class MediaStatusSink : IMediaStatusSink
{....
}
I just need help setting up the class attributes,
here is what im trying to do:
A sink is a COM component that supports the IMediaStatusSink interface and is registered as a member of the CATID_MediaStatusSink {FCB0C2A3-9747-4C95-9D02-820AFEDEF13F} component category.
in the registry editor at
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Component Categories\{FCB0C2A3-9747-4c95-9d02-820AFEDEF13F} i have:
(default) REG_SZ (value not set)
409 REG_SZ Media Status Sink
modified 16-May-21 21:01pm.
|
|
|
|
|
You create a new GUID using the GUID generate in the Tools menu, or the uuidgen.exe, or whatever preferred method you want. Then use the GuidAttribute on your class. Typically, you never change this GUID. You also attribute any class interfaces with a different GUID and after publishing your interfaces (i.e., releasing your code, etc.), never change it. Instead, inherit from that interface with a new one and a different GUID, and implement that as the first interface instead making it the class interface.
The GUID you're looking at is a category ID. I'm not sure what you're trying to do, but if you simply want to implement the interface, you can use any GUID you want. If you're trying to manually interop an existing class, then you can use oleview.exe to find the class and get its CLSID, which is what you'd put in the GuidAttribute on your class declaration.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Could someone please post a step by step tutorial on getting an access database to work on a asp.net form with c#? I have read a few things like changing the <appsettings> and then making a connection string. I'm still very confused. I thought that it was like winforms you simply drag the oledbdataadapter over to the form then generate a dataset and then in the code simply fille the dataset with oledbdataadapter1.fill(dataset);
I haven't a clue how what needs to be changed in the web.config file. I have a book but it assumes i use sql server. Unfortunate for me I don't have the money to buy an sql server so i'm forced to use what i have access too which is office access xp. Once again if you could direct me to a site that assumes i know nothing about c# webforms that would be great. Or simply make a webform with a dropdown menu that gets some values from a mdb.
thanks for your time. i constantly get the database is in use or you don't have permission to use it when i try. if you need some code examples of what i'm doing that would be fine just let me know. I would prefer a tutorial though so i don't get totall confused. Oh wait I already am totally confused.
Win32newb
"Making windows programs worse than they already are"
|
|
|
|
|
I've already told you, and this is very easy to do. In your Web.config file, put your connection string in the <appSettings> section:
<configuration>
<appSettings>
<add key="ConnectionString" value="your connection string"/>
</appSettings>
</configuration> When you need to create your connection, use:
string connString = ConfigurationSettings.AppSettings["ConnectionString"];
if (connString != null)
{
OleDbConnection conn = new OleDbConnection(connString);
} This allows you to change your connection string at any time so that your project is also easy to deploy.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath,
Sorry for not grasping it the first time you posted the answer. I was still confused but finally figured out what i was doing wrong. Its working now. Do you recommend a book for someone like myself that is just getting into c# and asp.net? I'm as you can tell stumbling over the simple things and really would like to learn. I just hope I don't get on your nerves or anyone elses for that matter for not understanding. Thanks for your patience with me on my quest for knowledge in c#.
Win32newb
"Making windows programs worse than they already are"
|
|
|
|
|
Just read through the articles and class documentation in the .NET Framework SDK. That's the best way to learn. There is books out there, but I can't recommend any since all I did was read through the SDK and got a sense of where everything was and what they do, read articles on sites like CodeProject (though there wasn't too many back in the 1.0 beta days), examined a lot of the MSIL in the .NET FCL assemblies, and just wrote lots of various projects trying different things.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I finally got it populating the dropdownlist from the dataset. I do have a question though for some reason i can't figure out why the index is always 0 regardless of what i select. What i'm trying to do is select an index in the dropdownlist and then have it display some information in the textbox2.
public DataSet dataset;
private void Page_Load(object sender, System.EventArgs e)
{
string datapath = Server.MapPath("bin/csharp.mdb");
string connString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]+datapath;
if (connString != null)
{
oleDbConnection1 = new System.Data.OleDb.OleDbConnection(connString);
}
oleDbConnection1.Open();
OleDbDataAdapter dataadapter = new System.Data.OleDb.OleDbDataAdapter("select * from Csharp",oleDbConnection1);
dataadapter.Fill(dataSet11,"Csharp");
oleDbConnection1.Close();
DropDownList1.DataTextField ="Help";
DropDownList1.DataValueField="Help";
DropDownList1.DataSource = dataSet11;
DropDownList1.DataBind();
}
private void Button1_Click(object sender, System.EventArgs e)
{
TextBox2.Text = dataSet11.Csharp[DropDownList1.SelectedIndex].Information.ToString();
}
for some reason as i mentioned before the page refreshes on the button push but it always reads whats in index 0.
thanks for the help and patience with me.
Win32newb
"Making windows programs worse than they already are"
|
|
|
|
|
Make sure you've enabled the ViewState for the control and/or page is enabled. Also, don't call ToString until after you've checked for null or use a try/catch block, though easy problems like this can easily be solved using conditionals and would result in better performance than throwing an exception, which is more expensive.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi folks,
Consider an SQL Server table that has got a PK (auto-identity column), which
has been referenced by another table as a FK. Then imagine 2 DataTables that
has been created to refer to the above-mentioned SQL Server tables, either
partially or completely. I need to know how can I read/write these
DataTables from/to those DataSources using the OleDbDataAdapter.
It goes without saying that when you insert a row within the first source table, you'll get an IDENTITY that has to be referenced by the second table as the FK's value. The thing that I cannot understand is that how I can possibly interact with these 2 DataTable(s) through the OleDbDataAdapter and how to map DataSource-DataTable columns to each other as well as how to get the newly added IDENTITY and insert it in the second DataTable.
Any sample would be highly appreciated
Thanks in advance,
Mehdi Mousavi - Software Architect [ http://mehdi.biz ]
|
|
|
|
|
First, don't use the OleDbDataAdapter for SQL Server! Use the SQL Server-specific classes in the System.Data.SqlClient namespace. They exhibit much more functionality and provide features that the generic OLE DB providers can't provide (at least in an abstract manner).
Second, use a typed DataSet , or construct one programmatically at runtime (not fun). You can create an identity column in one of your tables. When you insert a row into that DataTable , the column value is incremented to the next identity using your incremental step. This allows your FK column to reference the identity PK. This is easy to do.
The trick in a multi-user database-driven application is when you use that DataSet to update the database using SqlDataAdapter.Update . You should read the article, Inserting relational data using DataSet and DataAdapter[^]. Basically, your InsertCommand should also include a SELECT statement to make sure the DataSet is updated appropriately. The relationship that would exist in the DataSet for the PK/FK would update the FK with the PK value that was actually used when the row was inserted.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:First, don't use the OleDbDataAdapter for SQL Server!
We might change the Database engine later from SQL Server 2000 to Oracle 9i, and that's why we tried to use the OleDB Data Provider.
Heath Stewart wrote:
Second, use a typed DataSet, or construct one programmatically at runtime (not fun).
I don't see anything fun in this quote. I've never ever used an untyped DataSet, since it has got many drawbacks...
Heath Stewart wrote:
You should read the article, Inserting relational data using DataSet and DataAdapter[^].
Thanks a lot, I read the article and it will certainly solve my problem after two damn weeks of trying to post the same question here and there.
I do really appreciate your help.
Thank you for your time,
Mehdi Mousavi - Software Architect [ http://mehdi.biz ]
|
|
|
|
|
Mehdi Mousavi wrote:
We might change the Database engine later from SQL Server 2000 to Oracle 9i, and that's why we tried to use the OleDB Data Provider.
Reasonable enough. I just get used to saying this because so many with no such plans use the OLE DB provider and are trying to do SQL Server-specific things many times.
Mehdi Mousavi wrote:
I don't see anything fun in this quote. I've never ever used an untyped DataSet, since it has got many drawbacks...
Constructing typed DataSet classes using the DataSet designer is definitely a heck of a lot easier than trying to code the same thing, plus gives you typed access to columns which is much faster. Sure, the same thing could be done manually, too, but again it can be tedious.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
my computer is stand alon and connected to a busy router( which is been serving its services for different ISPs ) how can i communicate with that router to get knowledge of about its channel connection quality (like parameters latency, pakcet loss etc)
kashif<programming luvr>
|
|
|
|
|
This is specific to the firmware for the router. You need to consult the router manufacturer web site for details, if any are provided.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
use SNMP to communicate with the router.
but I haven't done something like this in c# til now.
|
|
|
|
|
|
Dear forum members,
I have controls (UserControl) designed in C#.
Can anyone tell me how I can embed them in MFC dialogs/views (in VC7) ?
Any sample code will be very helpful.
Thanks in advance.
|
|
|
|
|
|
hi,
do u know how to write and read from serial port. actually i have done the write and read but i do not know how to configure the port.
do anyone know in c#?
bye thank u
|
|
|
|
|
There are several articles on this here on CodeProject and it has been covered before in this forum. Please search the CodeProject site for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
|
Often, in my code, I use the following construct:
string someStr = "sdlkfj" + someOtherStr + "slkdfj";
One of my colleague rather uses the following:
string someStr = String.Format("sdlkfj{0}slkdfj", someOtherStr);
Which one do you think is better, and why?
Thanks
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
|
|
|
|
|
If your code uses "your way" of doing things often, your colleague's way is better. Performing the operation the way you specified:
string x = "bob" + stringObj + "bob";
actually allocates memory for all three RHS values (iirc), not to mention the fact that string concatenation in itself is not particularly speedy or memory efficient.
However, if you only use it sparingly, or in non-critical sections, your way doesn't really have a problem either. I generally use string concatenation unless performance becomes an issue, in which case I usually switch over to a StringBuilder.
Jeremy Kimball
magnae clunes mihi placent, nec possum de hac re mentiri.
(Large buttocks are pleasing to me, nor am I able to lie concerning this matter)
|
|
|
|
|
Jeremy Kimball wrote:
actually allocates memory for all three RHS values
Actually, it doesn't. The C# compiler compiles simple string concatenation to calls to String.Concat , which only allocates once.
StringBuilder also has interesting issues: see Concatenating with StringBuilders vs strings[^].
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
The strings are still allocated each time:
string s = string.Concat("One", "Two", "Three"); ...still allocates three strings in order to concatenate them.
Microsoft MVP, Visual C#
My Articles
|
|
|
|