Thanks, that might be just what I was looking for. F.O.R.
Frank Olorin Rizzi
Posts
-
Calling unmanaged code -
Calling unmanaged codeHi all. I haven't found an answer to this through quite some googling and searching, so I hope someone can provide some tips. Here's the deal: How can you call unmanaged code from a C# app? Yeah, I know about a few ways to do it, but they all seem to rely on the DllImport attribute initialized with the name of the DLL to be called at compile-time. For instance: [DllImport("msvcrt.dll")] in my case, I will not know the name of the unmanaged dll to be called until run-time. The name of the dll will come from a config file. So, imagine string unmanagedDll = this.GetUnmanagedDllNameFromConfigFile(); and now, is there any way to *programmatically* do the equivalent of [DllImport(unmanagedDll)] ? Thanks in advance for any suggestion, F.O.R.
-
The final hours of Half Life 2Yap, just went through all of it (I found the article before reading your post :-)... ..I'm thinking to pass it on to the managers were I work.. they *should* be interested in reading a post-mortem of a project *that* complex, right? F.O.R.
-
Looking for feedbackI hope you won't take this as inappropriate self-promotion... ..I am really looking for feedback on this C# App to see where to go with the second release: http://www.codeproject.com/csharp/myUML\_1\_pack.asp Hope you find the article interesting as well ! F.O.R.
-
Array questionWell...
static public Data data[] = { new Data(0, "Zero"), new Data(1, "One" ), new Data(-1, NULL )};
In a sense, it's the only logical thing to do (and allow).. After all, in C# arrays are actually a type of their own (unlike the older C style case where an array is just a pointer). So, while the first line begins the instanciation of a new Array of Data, you still have to instanciate and initialize each data (hence the other lines look like they do). The longer version of the same code is (forgetting about static and public):Data[] data = new Data[3]; data[0] = new Data(0, "Zero"); data[1] = new Data(1, "One"); data[2] = new Data(-1, NULL);
Until the second line, data[0] has not been instanciated to be a Data object (yet, data[] has been instanciated to be an array of Data objects that can accomodate 3 Data instances). Might seem inefficient, but, thinking of the Data instances as objects of their own right, it makes sense (sort-of)... ..sure, in your case they are structs, but I think that at this point they just figured it was better to avoid a different syntax for structs vs classes... I saw this situation in Java the first time, and it took a bit to get used to it (yeah, I kept on thinking that after Data[] data = new Data[3] all three data objects where instanciated, pointing to NULL... again, they are not pointers!). F.O.R. -
? The Key EventsGo it ! Phew* ! I was seeing only KeyDown message boxes because of timing issues; before that, I was doing a mistake in the code of the KeyUp handler and the shiftPressed was being set to true when I was de-pressing the key. For anyone else who needs this, this seems to work:
private void myApp_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { if(e.Shift) shiftPressed=true; e.Handled=false; } private void myApp_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e) { shiftPressed=e.Shift; }
We now return you to the universe next door. F.O.R. -
? The Key Events[mode="frustrated"] ARGH ! [/mode] Please, please, if you can help with this, *please* do so: I'm about to loose my mind on it :-) Here's the problem: I'm developing a simple WinForm application. Among other things, I'd like to set a private boolean flag, called "shiftPressed" to true when the user is pressing the Shift key. This flag is checked when doing other things (such as clicking on the form) to modify the behavior of the application as needed. So, I figured the logical thing to do was to intercept the KeyDown and the KeyUp events. In the Key down event, I would set the flag to true if the Shift key is pressed; in the KeyUp event I would unset the flag as needed. However, it seems that if I catch the KeyDown, the KeyUp event is not fired, and/or vice-versa (and let's not even talk about the KeyPressed event !). In short, I have
private void myApp_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { MessageBox.Show("KeyDown"); e.Handled=false; } private void myApp_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e) { MessageBox.Show("KeyUp"); }
and I see only "KeyDown" message boxes. Note that the line e.handled=false; can be there or not, but the behavior seems to be always the same. What can I do? Do I have to dive intopublic class TestMessageFilter: IMessageFilter {...}
andpublic bool HandleKeys(Keys keyCode) { bool ret = true; switch(keyCode) { case Keys.Shift: ...do stuff... default: ret = false; break; } return ret; }
??? Thanks in advance, F.O.R. -
SQL anyone ?OK, before I give up on this, let me rephrapse the question :-) Any way I can stick in a C# App the following lines?
sqlr = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &h_env); sqlr = SQLSetEnvAttr(h_env, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, SQL_IS_UINTEGER);
and other statements like that ? They are taken from a C/C++ app that includes and . Maybe I can place them in an un-managed section? It would solve soooo many problems ! Thanks in advance for any input, F.O.R. -
C# codingIf your splash dialog is started by a Main routine, and your MainMenu is just a form, then you should code your button like this:
MainMenu mm = new MainMenu(this); mm.ShowDialog();
the MainMenu will then be displayed as a modal dialog (i.e. the user can't interact with the original dialog -the splash screen- until (s)he closes the MainMenu). I'm not sure how you can then close the splash form, but that's a start, I hope. F.O.R. -
SQL anyone ?Because indeed I am. I am looking for something that has a 1:1 correspondence to the sql.h library from C/C++. Now, while C# has alternatiuve ways to achieve the same goals (all of the Data namespace, for instance), I am not surprized to find that C# keeps you away from such low level kind of stuff. It indeed makes much more sense for me to use a C++ (managed or not) app in this case, but I figured I could look around for a bit before giving up on being more modern :-) F.O.R.
-
SQL anyone ?Hmmm... ..I didn't know that 1.1 had an Odbc namespace! I'll take a look, thanks :-) F.O.R.
-
SQL anyone ?Thanks Rob, but that's not exactly what I was looking for. I suspect I'll end up moving to C++ one way or the other :-) Thanks again, F.O.R.
-
SQL anyone ?So, ehr... ..hope you won't think that this question is in the wrong forum, but.. You remember all the good'ol'SQL APIs like SQLConnect, SQLFetch, ... ? How can I access those from a C# app? I've tried to use the System.Data.SqlClient namespace stuff, but that is targetted for SQL Server DBs, and I am just trying to do something more ODBC-oriented (i.e. that would work with other DBMS as well). To be specific: I really, really, **really** need to execute an SQL call (rather than using Data Sets, and such). Is it possible in C#, or should I just go back to C++ ? Suggestions anyone? Thanks in advance, F.O.R.
-
DRawable Panel, Resize and Scrollbars !Got it ! Just for future reference of anyone who stumbles upon this: look at the following two articles here on CodeProject: http://www.codeproject.net/books/1861004990.asp and http://www.codeproject.com/cs/miscctrl/tracker.asp As a summary, I think my main mistake was to set the AutoScrollMinSIze to a value that was too small (5,5). Once I set this to the value of the highest X (and Y) coordinate of the stuff I was drawing, it worked much better! HTH, F.O.R. PS: funny thing is I *do* have the WROX book from the first link, but I left it at the office !
-
DRawable Panel, Resize and Scrollbars !This is starting to get to me ! So, let me ask you all, just in case someone has a quick solution for my problem. Here's what I would like to do. Imageine a simple Win App, with a main form with a couple of buttons, and a panel. The buttons are "Rectangle", "Ellipses", and "None". If you click on the "Rectangle" button, you can draw a rectangle in the panel (by clicking-dragging in the panel). Similarly, if you click on the "Ellipses" button, you'll be able to draw an ellipses in the panel. The "None" button is there simply to let you go back to your standard mouse situation. So far so good. I got all of that working by using the GDI+ DrawRectangle and DrawEllipses functions. Now, my problem is that I can't make the panel pop-up the scrollbars (both vertical and horizontal) as needed. In other words, if I open up the application, maximize it to full screen, and draw something in the lower-right corner of the panel, when I resize the application to a smaller size, the drawn object does not show up in the panel (duh! it's out there somewhere). But, most importantly, the scrollbars of the panel do not appear either ! I've tried to set to true the AutoScroll property of the panel, and set the minimum size and the actual size of the scrollbars to (5,5), but that had no impact. As far as I can tell, the problem is that the AutoScroll property comes into play only if some "Control" is placed outside the viewable area of the panel at some point, while the rectangles and circles are (being drawn with GDI+) not considered controls ! Any suggestions ? Thanks in advance for your 2 pennies :-) F.O.R.
-
ODBC QFor anyone who may stumble upon this... A colleague of mine actually fixed this to work. Apparently, he simply added the .def file to export all of the various TraceSQL* routines. In addition to that, he had to include the FireVSDebugEvent and TraceVSControl routines to the .def file. Looking at his source, and mine, I guess mine wasn't working because I had __declspec(_stdcall) (or something like that...I'm not 100% sure yet). In short: the source code from MS seems to work once you add the .def file. Hope this Helps, F.O.R. PS: Props to my colleague, and to Brannon, who sent some helpful hints as well!
-
Poor planning or good marketing?They did the same with the first movie, and, both then and now, I'd rasther pay money for the extended disc with a preview of the next movie. The *really* bad part is that I will end up forking more green bills when they'll have an "ultra-mega-extended" edition with all three movies in. Plus.. the 20th anniversary will prompt them to do Yet Another Edition, and so on and so forth... [sigh/] F.O.R.
-
(Rich) Text Box and cursor positionWell, so far here's what I found... if anyone has any better idea, feel free to post :-)
//In the handler for the mouse-click on the rich text box... //where e is the System.Windows.Forms.MouseEventArgs parameter... int ndex = this.rBox_MarkedUp.GetCharIndexFromPosition( new System.Drawing.Point(e.X, e.Y)); int line = this.rBox_MarkedUp.GetLineFromCharIndex(ndex);
ndex is now the 0-based index of the char clicked and line is the number of the line (0-based as well). We now return to the usual stream of questions :-) Thanks, F.O.R. -
(Rich) Text Box and cursor positionHi all. I've searched through the forums but couldn't find an answer. I have a rich text box (but the question stands even for "simple" text boxes), and I would like to get the cursor's position within it. Something like "line X column Y", or even just "char Z". Any suggestions? In particular, I'm trying to get to this info from the handler of a mouse click event on the rich text box --just in case the System.Windows.Forms.MouseEventArgs parameter can help Thanks in advance, F.O.R.
-
Wouldn't it be cool if..Since Google monitors all the searches, if we were willing to give up some of our oh-so-prixed privacy, they could let us know who shares the searches we make. That would be cool ! It sure would help when needed for technical questions, and would be fun for the rest... F.O.R.