|
How do resources work in .NET?
I'm just trying to include a bitmap for an imagelist...
However, MSDN talk either about ".rc" files which somehow I cannot add to my project (or can I?), or about .resx files being "the .NET" way and their cute and politically correct features how to localize your dialog resources and web apps (something I promise to look into once I get those friggin' folder icons into my tree view!)
Is there a Tutorial in MSDN? An article on CP? A merciful soul that gives me some step-by-step-instructions?
Oh, when we're at it... :blush: ...how do I get the "hinstance" i need for Bitmap.FromResource? or can I pass "null" for "me"?
Thanks
If I could find a souvenir / just to prove the world was here [sighist]
|
|
|
|
|
peterchen wrote:
An article on CP? A merciful soul that gives me some step-by-step-instructions?
Yes, JTJ has written a nice article on embedded resources in .NET. Understanding Embedded Resources in Visual Studio .NET[^]
Nick Parker
Not everything that can be counted counts, and not everything that counts can be counted. - Albert Einstein
|
|
|
|
|
Hi all
I want to create an ActiveX Control using c# and import it in non .NET application (MFC 6). How can it be done (I dont want a simple class, but visual control)? Generaly, what is the approach of .Net toward ActiveX, can I stil create an ocx file and use it in MFC(6) app?
If Activex is not relevant any more, how can use a .Net (c#) control from MFC app?
It would be greate if u could direct me to some data source about this...
thanks
|
|
|
|
|
I'm a beginner in .NET so take this all with a grain of salt.
An ActiveX control is basically a COM object that produces windows output.
Ergo, you need to construct a COM object in reality - maybe perhaps a COM object that is also a Control.
I noticed in the Articles section there are a couple of articles on COM Interop and creating COM objects out of .NET objects.
-Adrian
|
|
|
|
|
I have the following code which returns a Columns array back to the caller. The code is C# (no really!) with COM interop on the SQLDMO COM object.
SQLDMO._SQLServer sqlserverMain = new SQLDMO.SQLServerClass();
sqlserverMain.Connect(this.ServerName, this.UserName, this.Password);
SQLDMO.Database sqldatabaseCurrent = (SQLDMO.Database)sqlserverMain.Databases.Item
(this.Database, sqlserverMain);
SQLDMO.Table sqltblCurrent = (SQLDMO.Table)sqldatabaseCurrent.Tables.Item
(this.Table,sqlserverMain);
return sqltblCurrent.Columns;
So it creates a SQLDMO server connection, then gets a database, then gets a table and finally gets all the Columns for that table and returns that array.
However there is no sqlserverMain.DisConnect(); because of my problem. Basically if I put in the disconnect code then when I want to use the returned Columns array I get a "This object has been detached from SQLDMO, as the result of a refresh, automatic shutdown, error or App.Quit" error message.
If if leave out the disconnect then it all works fine.
Now my guess is that this is a classic reference vs. value problem with the return array. I am returning a reference rather than the value.
This is probably really, really simple but then how do I return the value and not the reference? I need to disconnect because otherwise I am leaving the connection open and by watching Taskmanager I noticed the app just kept eating memory without releasing every time that specific method was called. With the disconnect (but avoiding the error) the app eats memory and then releases it on disconnect.
ta
Paul Watson Bluegrass Cape Town, South Africa NOPcode wrote:
...but in America, you're not allowed to thrust, moan or see anything...
|
|
|
|
|
Paul Watson wrote:
This is probably really, really simple but then how do I return the value and not the reference?
I am not sure if this will work Paul, but it is worth a shot. Could you return you value as an out parameter? What is the problem with reconnecting to the DB?
Nick Parker
Not everything that can be counted counts, and not everything that counts can be counted. - Albert Einstein
|
|
|
|
|
Nick Parker wrote:
I am not sure if this will work Paul, but it is worth a shot. Could you return you value as an out parameter?
Good idea, will give that a bash, thanks.
Nick Parker wrote:
What is the problem with reconnecting to the DB?
The code that returns the Columns array is in a SQLDMO helper class I made. I could leave the connection open but then I would have to make sure the caller remembers to close the connection, not very elegant or helpful at all. Also the caller may only act on the returned Columns array many minutes later, in which case I don't want that SQLDMO server connection sitting open all the time.
The good old Open Late, Release Early idea
Paul Watson Bluegrass Cape Town, South Africa NOPcode wrote:
...but in America, you're not allowed to thrust, moan or see anything...
|
|
|
|
|
Paul Watson wrote:
The code that returns the Columns array is in a SQLDMO helper class I made. I could leave the connection open but then I would have to make sure the caller remembers to close the connection, not very elegant or helpful at all.
True, so why don't you just close the connection once you have receive the data in a dataset, since you said your not sure when the caller will work with the returning dataset and you have already written a helper class why not just do the clean up inside the function and close the connection.
***
If nothing I wrote above made any sense, don't blame yourself. I have had my head stuck in writing a binary tree for the last two hours, yuck.
Nick Parker
Not everything that can be counted counts, and not everything that counts can be counted. - Albert Einstein
|
|
|
|
|
Nick Parker wrote:
True, so why don't you just close the connection once you have receive the data in a dataset, since you said your not sure when the caller will work with the returning dataset and you have already written a helper class why not just do the clean up inside the function and close the connection
LOL no wonder I was getting confused. I was not thinking of using the DataSet (or any ADO.NET) at all. I was hopping the SQLDMO Columns collection could work disconnected, but alas no.
I am going to go the DataSet route now thanks to your and .S.Rod.s advice
ta
Paul Watson Bluegrass Cape Town, South Africa NOPcode wrote:
...but in America, you're not allowed to thrust, moan or see anything...
|
|
|
|
|
Paul Watson wrote:
This is probably really, really simple
Yes, that's simple. You can't read a query result on a disconnected database.
That's why ADO.NET introduces datasets. Fill the dataset, then you can disconnect from sqlserver if you like.
|
|
|
|
|
.S.Rod. wrote:
Yes, that's simple. You can't read a query result on a disconnected database.
That's why ADO.NET introduces datasets. Fill the dataset, then you can disconnect from sqlserver if you like.
Maybe I really have the wrong end of the stick but...
The connection and all other database bits are using SQLDMO and AFAIK it does not go through ADO.NET in anyway, right?
Also you are right in that even with SQLDMO once cannot return any query on a disconnected database. What I did there was before the return I created a new Columns var, passed the Columns array from the still connected connection, then disconnected and returned the new Columns var.
At first actually I thought that would get around the whole problem, but I think it was still a reference and not a value and so the error persisted.
Paul Watson Bluegrass Cape Town, South Africa NOPcode wrote:
...but in America, you're not allowed to thrust, moan or see anything...
|
|
|
|
|
Paul Watson wrote:
The connection and all other database bits are using SQLDMO and AFAIK it does not go through ADO.NET in anyway, right?
Right.
That's why I have said that's up to you to use a ADO.NET dataset as a container for the query result. This requires a few lines of code from you, to fill the dataset with a COPY of the pointed query result. Indeed, there is no direct support for this using sqldmo.
I am talking about a dataset since it's a natural way of storing data with .NET, even though you could just have arrays of strings if you liked.
Of course, the usefulness of sqldmo is questionable, since ADO.NET provides the .NET SQLServer data provider, which does the same job than sqldmo.
Paul Watson wrote:
What I did there was before the return I created a new Columns var, passed the Columns array from the still connected connection, then disconnected and returned the new Columns var.
accessing query results requires a connection anyway. Creating new columns just adds references to objects whose target content vanishes as soon as the disconnection happens. Hence the GPF.
|
|
|
|
|
.S.Rod. wrote:
That's why I have said that's up to you to use a ADO.NET dataset as a container for the query result.
OIC what you are saying.
Thanks man, that makes sense. I still have to get into the whole DataSet way of thinking
.S.Rod. wrote:
Of course, the usefulness of sqldmo is questionable, since ADO.NET provides the .NET SQLServer data provider, which does the same job than sqldmo.
Serious? I will look into that then. Would far rather use ADO.NET to get the structure of a SQL Server and it's databases than having to do COM interop on SQLDMO. Hopefully ADO.NET can provide a list of registered SQL servers as well, like SQLDMO does.
Thanks for the help
Paul Watson Bluegrass Cape Town, South Africa NOPcode wrote:
...but in America, you're not allowed to thrust, moan or see anything...
|
|
|
|
|
To get the list of SQL servers on NT/2000/XP, use the code from the Server Enumerator[^] article. If you can see multiple domains, you'll need to enumerate the domains, and then enumerate the SQL servers for each domain. I've got some simple code to enumerate each domain in a new thread, if you want it.
Once you choose the server, you can connect to the master database, and execute SELECT name FROM master.dbo.sysdatabases ORDER BY name to get the list of databases. You could also use sp_databases , but that seems to be slightly slower.
To get the list of tables, connect to the database and execute sp_tables @table_type = "'TABLE'" . (Note the extra quotes around the parameter value.) The important column of the results is TABLE_NAME .
To get the columns of the table, use sp_columns 'Table name' . COLUMN_NAME , PRECISION , LENGTH , SCALE and NULLABLE are all fairly obvious. The TYPE_NAME will give you the name of the datatype for the column, or you can map the SS_DATA_TYPE column to the types defined in srv.h in the Tools\DevTools\Include directory of your SQL Server installation. NB: Watch out for identity columns, with a TYPE_NAME of "int identity".
You can get details of the primary key for the table using sp_pkeys 'Table name' , which will return the list of columns (COLUMN_NAME ) in the primary key for that table.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
Thanks for all the info and I did consider using the built in SPs and tables... The thing though is I like the strongy typed way of SQLDMO. The collections are all enumerable to which makes working with them easier. Using the above is a bit more finicky IMO.
I might then use your way just for the Columns... or I may switch to using ADO.NET and loose SQLDMO all together.
I wonder when SQLDMO.NET from MS is coming out
Paul Watson Bluegrass Cape Town, South Africa NOPcode wrote:
...but in America, you're not allowed to thrust, moan or see anything...
|
|
|
|
|
I'm surprised it's not out already.
I've thrown together a basic read-only library to get the information in a sensible form. I haven't done much testing, and there may be glaring holes in it, but it seems to work on my machine. If I get time, I may tidy it up a bit and upload it as an article.
If you want to try it out, and don't mind dealing with the bugs that are bound to have crept in , let me know and I'll send you the code.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
Hello,
I would like to replace standard runtime error box that displays when an unhandled exception occurs. The new standard error box should contain general unhandled error message along with the option to the user to express the circumstances of the error and send this information directly to our issue management system.
I know there is an AppDomain object that has UnhandledException event. I tried to bind a procedure to this event using AddHandler keyword. Actually I did the same what could be seen as the example in the MSDN library.
Unfortunatelly I found that this is not the way to go. The system default error message box is shown prior to mine. In addition, no all exceptions were catched by this error event handler in compiled application, although they were catched when the application was started from whithin IDE.
Does anybody any idea how to achieve desired functionality?
Thanks for any suggestions.
Vasek
Vasek
VB6, C#, MS DNA, MS .NET software developer
|
|
|
|
|
You don't indicate if this is a web app, a fat client, a component, etc.
Assuming this is a fat client: the only way I can think of how to do this is to write a wrapper application that would be the starting point for all of your executions. It would be passed the name of the application to execute.
Then you would do a TRY and use reflection to load and execute the application. Your CATCH would trap all uncaught errors and you can handle the display of the error.
Of course, a simpler way is to just catch all of your errors.
_____________________________________________
The world is a dangerous place. Not because of those that do evil, but because of those who look on and do nothing.
|
|
|
|
|
theRealCondor wrote:
You don't indicate if this is a web app, a fat client, a component, etc.
It is a fat windows client.
theRealCondor wrote:
Of course, a simpler way is to just catch all of your errors.
I thought there is a simple way how to handle those errors they are left uncought. No way I advocate for not handling errors.
Anyway, thanks for your response
Vasek
VB6, C#, MS DNA, MS .NET software developer
|
|
|
|
|
.NET magazine just did an article on how to do this. Do a google search for "Visual Studio Magazine - Hot .NET Tips - Catch All Exceptions in One Place"
|
|
|
|
|
I have an existing C# program which displays a form and then runs a worker thread that does some work. I have arranged for the form data to be stored within the Registry and restored when it gets run again.
What I would like to do is convert this fairly generic program to have the following features:
1. Check box that enables a NotifyIcon (Remove from Taskbar).
2. NotifyIcon that has a contextMenu that can show the form again.
(context menu has "Show Me" and "Exit" options)
I've read the tutorials on this site on creating NotifyIcon elements. However, I am not sure how to implement the above. Can someone provide some information?
-Adrian
|
|
|
|
|
You need to add a NotifyIcon to your form and to attach a ContextMenu to it.
|
|
|
|
|
I have a legacy COM In-Proccess server, which has an interface
function:
STDMETHODIMP CMyObj::GetData( /*[out]*/ DataStruct* pData )
{
...
}
where DataStruct is defined:
typedef struct AnotherStruct
{
long ID[4];
BSTR Name;
}AnotherStruct;
typedef struct DataStruct
{
AnotherStruct ArrayStruct[4];
long ArrayLong[4];
}DataStruct;
now, when i'm calling this function from the .NET (C# for the matter)
MYOBJECTLib.MyObjectClass obj = new MYOBJECTLib.MyObjectClass();
MYOBJECTLib.DataStruct data;
obj.GetData( out data );
i get an exception: "Not enough storage is available to complete this
operation.", where the source of the exception was the interop.
I tried to look at the data struct and i found out that the C#
compiler, or the interop ( i don't know which one is responsible for
it ) ,that each primitve array in the struct was initialize
automaticly to the size that was defined in the COM typelib( for
example the ArrayLong was initialized to 4 int ) , but the array of
the struct ( ArrayStruct) was set to null.
I tried to modify the code to initialize it myself:
MYOBJECTLib.MyObjectClass obj = new MYOBJECTLib.MyObjectClass();
MYOBJECTLib.DataStruct data;
data.ArrauStruct = new MYOBJECTLib.AnotherStruct[4];
obj.GetData( out data );
but it didn't work.
worth mentioning that when i modified the struct:
typedef struct DataStruct
{
AnotherStruct ArrayStruct;//ArrayStruct[4]
long ArrayLong[4];
}DataStruct;
everything worked ok.
anybody???
Amir Harel
|
|
|
|
|
I guess it's about time to do struct marshaling yourself[^].
|
|
|
|
|
my main application had started a process X and i want my application to be notified when that process had been terminated externally by OS.
i try:
X.EnableRaisingEvents = true;
but what is the event method declaration for my main application's to handle exit event triggered by process X?
thank you.
regards
yccheok
|
|
|
|
|