Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
uXs
May 3, 2005

Mark it zero!

Richard Noggin posted:

I don't believe there's an option to do that in the GD control panel.

It would help if you told us what your co-worker is trying to do. If he's trying to read what files are on the webserver, that sounds horribly insecure and I'm not in the least surprised that it's not allowed.

Adbot
ADBOT LOVES YOU

Richard Noggin
Jun 6, 2005
Redneck By Default

uXs posted:

It would help if you told us what your co-worker is trying to do. If he's trying to read what files are on the webserver, that sounds horribly insecure and I'm not in the least surprised that it's not allowed.

This will be used to display random images from a directory on a web site. The directory is a subdirectory of the site (e.g. /images).

NotAok
Dec 29, 2003
This is killing me, all I'm trying to do is create an appdomain so I can unload assembly files. I've looked just about everywhere for setting this up and I've looked over the Fusion log.

This dll is simply an example, the dll I'm using is a .NET assembly and I have loaded it using only the assembly class before (but using the LoadFile method).

code:
Dim assemblyFileName As String = "C:\WINDOWS\twain_32.dll"
Dim assemblyName As String = "twain_32"
Dim evidence As New Security.Policy.Evidence(AppDomain.CurrentDomain.Evidence)
Dim TestDomain As AppDomain = AppDomain.CreateDomain("TestDomain", evidence, AppDomain.CurrentDomain.BaseDirectory, 
System.IO.Path.GetDirectoryName(assemblyFileName), True)
MsgBox(TestDomain.Load(assemblyName).FullName)
I get "An unhandled exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll" and "File or assembly name C:\WINDOWS\twain_32.dll, or one of its dependencies, was not found. If I change the AppDomain.CurrentDomain.BaseDirectory to System.IO.Path.GetDirectoryName(assemblyFileName) as well, I get an error about serialization.

Of course if I have the dll file within the bin directory of my project it does load the assembly, so my assumption is that I'm misunderstanding how setting these directory paths work. This is frustrating :(

Fusion log, again, replaced paths/dll names:

