|
Hi guys I'm not a .net developer, but I have a managed c++ app that I need to work on. I need to find out the name of the .exe currently being run - if someone renames the app from abc.exe to def.exe then I need to be able to call something that tells me the running .exe is def.exe. I've tried my luck with System::Assembly::GetExecutingAssembly()->FullName but it doesnt seem to be working as expected - my app retrieves settings from the registry - originally it was hard-coded to the original name of the app, but I want to be able to rename the app to something else and be able to use another set of config settings. When I rename the app and run it from explorer, it loads up the settings from the original registry key, rather than creating new settings for the new filename. Worst case I'll call ::GetModuleFileName(NULL,,) and copy that into a System::String but there must be a .net function that can do this?
|
# ? May 21, 2007 09:42 |
|
|
# ? Jun 10, 2024 11:21 |
|
beuges posted:Hi guys Can't you just pull the name of the program from the arguments passed into the main method?
|
# ? May 21, 2007 12:23 |
|
Fart Amplifier posted:Can't you just pull the name of the program from the arguments passed into the main method? Not in .NET, no. The string[] args passed to Main() doesn't include the executable name. To the original question: System.Assembly.GetEntryAssembly().CodeBase will return the path to the originally-executed file in URI format (a file:// URL for local paths -- but since .NET applications can be run directly from an [url]http://[/url] location, it could also possibly be that). It should also be in System.Environment.GetCommandLineArgs()[0], for a locally-executed app anyway; but that may or may not be a fully-qualified pathname, depending on how the app was executed. biznatchio fucked around with this message at 12:40 on May 21, 2007 |
# ? May 21, 2007 12:37 |
|
beuges posted:Hi guys If biznatchio's suggestions don't pan out you could try System::Process::GetCurrentProcess()->MainModule->FileName.
|
# ? May 21, 2007 16:34 |
|
I am pulling my hair out. I have a popup window class (much like the MSN 'toaster' windows), but everytime I create and display one, it takes focus from my main application. After creating the window, the program immediately attempts to refocus the main window (which is by no means ideal, even if it worked). Upon being displayed, the popup window again attempts to invoke the main window's Focus method (and I briefly tried to use BringToFront) to no avail. A long time ago I came across a way to make a window unfocusable. I believe the Windows On Screen Keyboard uses this technique. Does anyone know a good way to solve my problem in .NET?
|
# ? May 21, 2007 17:35 |
|
SLOSifl posted:A long time ago I came across a way to make a window unfocusable. I believe the Windows On Screen Keyboard uses this technique. Does anyone know a good way to solve my problem in .NET? This blog post answers your question, and also gives a solution to your problem of a form taking activation focus when it's shown.
|
# ? May 21, 2007 18:42 |
|
biznatchio posted:This blog post answers your question, and also gives a solution to your problem of a form taking activation focus when it's shown. I came across a Win32 way to do it involving ShowWindow and an argument called SW_SHOWNOACTIVATE, but it still took focus. edit: It seems that the window takes focus still, depending on some unknown factor. When the popup window is created as the result of an event outside the main thread, it is shown unfocused. When the window is created by the UI thread directly, it takes focus. In the case of the off-thread creation, the popup window is constructed and shown using Invoke. SLOSifl fucked around with this message at 19:08 on May 21, 2007 |
# ? May 21, 2007 18:50 |
|
SLOSifl posted:edit: It seems that the window takes focus still, depending on some unknown factor. When the popup window is created as the result of an event outside the main thread, it is shown unfocused. When the window is created by the UI thread directly, it takes focus. In the case of the off-thread creation, the popup window is constructed and shown using Invoke. Does the SW_SHOWNOACTIVATE thing in combination with the WndProc() override work?
|
# ? May 21, 2007 19:20 |
|
When I used ShowWindow, the window wouldn't take focus, but it wouldn't run through my OnShown event handler. When the window is shown, it runs through code that fades it in from transparent to opaque. It also positions the window. I moved things around so that it called my positioning and fading code, using ShowWindow in there as well, and it started taking focus. I have no idea what the hell is going on anymore. As far as I can tell, I'm telling the window in at least two ways to never take focus. Ever.
|
# ? May 21, 2007 19:53 |
|
This may not be a (direct) programming question, but I'm writing a .Net 2.0 app that my client would like to be able to run off a network share. I remember seeing somewhere that i need to modify the security permissions of the app to allow it to run from the network, but other than that, are there any issues I should be aware of with allowing multiple users to run a .Net app off a share?
|
# ? May 21, 2007 20:13 |
|
^^^^^^^^^^^^^^^^^^ Why not use clickone? http://msdn2.microsoft.com/en-us/netframework/aa497348.aspx
|
# ? May 21, 2007 21:18 |
|
I have a GridView set up to display the results of a DAL query. I'm making the primary key column invisible. However, on row selection, I'd need to use the primary key as an argument for another method that populates a different table. Unfortunately, if you set a column to not be visible, then the data of that column returns an empty string when using keyRow.Cells[x] property during a GridView_SelectedIndexChanged event. (Apparently it didn't do this in 1.1) I've looked around this afternoon, but any answers I find on this are very cryptic. One is suggesting using an invisible template, but doesn't go into much detail. (http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=226153&SiteID=1) I'm fairly new to .NET and I'm finding this wayyyy more painful than it should be. Anyone familiar with a workaround? Fryedegg fucked around with this message at 03:04 on May 22, 2007 |
# ? May 22, 2007 03:00 |
|
I'm writing a very, very, very basic proof-of-concept FTP client library, just to learn C#/.NET. All the commands are hard-coded and it's kludgey to an amazing degree, but it seems to work. A couple of times. I'm using PORT mode and the problem is, after running the program a couple of times in succession, the FTP server won't be able to connect to my listening socket. My listening socket doesn't seem to report any problems, and will happily sit waiting there forever for an incoming connection from the server, while my server reports "425 Can't open data connection." However, if I wait for about 5 minutes before trying again, it all works great for at least one or two more runs. I've tried this against two different servers on two different machines (one local,) and gotten the same results, so I'm fairly sure it's a problem on my end. The time-based component makes me think I'm not properly closing some connection, and I'm having to wait for a timeout for it to work again, but I call Close() on the TcpClient and Stop() on the TcpListener, so I'm not sure what else I can do. You can see my code here: http://ace.pastey.net/37605 (line where it hangs is highlighted.) I know the code is utter crap, but like I said, this is just a learning proof-of-concept, so I'm not too concerned with it since it's all getting thrown out once it works (though if you see any fundamental theory flaws, please point them out.)
|
# ? May 22, 2007 08:15 |
|
Magicmat posted:The time-based component makes me think I'm not properly closing some connection, and I'm having to wait for a timeout for it to work again, but I call Close() on the TcpClient and Stop() on the TcpListener, so I'm not sure what else I can do. I have never written a FTP client, but it does definitely sound like something isn't being closed. It could be "foo", you don't seem to close that at all.
|
# ? May 22, 2007 09:57 |
|
Fryedegg posted:I have a GridView set up to display the results of a DAL query. I'm making the primary key column invisible. However, on row selection, I'd need to use the primary key as an argument for another method that populates a different table. Try either setting the width of the column to be 0, using a ListView instead (yes, you have to add the items and columns yourself, but they typically look nicer and work better), or you can set the Tag property of the row if it has one.
|
# ? May 22, 2007 09:58 |
|
Magicmat posted:I'm using PORT mode and the problem is, after running the program a couple of times in succession, the FTP server won't be able to connect to my listening socket. My listening socket doesn't seem to report any problems, and will happily sit waiting there forever for an incoming connection from the server, while my server reports "425 Can't open data connection." However, if I wait for about 5 minutes before trying again, it all works great for at least one or two more runs. Try running "netstat" between runs, in the time window your app doesn't run properly. See if any of your sockets are being held open by the OS in FIN_WAIT state. Also, try creating and starting your listener before sending the PORT command to the server. I suppose its possible the server is trying to connect immediately upon receiving the command, but you don't actually have a listener running at that point yet.
|
# ? May 22, 2007 12:47 |
|
Well, using netstat, I've found that my socket is being left in a TIME_WAIT state after the app exits. This raises two questions: Why is it doing this, and why doesn't the TcpClient complain when I use a port that is already being used? After some more reading, I figured out that (despite what the MSDN examples seem to imply,) I should call Close() on the TcpClient's underlying NetworkStream. However, this doesn't seem to have fixed the problem in any way, so I'm still stumped at what I'm doing wrong. Edit: When trying to do netstat -abv to see the call stack and process for the TIME_WAIT port, it just returns PID 0 (system) and no call stack, if that helps anybody. Also, as a side note, the both the port for the control connection and the data connection are stuck in TIME_WAIT, though the outgoing control connection works just fine if I try to run the app again with the port in that state, while the incoming data connection fails. Does anybody with experience using TcpClient know the correct procedure for shutting it down? Here's my updated code, if you want to see it. Magicmat fucked around with this message at 00:24 on May 23, 2007 |
# ? May 23, 2007 00:08 |
|
In that case, you can set the reuse flag on the socket, which tells the OS that it's alright to hijack a socket in the close-wait state and reappropriate it for new use.code:
If you want to make a robust FTP client though, instead of hardcoding your port to a certain value, you should just open a socket, letting the OS decide the local port number, then send that to the server. The reason you don't get the same problem with your TcpClient object is because what I just described in the last sentence is exactly what TcpClient does -- your local port number for the client connection is selected automatically by the OS, the port number you're supplying is the remote port, which is set up as a listener and can accept any number of incoming connections. (You can verify this by using netstat, you'll notice the remote port number is always the same, but the local port number appears to be random.) biznatchio fucked around with this message at 02:00 on May 23, 2007 |
# ? May 23, 2007 01:54 |
|
biznatchio posted:In that case, you can set the reuse flag on the socket, which tells the OS that it's alright to hijack a socket in the close-wait state and reappropriate it for new use. As for the port usage, one of the features that I hope to have is the ability for the user to specify which ports to use for inbound transfers as a way to get past NAT devices (so that they can forward a set of ports to their specific computer and make sure the ftp client always asks the server to connect to one of those ports.) In practice the range of ports will hopefully be larger than one, but even then I'd need a way to determine which ports are safe to use and which ones are otherwise occupied.
|
# ? May 23, 2007 02:18 |
|
Magicmat posted:Setting that option doesn't seem to have any effect. I still get a "425 Failed to establish connection" error from the server. As a side note, vsftpd seems to send that error right after the RETR command, while FileZilla Server will send a "150 Opening data channel for file transfer" and then send the 425. Both happen after I call Start() on the TcpListener but before I call AcceptTcpClient(). Ok, I'm confused then. Try this, just to see if it affects anything... replace lines 35-52 with the following: code:
If it doesn't work and it still fails in the same way, run it until it hangs, and while it's running and hung, do a netstat and see if you even have a socket open on port 7777 in the LISTENING state.
|
# ? May 23, 2007 03:10 |
|
Nope, no luck. Works the first time, fails the second. Here's the relevent output from netstat -a: code:
That is taken from just after the client hangs waiting for a connection, using your revised code. Here's the relevent output between when I first run the client successfully but before I run it a second time (where it will hang): code:
Magicmat fucked around with this message at 04:02 on May 23, 2007 |
# ? May 23, 2007 03:56 |
|
Did you also write the server? I ran your code against a dreamhost ftp server and couldn't get it to hang.
|
# ? May 23, 2007 04:07 |
|
poopiehead posted:Did you also write the server? I ran your code against a dreamhost ftp server and couldn't get it to hang. Hmm, maybe it's my router. I'm going to try removing that from the equation and seeing if it works. Edit: Nope, removed the router and got the same thing. That's odd, though, that it's working for you and not for me. Did you run the program at least two times in relatively quick succession? Edit 2: Just tried it against my webhosting's, 1&1, ftp server and still got the same errors. Curiouser and curioser. Magicmat fucked around with this message at 04:59 on May 23, 2007 |
# ? May 23, 2007 04:18 |
|
Those netstat readings are exactly what was expected if it was working correctly. This is a perplexing problem, there's no reason it shouldn't be working. Are you running any sort of personal firewall software that might be interfering with the connections? Do you have access to another machine to try running it on? Can you get a copy of ethereal and do some logging? edit: Woah woah woah wait a minute. Problem identified: You're listening on a 192.168.* address, and connecting to servers on the internet. That means NAT is getting involved. (You mentioned this earlier but it didn't really register with me until now.) I would bet money on the fact that your NAT is getting confused because you're using the same port for your data connection across multiple control connections in a short period of time. NAT boxes have to do some special voodoo port forwarding magic to correctly map active mode FTP (since at the very least you can't really be telling the server that it needs to connect to 192.168.x.x because it'd never be able to connect back to you -- the NAT at least needs to rewrite your PORT command with your actual public IP, and it undoubtedly does some other magic too). You said once it starts failing, it's like 5 minutes before it works again. Run it once, then again to get it to fail, then quickly reset whatever is performing your NAT and get it back online so you can try another connection within the 5 minute failure window. If it works, then you know it's a NAT issue, and actually changing the port number of your data connection would solve the problem (but completely derail your actual goal, of course). If this ends up being the problem, is there a reason you couldn't use passive FTP instead? biznatchio fucked around with this message at 05:19 on May 23, 2007 |
# ? May 23, 2007 05:06 |
|
I tried it with my computer directly connected to the cable modem and got the same results. I'll try again by rebooting the router between connections, though I'm not sure the router will be able to reboot completly before the nominal reconnect error time times out by itself. My router is running DD-WRT (and thus Linux with IPTables,) though I'm not sure if IPTables' FTP connection tracking works when the control port is something other than 21 on the server. Regardless, I'll try it again without the router, too. I could use PASV, I just chose PORT because it involved listening, which would teach me more about how sockets work in .NET. Plus, I want the client to eventually work with PORT, so might as well get it working now. Edit: Arghh, even with the router completly gone and with my own computer directly connected to the 'net, and even connecting to 127.0.0.1 I still get the same problem! This doesn't make sense. I don't have any software firewalls, or "Inernet Protection" software or anything else that might be messing with the TCP/IP stack. Edit2: Although now a netstat in between the good and bad runs of the app show that port 7777 is stuck in a TIME_WAIT state only when I connect to 127.0.0.1. Connecting to a remote IP only leave the control connection in the TIME_WAIT state. Edit3: Sniffing with Wireshark (Ethereal) shows that there is absolutely no activity to when the client sends the RECV command and when the server sends the 425 error. I don't know enough about socket programming to know whay implications this has, but there you go. Edit4: I've figured out that it's the server's WAIT_TIME that's the key. By setting the ReuseAddress flag on the client socket at well, I've eliminated all WAIT_TIMEs on the client. However, running netstat (or, to be more precise, TCPView) on the server shows that it is still in WAIT_TIME mode connected to port 7777 of my machine, as well as for the control connection. So why does the control connection work and not the data, and how can I get them both to work all the time? Interesting side note, while most of the time I can only run the client app once before it hangs the next time, every so often I can run it twice before it hangs. I don't know what the variable is during these times, though. Magicmat fucked around with this message at 09:45 on May 23, 2007 |
# ? May 23, 2007 05:56 |
|
Haha! Success! I just figured out that I had set vsftpd to always connect out from the same port in PORT mode. Changing it to let it connect from any port it wants now lets the client work! I guess FileZilla by default does this, too, which is why I was seeing the same behavior on both servers. (and, interestingly, whatever server 1&1 is using, since I got the same results from them, too.) Question, though: Is it just a fact of life that a server won't be able to connect out from a port in WAIT_TIME mode to the same port it was just connected to? Is that correct, or is that behavior a bug somewhere? If it's supposed to be able to, why can't I do it, and how could I do it? And, since it seems a decent amount of ftp servers out there only connect out in PORT mode from a single port, would the only way to avoid this while manually managing my local ports be to make sure I have enough ports in my "allowed ports" list so that I don't repeat a transfer from the same server to the same port before the average WAIT_TIME expires? Like, keep a stack of used ports somewhere for each server, and just go down that list each time I want to transfer something? That could get messy if each transfer is quick, I'd need a fair number of ports available. I know that other FTP clients don't seem to choke when I only let them have 10 ports and do a bunch of quick transfers, how do they do it? Edit: I also notice my comment in my last message about being no more TIME_WAIT ports was a bit hasty. It seems even setting ReuseAddress on the control port, nearly every (but not all?) running of the app leaves one port in TIME_WAIT to the control port of the server, though this doesn't seem to happen with the data port. However, with the aforementioned change to vsftpd, this doesn't seen to affect the workings of the system. Edit2: Also, the vsftpd server was on a machine doing NAT forwarding for a lan, and thus may have been subject to meddling by that. However, as I mentioned in a previous post, I did test against FileZilla with no router/NAT involved at all and got the error, so take that as you will. Magicmat fucked around with this message at 10:37 on May 23, 2007 |
# ? May 23, 2007 10:08 |
|
I'm doing an ASP.NET project where I have gridviews that show a list of records. These lists don't have to be edited. There are some columns where the value I have in the list is a foreign key. Naturally I want to display something else than a (for the user) meaningless key value. What are some elegant methods of showing the user a value from the other table for each foreign key ? I'm using an objectdatasource as the datasource for the grid. I was able to make a templatecolumn that has a dropdownlist, with another objectdatasource as the datasource, bound to the correct value. But using a dropdownlist in something that can't be edited is rather retarded. I want it to look like all the other columns, but with the value looked up from another table.
|
# ? May 24, 2007 11:02 |
|
Me again. What is the best way to retrieve a file-type or folder's icon? I know about System.Drawing.Icon.ExtractImage(), but there are a few problems with that: First, I need to get a file type's icon given just its extension, not a full path (since I'm trying to create an Explorer-like details ListView based off the text directory listing from a FTP server.) Second is that it doesn't work for folders. Now, I could probably find a generic "folder" icon, but that doesn't work when the folder who's icon I want has a special icon (like My Pictures.) Additionally, I'd like the icon to be "faded" if the file or folder is hidden. Basically, I want the icons to look exactly how they do in Explorer's details view. Also, the icons ExtractImage() gives me seem to look crappy when given to my ListView control. Observe my app on the left, and the FlashFXP FTP client on the right: Magicmat fucked around with this message at 10:54 on May 29, 2007 |
# ? May 29, 2007 10:11 |
|
Looks like the icons are being resized. Check there's enough room in that column to display them.
|
# ? May 29, 2007 11:35 |
|
Elky posted:Looks like the icons are being resized. Check there's enough room in that column to display them. It looks like FlashFXP is able to retrieve icons that where designed for 16x16, while my app, using ExtractImage(), is getting larger icons and simply resizing them. However, ExtractImage() doesn't seem to support extracting any paticular size of icons.
|
# ? May 29, 2007 11:45 |
|
uXs posted:I'm doing an ASP.NET project where I have gridviews that show a list of records. These lists don't have to be edited. There are some columns where the value I have in the list is a foreign key. Naturally I want to display something else than a (for the user) meaningless key value. What is underneath the ObjectDataSource? A typed dataset or a real object? If it is a typed dataset, you could select the appropriate bits of the child table and then create a data relation and use that to hook up the rows and display pretty stuff. If it is a real object, then things can be a bit trickier unless you want to "deep load" everything from the get go.
|
# ? May 29, 2007 14:14 |
|
Magicmat posted:Well, there's plenty of room in the ListView as a whole, and each columns is set to auto-size itself. I tried converting the icons it BitMap, resizing them and then passing them in on the image list, and that helped them look slightly less rear end, but it still didn't get to the heart of the problem. For example, look at the icon for AutoTuneScript.dll. In my app, it has a weird blocky drop shadow looking thing, while FlashFXP doesn't have that. And _default.pif in my app looks squished horizontally. this.imageListIcons.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit; I've got some code to pull icons but I doubt its going to do anymore than ExtractImage. You'll probably have to reshade the icons yourself when a file is hidden regardless of where you get the icon from. Here's the code: code:
Path to the file is "file": hImgSmall = Win32.SHGetFileInfo(file, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), Win32.SHGFI_ICON | Win32.SHGFI_SMALLICON)
|
# ? May 29, 2007 16:22 |
|
You can call SHGetFileInfo like this instead:code:
|
# ? May 29, 2007 17:23 |
|
Anyone know a good tool that can convert word documents to pdf? I'm asking here because I'd prefer a .NET library that I can call from my ASP .NET code, but anything wtih a command line interface will work...
|
# ? May 29, 2007 18:48 |
|
poopiehead posted:Anyone know a good tool that can convert word documents to pdf? I'm asking here because I'd prefer a .NET library that I can call from my ASP .NET code, but anything wtih a command line interface will work... Has anyone worked with any of these before?
|
# ? May 29, 2007 18:57 |
|
Fryedegg posted:I have a GridView set up to display the results of a DAL query. I'm making the primary key column invisible. However, on row selection, I'd need to use the primary key as an argument for another method that populates a different table. Have you tried using the SelectedDataKey collection? Perhaps it uses the underlying datasource rather than the presentation collection. You would need to set the column name for the datakey in the <gridview> decleration
|
# ? May 29, 2007 19:02 |
|
Fiend posted:Have you investigated the google yet? The google pretty much ends up giving all horrible freeware/shareware lists or services that do online conversion for you, so I was hoping someone here actually had a positive experience with something. I'm sure something in the google results I've gotten is good but it's impossible to find.
|
# ? May 29, 2007 19:07 |
|
wwb posted:What is underneath the ObjectDataSource? A typed dataset or a real object? It's an object. I ended up putting the parts of the foreign table I want to view in the object itself. It seemed the easiest way and it's not that much overhead. Perhaps I should make some functions that do get the extra info and some others that don't, to make it more maintainable, I dunno.
|
# ? May 29, 2007 19:19 |
|
poopiehead posted:The google pretty much ends up giving all horrible freeware/shareware lists or services that do online conversion for you, so I was hoping someone here actually had a positive experience with something. I'm sure something in the google results I've gotten is good but it's impossible to find. It sure would be useful to have Adobe Acrobat Document (.PDF) show up in the list of file types in the Save As dialog in word.
|
# ? May 29, 2007 22:41 |
|
|
# ? Jun 10, 2024 11:21 |
|
havelock posted:untested code: Hey, I apologize for the lateness in this response, but it turns out that I had to completely scratch my website and start a whole new program, which means I didn't even need this . But, I wanted to thank you for posting this .
|
# ? May 29, 2007 22:43 |