*** Assembly Binder Log Entry (4/9/2008 @ 4:31:51 PM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from: c:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\fusion.dll
Running under executable C:\blah\testapp\testapp\bin\testapp.exe
--- A detailed error log follows.

=== Pre-bind state information ===
LOG: DisplayName = twain_32
(Partial)
LOG: Appbase = C:\blah\testapp\testapp\bin\
LOG: Initial PrivatePath = C:\Windows
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = NULL
Calling assembly : (Unknown).
===

LOG: Processing DEVPATH.
LOG: DEVPATH is not set. Falling through to regular bind.
LOG: Attempting application configuration file download.
LOG: Download of application configuration file was attempted from file:///C:/blah/testapp/testapp/bin/testapp.exe.config.
LOG: Application configuration file does not exist.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Post-policy reference: twain_32
WRN: Not probing location file:///C:/Windows/twain_32.DLL, because the location falls outside of the appbase.
WRN: Not probing location file:///C:/Windows/twain_32/twain_32.DLL, because the location falls outside of the appbase.
WRN: Not probing location file:///C:/Windows/twain_32.EXE, because the location falls outside of the appbase.
WRN: Not probing location file:///C:/Windows/twain_32/twain_32.EXE, because the location falls outside of the appbase.
LOG: Attempting download of new URL file:///C:/blah/testapp/testapp/bin/twain_32.DLL.
LOG: Attempting download of new URL file:///C:/blah/testapp/testapp/bin/twain_32/twain_32.DLL.
LOG: Attempting download of new URL file:///C:/blah/testapp/testapp/bin/twain_32.EXE.
LOG: Attempting download of new URL file:///C:/blah/testapp/testapp/bin/twain_32/twain_32.EXE.
LOG: All probing URLs attempted and failed.

If I hardcode the two directories passed in as "C:" and "C:\Windows" I get the error about the serialization - " Insufficient state to deserialize the object. More information is needed." Here's the log:

*** Assembly Binder Log Entry (4/9/2008 @ 4:55:37 PM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from: c:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\fusion.dll
Running under executable C:\blah\testapp\testapp\bin\testapp.exe
--- A detailed error log follows.

=== Pre-bind state information ===
LOG: DisplayName = twain_32, Version=3.7.0.7, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = C:\blah\testapp\testapp\bin\
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = NULL
Calling assembly : (Unknown).
===

LOG: Processing DEVPATH.
LOG: DEVPATH is not set. Falling through to regular bind.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Post-policy reference: twain_32, Version=3.7.0.7, Culture=neutral, PublicKeyToken=null
LOG: Attempting download of new URL file:///C:/blah/testapp/testapp/bin/MEMY001.DLL.
LOG: Attempting download of new URL file:///C:/blah/testapp/testapp/bin/MEMY001/MEMY001.DLL.
LOG: Attempting download of new URL file:///C:/blah/testapp/testapp/bin/MEMY001.EXE.
LOG: Attempting download of new URL file:///C:/blah/testapp/testapp/bin/MEMY001/MEMY001.EXE.
LOG: All probing URLs attempted and failed.

NotAok fucked around with this message at 21:57 on Apr 9, 2008

csammis
Aug 26, 2003

Mental Institution
AppDomain.Load has a bunch of semantics that are probably defeating what you're trying to do. For example, the code that you posted would actually load the assembly into the target AppDomain and the calling AppDomain, which would nix the benefit of unloading the assembly later. See the below-linked article for details.

Aside from that rather serious problem that you'll have to address (hint hint :) ), try the AppDomain.Load(AssemblyName) overload, setting the AssemblyName.CodeBase property might be what you need.

MORE CURLY FRIES
Apr 8, 2004

I was wondering if anyone could shed light on this.

I've got a small application which monitors one folder and mirrors it in another using filesystemwatcher. I wanted it to update a text box with actions so that I could monitor what was going on, then maybe save this to a file on exit or something, I dunno yet but I thought it'd be nice to have.

Anyway, I had it functioning as a flat file thing, files could be created but they were just copied with no directory structure to the destination folder. When it did this I had the text box spitting out information no problem. I then reworked the code so that it would start mirroring the folder structure too, and all of a sudden I get cross thread errors. I'm assuming I've missed something completely basic here, but who knows. Here's the relevant code:

Delegate methods:
code:
private string UpdateText(string text)
        {
            return text;
        }

        public delegate string UpdateTextCallback(string text);
And here's a method I'm using to update files with structure:
code:
        public void FileAction(string trigger, string file, string action)
        {
            string newSource = trigger.Remove(0, source.Length+1);
            string currentSource = source;
            string currentDestination = destination;
            string[] items = newSource.Split(new char[]{'\\'});
            for (int i = 0; i <= (items.Length - 1); i++)
            {
                if (FolderCheck(items[i], currentSource))
                {
                    if(!Directory.Exists(currentDestination + @"\" + items[i]))
                    {
                        //If directory doesn't exist, create it
                        Directory.CreateDirectory(currentDestination + @"\" + items[i]);
                        txtLog.Text = (string)txtLog.Invoke(new UpdateTextCallback(this.UpdateText), txtLog.Text + "Directory creation detected: " +
                                Environment.NewLine + currentSource + "\t" + Environment.NewLine + "Directory created:" + Environment.NewLine + "\t" +
                                currentDestination + @"\" + items[i].ToString() + Environment.NewLine);

                    }
                    //Update source and destination and repeat iteration
                    currentDestination = currentDestination + @"\" + items[i].ToString();
                    currentSource = currentSource + @"\" + items[i].ToString();
                }
                else
                {
                    switch (action)
                    {
                        case "Created":
                            File.Copy(currentSource + @"\" + items[i].ToString(), currentDestination + @"\" + items[i], true);
                            //Update the text log
                            txtLog.Text = (string)txtLog.Invoke(new UpdateTextCallback(this.UpdateText), txtLog.Text + "File creation detected: " +
                                Environment.NewLine + "\t" + currentSource + Environment.NewLine + "File copied to:" + Environment.NewLine +
                                "\t" + currentDestination + @"\" + items[i].ToString() + Environment.NewLine);
                            break;
                        case "Changed":
                            File.Copy(currentSource + @"\" + items[i].ToString(), currentDestination + @"\" + items[i], true);
                            txtLog.Text = (string)txtLog.Invoke(new UpdateTextCallback(this.UpdateText), txtLog.Text + "File change detected: " +
                                Environment.NewLine + currentSource + "\t" + Environment.NewLine + "File updated:" + Environment.NewLine + "\t" +
                                currentDestination + @"\" + items[i].ToString() + Environment.NewLine);
                            break;
                    }

                }
            }
        }
The FolderCheck method simply checks to see whether the current file is actually a file or is a folder.
These methods are called from the relevant file system methods, such as this one:

code:
public void monitor_FileCreated(object sender, FileSystemEventArgs e)
        {
            FileAction(e.FullPath, e.Name, "Created");
        }
As I said before, the invoking worked when they were in the file monitor methods, I simply shunted them into the FileAction method so that once it was working I could group common stuff together easier, but the whole thing fell apart.

The file copying itself works as intended, it's just these silly cross calls causing me the problem.

chglcu
May 17, 2007

I'm so bored with the USA.

MORE CURLY FRIES posted:

code:
...

txtLog.Text = (string)txtLog.Invoke(new UpdateTextCallback(this.UpdateText), txtLog.Text + "Directory creation detected: " +
Environment.NewLine + currentSource + "\t" + Environment.NewLine + "Directory created:" + Environment.NewLine + "\t" +
currentDestination + @"\" + items[i].ToString() + Environment.NewLine);

...

This is only invoking that property getter, unless I'm misreading it. The actual setting of txtLog.Text is what needs to be Invoke()d, since that's what's actually modifying the UI.

edit:

So what you want is something along the lines of:
code:
private void UpdateText (string text) {
    txtLog.Text = text;
}
...
public void FileAction(string trigger, string file, string action) {
...
    txtLog.Invoke(new UpdateTextCallback(UpdateText(txtLog.Text + "Directory creation detected: " +
        Environment.NewLine + currentSource + "\t" + Environment.NewLine + "Directory created:" + Environment.NewLine + "\t" +
        currentDestination + @"\" + items[i].ToString() + Environment.NewLine)));
...
}
edit #2:

Actually, all your code is doing is invoking a return of the string you pass in onto the UI thread, but the problem still stands. The setting of txtLog.Text is what needs to be Invoke()d.

chglcu fucked around with this message at 03:57 on Apr 10, 2008

uXs
May 3, 2005

Mark it zero!

Richard Noggin posted:

This will be used to display random images from a directory on a web site. The directory is a subdirectory of the site (e.g. /images).

Is there any way you can keep a list of files, so you don't have to read the directory content ? It might be easier to do that than to gently caress around with permission problems. Those are hard enough when you have full control over the server, it will be even harder when you don't.

Richard Noggin
Jun 6, 2005
Redneck By Default

uXs posted:

Is there any way you can keep a list of files, so you don't have to read the directory content ? It might be easier to do that than to gently caress around with permission problems. Those are hard enough when you have full control over the server, it will be even harder when you don't.

If I can't even parse a directory, how do I read a list of files without putting it in the code-behind? Is this normal - not being able to have file-level access in your own virtual directory structure?

biznatchio
Mar 31, 2001


Buglord

Richard Noggin posted:

If I can't even parse a directory, how do I read a list of files without putting it in the code-behind? Is this normal - not being able to have file-level access in your own virtual directory structure?

By default, medium trust in ASP.NET 2.0 should allow you access to the files within your application's virtual directory hierarchy. If you're getting FileIOPermission exceptions, it means one of two things: they either tightened the security (which if I'm not mistaken would break ASP.NET entirely), or you're trying to access the filesystem wrong; either the wrong directory, or you're not qualifying your path names right.

Use something like Path.Combine(Request.PhysicalApplicationPath, "Images") to get the full path to your images directory, that you can then read through.

NotAok
Dec 29, 2003

csammis posted:

AppDomain.Load has a bunch of semantics that are probably defeating what you're trying to do. For example, the code that you posted would actually load the assembly into the target AppDomain and the calling AppDomain, which would nix the benefit of unloading the assembly later. See the below-linked article for details.

Aside from that rather serious problem that you'll have to address (hint hint :) ), try the AppDomain.Load(AssemblyName) overload, setting the AssemblyName.CodeBase property might be what you need.

Ok thanks for the tip on the reference. I looked into the assemblyname class and I think it would work much better but I'm running into the same problem as before though, " Insufficient state to deserialize the object. More information is needed."

code:
Dim assemblyName As New AssemblyName
assemblyName.CodeBase = "C:\Windows\twain_32.dll"

Dim TestDomain As AppDomain
TestDomain = TestDomain.CreateDomain("TestDomain")

Dim blah As [Assembly]
blah = TestDomain.Load(assemblyName)
From what I've read, it seems that only the codebase needs to be filled out unless I wanted to get more specific. What am I doing wrong here? I don't really understand this as the Fusion LOG is showing the information of the DLL file and obviously found it:

LOG: Post-policy reference: twain_32, Version=3.7.0.7, Culture=neutral, PublicKeyToken=null

edit: Also, if I simply use blah.Load instead of TestDomain.Load, it actually does load the assembly. It must have to do with the appdomain.

NotAok fucked around with this message at 18:26 on Apr 10, 2008

riggsninja
Jan 15, 2006
Is it impossible to a store a reference in C#?

Something to the general effect of:

code:
class MyObject{
   public Point pos;

   MyObject(ref Point p){
       pos = p;
   }

}

OtherFunction(){
    Point q = new Point(0, 0);
    MyObject s = new MyObject(ref q);
        
    Console.WriteLine(s.pos.X);
    q.X = 999;
    Console.WriteLine(s.pos.X);
}
Obviously, this will output 0. Is there a way to set this up so it will output 999?

I've worked in C and C++ before. So I'm comfortable with "unsafe" code. But my c# complains when I declare a pointer to or attempt to get the address of a "managed type".

riggsninja fucked around with this message at 21:28 on Apr 10, 2008

csammis
Aug 26, 2003

Mental Institution

riggsninja posted:

I've worked in C and C++ before. So I'm comfortable with "unsafe" code. But my c# complains when I declare a pointer to or attempt to get the address of a "managed type".

C# struct semantics are different from both C and C++. This:
code:
class MyObject{
   public Point pos;

   MyObject(ref Point p){
       pos = p;
   }

}
Is not the same as:

code:
struct MyObject
{
  Point* pos;

  public void setPoint(Point *p)
  {
    pos = p;
  }
}
Since Point is a struct, it's being passed by value. You're storing a copy of that struct in the constructor, not the pointer you think you're getting. If you want the semantics you're going for, use a class instead, since classes are always passed by reference. Using ref with a class is like using &*ptr (Disclaimer: It's been a while since I've fiddled with pointers like this in C/C++, my analogy might be rusty :) )


edit: I think I see the root of your problem: ref isn't a way to get a pointer.

riggsninja
Jan 15, 2006
I had no idea Point was a struct, Im not used to structs having constructors. I fully realize that code was no good. I was just trying to convey the logic of what I was getting at. Basically what I'm asking is:

How do I translate this to C#:
code:
Object* pObj = &objectInstance;
I tried converting the class I'm working with to a struct, since C# allows you to get the address of a struct, but I also need a list. And when I try to access elements of a list that holds my struct for some reason I get the error "cannot modify the return value of list[i] because it is not a variable". I thought maybe storing a pointer would be a work around for this, but C# wont let me use a pointer as the generic argument to a list.

jonnii
Dec 29, 2002
god dances in the face of the jews

riggsninja posted:

How do I translate this to C#:

You would just do

code:
object o = new object();
Then o would be a reference to the object you created. I think you need stop thinking like a C++ programmer, it will only slow you down because you'll be focusing more on the how, not on the what.

riggsninja
Jan 15, 2006
object o = new object();

is not equivalent to what I want. Your statement would be equivalent to something like Object* o = (Object*)malloc(sizeof(Object)); (For C, in C++ it would pretty much look the same as the C# version).

I want this translated:
code:
Object obj(/*construction parameters*/);
Object* pObj = &obj;
I already have a constructed object. I want to store a reference to it.
So that I could something like this:

code:
obj.integerVariable = 372;
printToScreen(pObj->integerVariable); //This should now give me 372
Is this just impossible to do then? I'm sure can achieve this effect in Java. But C# seems unsure of whether it wants to do things value or by reference, and it's irritating.

Inquisitus
Aug 4, 2006

I have a large barge with a radio antenna on it.
Is your type a class or a struct?

Edit: I guess it's a struct, going by your example.

If you want to keep the type as a value type, then yes, it's possible, but it would require either unsafe code or boxing (which is clunky and generally undesirable).

Technically you shouldn't be mixing value types with reference type semantics like that, at least in C#. If you want reference type semantics, then just make the type a reference type in the first place. This may sound like a lame solution if you're coming straight from C/C++ but honestly in the two years I've been using C# it hasn't once even seemed unnatural. In fact, before I learned C++ I couldn't even understand why you'd want to use pointers :p

Btw, how did you do it in Java if it's not working in C#?

Inquisitus fucked around with this message at 00:14 on Apr 11, 2008

SLOSifl
Aug 10, 2002


The reason your idea above doesn't work is because, as csammis pointed out, Point is a struct. If it was a class, that would have worked. You would need to remove the "ref" as well.

cowboy beepboop
Feb 24, 2001

Try this:

code:
namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();

            AnObject obj1 = new AnObject(10);
            AnObject obj2 = obj1;

            obj2.intergerVariable = 100;

            MessageBox.Show(obj1.intergerVariable.ToString() + "\n" +  obj2.intergerVariable.ToString());
        }
    }

    class AnObject
    {
        public int intergerVariable;

        public AnObject(int hello)
        {
            intergerVariable = hello;
        }
    }
}
Notice how both values are 100? That's how you get your reference

Inquisitus
Aug 4, 2006

I have a large barge with a radio antenna on it.

my stepdads beer posted:

Try this:

code:
namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();

            AnObject obj1 = new AnObject(10);
            AnObject obj2 = obj1;

            obj2.intergerVariable = 100;

            MessageBox.Show(obj1.intergerVariable.ToString() + "\n" +  obj2.intergerVariable.ToString());
        }
    }

    class AnObject
    {
        public int intergerVariable;

        public AnObject(int hello)
        {
            intergerVariable = hello;
        }
    }
}
Notice how both values are 100? That's how you get your reference

I think he wants AnObject to be a value type and yet be able to obtain a reference to an instance of it.

cowboy beepboop
Feb 24, 2001

Inquisitus posted:

I think he wants AnObject to be a value type and yet be able to obtain a reference to an instance of it.

Could he wrap it in an object? Or is that bad?

riggsninja
Jan 15, 2006

Inquisitus posted:

Btw, how did you do it in Java if it's not working in C#?

code:

        MyObject a = new MyObject();
        MyObject b = new MyObject();
        
        a.x = 0;
        b.x = 1;
        
        println(a.x); // "0" - replace with System.out/Console.write as per your language
        println(b.x); //"1"
        
        b = a;
        
        b.x = 3;
        
        println(a.x); // "3" in java. "0" in C#.
3 is what I want. a's value changed. because b because I changed b and b is a reference to a. This what I want. I just double-checked this in both languages too.


As far as classes and structs, I dont care which, since they seem to be basically the same thing in C#. Except that structs break lists for some reason.

Inquisitus
Aug 4, 2006

I have a large barge with a radio antenna on it.

my stepdads beer posted:

Could he wrap it in an object? Or is that bad?

He could but it's a lame way of doing what would be much better achieved by rewriting it so that the semantics riggsninja wants aren't even necessary (which is possible and simpler to do 9 times out of 10).

riggsninja posted:

code:

        MyObject a = new MyObject();
        MyObject b = new MyObject();
        
        a.x = 0;
        b.x = 1;
        
        println(a.x); // "0" - replace with System.out/Console.write as per your language
        println(b.x); //"1"
        
        b = a;
        
        b.x = 3;
        
        println(a.x); // "3" in java. "0" in C#.
3 is what I want. a's value changed. because b because I changed b and b is a reference to a. This what I want. I just double-checked this in both languages too.

I assume you're declaring MyObject as a struct? Change it to a class and all should work as expected.

riggsninja posted:

As far as classes and structs, I dont care which, since they seem to be basically the same thing in C#. Except that structs break lists for some reason.

This is true in C++; the only difference is member accessibility. In C#, however, there's a rather crucial difference (and some other less significant ones too): structs are allocated on the stack, whereas classes are allocated on the managed heap, and have implicit reference-type semantics.

For example, this in C#:

code:
struct Foo
{
    int Bar;
}

static class Program
{
    static void Main()
    {
        // Don't be misled by the use of the new operator; we're not allocating anything on the heap; it's going on the stack.
        Foo foo1 = new Foo1();
        foo1.Bar = 0;

        Foo foo2 = foo1;
        foo1.Bar = 1;

        Console.WriteLine(foo2.Bar); // Outputs 0.
    }
}
…is equivalent to this, in C++:

code:
struct Foo
{
    int Bar;
};

int main()
{
    Foo foo1;
    foo1.Bar = 0;

    Foo foo2 = foo1;
    foo1.Bar = 1;

    cout << foo2.Bar << endl; // Outputs 0.
}
Whereas if we change Foo to a class in the C# example while keeping the Main method the same, the equivalent C++ would become:

code:
struct Foo
{
    int Bar;
};

int main()
{
    Foo *foo1 = new Foo;
    foo1->Bar = 0;
    
    Foo *foo2 = foo1;
    foo1->Bar = 1;
    
    cout << foo2->Bar << endl; // Outputs 1.
}
Check out these pages for more info:
http://www.jaggersoft.com/pubs/StructsVsClasses.htm
http://www.c-sharpcorner.com/UploadFile/rajeshvs/StructuresInCS11112005234341PM/StructuresInCS.aspx
http://msdn2.microsoft.com/en-us/library/ms173109(VS.80).aspx

Inquisitus fucked around with this message at 01:07 on Apr 11, 2008

riggsninja
Jan 15, 2006
Okay, case closed, I suppose. Sorry about that.

I had been using structs instead of classes, because of earlier efforts to get a pointer and forgot to switch back.. It seems using classes allows me to do the Java method of doing things.

But, really, I swear to god I tried that way and didnt get the values I expected. So thanks to everybody. It's last week before finals and everything's due, so I'm a little bit sleep deprived.



The problem is, it's not always clear if C# is using references or pointers. the operator = apperently handles references in for classes but not structs for example. It makes, sense, but the reference bit is a little unclear.

Anyways, once again, thanks, and sorry for the stupid error.

Inquisitus
Aug 4, 2006

I have a large barge with a radio antenna on it.

riggsninja posted:

Anyways, once again, thanks, and sorry for the stupid error.

No problems :)

And yeah I agree that it's a little unclear how C# handles references with respect to classes and structs. C/C++ is certainly more explicit about it.

joe87653
Jul 9, 2002
I can't seem to find an answer for this anywhere..

I'm developing a touchscreen application using C#. I need controls that are much bigger than what is offered in .NET.

For example, a vertical scrollbar. I am able to adjust the width of this bar no problem. However, the up and down buttons remain a fixed 16 pixels tall (at least on windows xp, it's probably different per OS or skin). I can't seem to find
1) where this button height is stored
2) how to change this button height

For example, I have included a picture...


The left picture shows what happens when you resize a VScrollBar. The width is great, I am ok with this. However, I want the scrollbar's up and down arrow buttons to be the same height as they are wide. The right picture shows this (which I did via MS Paint).

Is this possible to do via .NET? I really want to avoid writing my own control just for this. It's almost impossible to touch the scrollbar when the up and down arrows are only 16 pixels tall. Also, I am not sure if there is a way to change the minimum thumb bar size (which needs to be bigger obviously, because of the same issue). I previously wrote all my touchscreen software in C++ using my OpenGL control library but I want to avoid using this because the development time is too costly for reinventing the wheel (which is what I did).

joe87653 fucked around with this message at 17:03 on Oct 1, 2011

cowboy beepboop
Feb 24, 2001

Are you using Windows Forms or WPF? If WPF, try this tutorial on custom controls.

You might be able to modify the RepeatButtons without needing an entire custom control, but I'm not sure.

Eararaldor
Jul 30, 2007
Fanboys, ruining gaming since the 1980's

SLOSifl posted:

With the Windows Forms calendar control, you would set the MinDate property to DateTime.Today. I can't tell if you're talking about Win Forms, WPF or ASP.NET though, so please clarify.

Just general ASP.NET

csammis
Aug 26, 2003

Mental Institution

my stepdads beer posted:

Are you using Windows Forms or WPF? If WPF, try this tutorial on custom controls.

Judging from the picture he's probably using Winforms (it's straight out of the designer), but I was going to suggest WPF. It's made for this sort of thing.

MORE CURLY FRIES
Apr 8, 2004

Eararaldor posted:

Just general ASP.NET

Take the date the select, get the current date and then if the date they've selected is less than the current date it's in the past and you can reject it.

Edit:

Also I was wondering if there was a simple way in C# winforms to detect when a storage device had been mounted. This is for the sync thing I'm messing with, and I'd like to be able to recognise when something's mounted or removed and then I can take an appropriate action.

Mainly when something's mounted I can pop up another form and populate it with a list of drives and devices, and then allow the user to browse it to select a location, and when it's removed I want to check whether the program's listening to it and if it is, stop the syncing.

I've been looking around and a lot of tutorials seem to suggest having to mess around with hooking into the registry or something, but I can't beieve there isn't a basic argument or function I can use, seeing as this is a MS/Windows framework to start with.

MORE CURLY FRIES fucked around with this message at 14:23 on Apr 11, 2008

Potassium Problems
Sep 28, 2001
MORE CURLY FRIES, you have to override the WndProc method in a WinForm. When a device is added or removed, a message is sent to all windows notifying them of the change. I did this before, but I can't seem to find the code & I can't remember off the top of my head. :(

edit: found this, I think it's what you're looking for

Potassium Problems fucked around with this message at 16:42 on Apr 11, 2008

MORE CURLY FRIES
Apr 8, 2004

Lone_Strider posted:

MORE CURLY FRIES, you have to override the WndProc method in a WinForm. When a device is added or removed, a message is sent to all windows notifying them of the change. I did this before, but I can't seem to find the code & I can't remember off the top of my head. :(

edit: found this, I think it's what you're looking for

That's interesting, I was also reading up on the Drive Info class, I could put a thread in my main form and refresh devices every so often too I guess?

csammis
Aug 26, 2003

Mental Institution

MORE CURLY FRIES posted:

That's interesting, I was also reading up on the Drive Info class, I could put a thread in my main form and refresh devices every so often too I guess?

You could, but polling for information when there's an event-driven notification available should only be done if you absolutely positively with good reason can't use the notification :)

MORE CURLY FRIES
Apr 8, 2004

csammis posted:

You could, but polling for information when there's an event-driven notification available should only be done if you absolutely positively with good reason can't use the notification :)

True, I'll look into overriding the method, and I can use the drive info thing on a button prompt or something.

Richard Noggin
Jun 6, 2005
Redneck By Default

biznatchio posted:

By default, medium trust in ASP.NET 2.0 should allow you access to the files within your application's virtual directory hierarchy. If you're getting FileIOPermission exceptions, it means one of two things: they either tightened the security (which if I'm not mistaken would break ASP.NET entirely), or you're trying to access the filesystem wrong; either the wrong directory, or you're not qualifying your path names right.

Use something like Path.Combine(Request.PhysicalApplicationPath, "Images") to get the full path to your images directory, that you can then read through.

This was it exactly. Thanks!

boo_radley
Dec 30, 2005

Politeness costs nothing
Is there a way to specify multiple exception types in a catch block?
I'd like to merge two blocks that are similar to
code:
catch (SpecificException e) {
myLog.WriteEntry (...)
}
catch (AnotherSpecificException e) {
myLog.WriteEntry (...)
}
but leave a general catch block for really unforeseen things.

fankey
Aug 31, 2001

Does anyone have experience using a tool like Dotfuscator? How well do tools like this stop people from stealing your source code? Are the claims of reduced size and increased speed true? It seems like there's a possibility of it screwing up the code in some way.

Most of the 'secrets' in the code are hidden away in C++ DLLs but my manager asked me to look into obfuscation technology. I personally don't think it's important to our app but I thought I'd see if anyone here has any experience with the tools. My guess is that if someone in China wants to rip off your source they'll figure out some way to do it no matter what the barrier.

csammis
Aug 26, 2003

Mental Institution

fankey posted:

Does anyone have experience using a tool like Dotfuscator? How well do tools like this stop people from stealing your source code? Are the claims of reduced size and increased speed true? It seems like there's a possibility of it screwing up the code in some way.

Most of the 'secrets' in the code are hidden away in C++ DLLs but my manager asked me to look into obfuscation technology. I personally don't think it's important to our app but I thought I'd see if anyone here has any experience with the tools. My guess is that if someone in China wants to rip off your source they'll figure out some way to do it no matter what the barrier.

About a year and a half ago a gentleman on this very forum challenged me to break the key system on his Dotfuscated software. It took about thirty minutes and I'd made a keygen. Granted this was the Community edition, but with tools like Reflector it's almost painfully easy to do given enough time and motivation.

If the "secrets" have to be on the client's machine, putting them in non-managed DLLs is about as good as you can ask for, because you're right, some teenager in eastern Europe will make you his bitch in less than a week if he really wants your software. If your manager wants proof, use the Dotfuscator tool to obfuscate a copy of your application, then load the un-crapped-up copy and the Dotfuscated copy side-by-side in Reflector, set it to show the disassembly. About all it'll do is name-mangling, but it should get the point across: programs follow a logical flow, and obfuscation doesn't change that, it only makes the path less followable by a human.

Reduced size and speed? Maybe, but I couldn't prove it one way or another...it'll reduce the byte size of the named symbol table at least by giving them one-letter names :v:

Potassium Problems
Sep 28, 2001
I've recently had to write my own implementation of ASCII85, and I want to get feedback because for large files, it runs pretty slowly. For example, it takes about 1 second to encode a 7 MB file, and 2.5 seconds to decode it back to its native format. Anyone have any suggestions?

http://pastebin.com/m5c907653

gibbed
Apr 10, 2006

fankey posted:

Does anyone have experience using a tool like Dotfuscator? How well do tools like this stop people from stealing your source code? Are the claims of reduced size and increased speed true? It seems like there's a possibility of it screwing up the code in some way.

Most of the 'secrets' in the code are hidden away in C++ DLLs but my manager asked me to look into obfuscation technology. I personally don't think it's important to our app but I thought I'd see if anyone here has any experience with the tools. My guess is that if someone in China wants to rip off your source they'll figure out some way to do it no matter what the barrier.
Dotfuscator is pretty decent (assuming non-community edition) at protecting your program logic than protecting it from modification. Nobody wants to sit there and toil over the retarded amount of jumps and crap that Dotfuscator does to mangle the code. As csammis said though, it's fairly trivial to break any actual protection even if it's Dotfuscated. csammis is wrong about that it only does name mangling though. Here's an example of dotfuscated code that isn't community edition:

code:
    private void b(a1 A_0)
    {
        bool flag;
        int num;
        goto Label_0023;
    Label_0002:
        switch (num)
        {
            case 0:
                this.h.b(new a1.a(this.d));
                num = 1;
                goto Label_0002;

            case 1:
                return;

            case 2:
                if (!flag)
                {
                    return;
                }
                num = 0;
                goto Label_0002;

            case 3:
                goto Label_00AA;

            case 4:
                if (!flag)
                {
                    goto Label_0071;
                }
                num = 3;
                goto Label_0002;

            case 5:
                goto Label_0071;
        }
    Label_0023:
        flag = this.h != null;
        num = 4;
        goto Label_0002;
    Label_0071:
        this.h = A_0;
        flag = this.h != null;
        num = 2;
        goto Label_0002;
        debug;
    Label_00AA:
        this.h.a(new a1.a(this.d));
        num = 5;
        goto Label_0002;
    }
Now imagine a complicated function obfuscated like this that is a few thousand lines long.

However, a dedicated reverser can still take the time to work it out - all Dotfuscator does is make the process much more lengthy, tedious, and loving annoying (speaking from experience myself!).

gibbed fucked around with this message at 03:55 on Apr 12, 2008

Adbot
ADBOT LOVES YOU

csammis
Aug 26, 2003

Mental Institution

gibbed posted:

csammis is wrong about that it only does name mangling though

Which is why I qualified my example by saying it was the Community edition :confused:

  • Locked thread