|
Yup, sounds logical too. It must be either time for coffee, or for some sleep
Bastard Programmer from Hell
|
|
|
|
|
Thanks for the input, guys. See my clarification at the end here.
|
|
|
|
|
To clarify:
main program is in directory A
main program uses sub-program in directory B
I need to get the directory of B programatically.
Wouldn't anything referring to executing assembly refer to the location of main program in directory A? Since I am referring to program B in program A, the dll or exe is copied to program A's directory, so getting that location would return program A's location, not program B. I have a file I need to use/get in dir B.
A->B and B is trying to open a file in it's directory but I'm getting the location of A because A is the application startup path (and executing assembly,no?).
Sorry for the confusion! I hope that this makes it more clear!
modified 25-May-12 13:28pm.
|
|
|
|
|
Is directory of the B is relative to the A's directory then you can calculate the path for B's directory
get the App path and then add directories or remove directories depending on the B's location...
Assuming that B's directory does not change with respect to A's
Happy Coding
|
|
|
|
|
That's a good idea. A's directory is blah/blah1/blah2/tool/tool/bin/Debug and then B's directory could be found by appending it's location onto blah/blah1/blah2.
|
|
|
|
|
As I pointed out earlier this command returns the path of the executable program. It does not matter where the various components used to build that executable are stored.
|
|
|
|
|
But B's exe file is referenced by program A, so A copies the exe file to A's Debug directory. So getting the exe location would return A's dir and not B's.
|
|
|
|
|
Exactly, and that is why it does not work. When you start an executable program Windows makes a note of its location and it is that location that will be returned. Program A can only ever find program A's directory. Maybe if you explain what problem you are actually trying to solve people will be able to give some better suggestions.
|
|
|
|
|
Right. It does not work. Thanks for helping!
|
|
|
|
|
Hi guys. I'm going to call this since I decided what I'm going to do. For anyone looking at this post in the future, this is what I figured out.
I'm new to c# programming (3 months experience), so this is my first program (in this language and with visual studio). Apparently, once this is released, all of the executables will be put in the same directory as the calling application directory, so the debug subdirectories will be gone. So I need to put my file referenced by B into A's directory.
Thanks for all the help!!
Have a great Memorial Day weekend and enjoy!
|
|
|
|
|
Hey guys,
I have 2 lists defined like this within the class 'image':
public List<uint16> data = new List<uint16>();
I'm trying to subtract two the coresponding values of two instances of the list like this:
UInt16 toAdd, lhs, rhs;
for (int i = 0; i < a.data.Count; i++)
{
lhs = a.data[i];
rhs = b.data[i];
toAdd = lhs + rhs;
}
but I get the error:
Error 1 Cannot implicitly convert type 'int' to 'ushort'. An explicit conversion exists (are you missing a cast?) d:\my documents\visual studio 2010\Projects\Contrast Enhanced Subtaction\Contrast Enhanced Subtaction\Program.cs 28 25 Contrast Enhanced Subtaction
Any ideas?
|
|
|
|
|
Terry Price wrote: Any ideas?
Yes, take the advice offered and use a cast:
UInt16 toAdd, lhs, rhs;
for (int i = 0; i < a.data.Count; i++)
{
lhs = (UInt16)a.data[i];
rhs = (UInt16)b.data[i];
toAdd = lhs + rhs;
}
BTW I don't know what this code is supposed to be doing but I don't think it is doing it right. You say you are trying to subtract something but then you add the same value twice into variable toAdd , so at the end of your loop toAdd will contain the sum of 2 * a.data[0] + 2 * a.data[1] ...
Programming is work, it isn't finger painting. Luc Pattyn
|
|
|
|
|
That still won't compile you know,
Richard MacCutchan wrote: toAdd = lhs + rhs; will still fail with the same error.
|
|
|
|
|
Well spotted; I thought it too trivial to paste into the IDE - serves me right.
Programming is work, it isn't finger painting. Luc Pattyn
|
|
|
|
|
that is not where the problem is; the problem is the addition result is an int, and toAdd is just a ushort, so some narrowing needs enforced.
|
|
|
|
|
|
Terry Price wrote: Program.cs 28
Compiler messages and run-time errors/exceptions tend to include useful information such as class name, file name, and line number. Now tell your IDE to always display the line numbers in source windows and start relying on them.
28
|
|
|
|
|
I have to say this really is a case of 'RTFM', the M being 'message' in this case. The error message tells you which line is broken, what the problem is and how to fix it!
You should use List<ushort> but I guess you are and you just didn't manage to type your post correctly (eaten by the HTML parser?) since there is no List class in .Net.
The answer is: toAdd = (ushort)(lhs + rhs)
... but I must ask why you're using ushorts in the first place. Unless you're declaring these lists to directly interface to a ushort-taking API, there's no reason not to just use uint or int in most cases. Arithmetic operations are optimised for 32 bit numbers and you're just slowing yourself down by using 16 bit.
|
|
|
|
|
BobJanova wrote: but I must ask why you're using ushorts in the first place. Well, he mentioned this being part of a class called "image", so I'd guess its for space reasons. So I'm not very sure that it would be slower either, usually yes (that extra AND at the end costs time, if not that much), but if he's saving cache misses that way then they probably make up for it.
|
|
|
|
|
ushort and int take up the same space on the stack. No memory saving there. Same as bool, they all take up 4 bytes.
"You get that on the big jobs."
|
|
|
|
|
Yes so I wasn't talking about those three local variables, but about the List, which is backed by an array, not by a million local variables.
|
|
|
|
|
But since the OP has not responded to any of our messages this discussion becomes largely academic.
|
|
|
|
|
Maybe the OP will come back on Monday, but I don't actually expect that.
|
|
|
|
|
Here I am using follwing code for the Draw RoundRect.The Path geomatric use for the save RoundRect Points . there is only fault with round rect geometry when combine. single Roundrect geometry is appeared during drawing .but after combine its only Ellips geometry appeared and round rect not appeared.
// --------------------------------------------------------------- //
Below Function generate Round rect PathGeometry...........
// ---------------------------------------------------------------
public PathGeometry RoundRect() { Rect rect = new Rect(30, 30, 200, 200);
Pen pen = new Pen(null, 50); Brush brush = null;
CornerRadius cornerRadius = new CornerRadius(10, 10, 10,10);
var geometry = new StreamGeometry();
using (var context = geometry.Open()) { bool isStroked = pen != null;
const bool isSmoothJoin = true;
context.BeginFigure(rect.TopLeft + new Vector(0, cornerRadius.TopLeft), brush != null, true);
context.ArcTo(new Point(rect.TopLeft.X + cornerRadius.TopLeft, rect.TopLeft.Y), new Size(cornerRadius.TopLeft, cornerRadius.TopLeft), 90, false, SweepDirection.Clockwise, isStroked, isSmoothJoin);
context.LineTo(rect.TopRight - new Vector(cornerRadius.TopRight, 0), isStroked, isSmoothJoin);
context.ArcTo(new Point(rect.TopRight.X, rect.TopRight.Y + cornerRadius.TopRight), new Size(cornerRadius.TopRight, cornerRadius.TopRight), 90, false, SweepDirection.Clockwise, isStroked, isSmoothJoin);
context.LineTo(rect.BottomRight - new Vector(0, cornerRadius.BottomRight), isStroked, isSmoothJoin); context.ArcTo(new Point(rect.BottomRight.X - cornerRadius.BottomRight, rect.BottomRight.Y), new Size(cornerRadius.BottomRight, cornerRadius.BottomRight), 90, false, SweepDirection.Clockwise, isStroked, isSmoothJoin);
context.LineTo(rect.BottomLeft + new Vector(cornerRadius.BottomLeft, 0), isStroked, isSmoothJoin);
context.ArcTo(new Point(rect.BottomLeft.X, rect.BottomLeft.Y - cornerRadius.BottomLeft), new Size(cornerRadius.BottomLeft, cornerRadius.BottomLeft), 90, false, SweepDirection.Clockwise, isStroked, isSmoothJoin);
context.Close(); } PathGeometry pt = new PathGeometry();
pt = PathGeometry.CreateFromGeometry(geometry);
return pt;
}
//------------------------------------------------ Below Function generate Ellips PathGeometry...........
//----------------------------------------------- public PathGeometry ellips() { EllipseGeometry eGeo = new EllipseGeometry(new Rect(30, 30, 200, 200));
return eGeo.GetFlattenedPathGeometry();
} --------------------------------------------------------------- Below Function Combine both pathgeometry and make new pathgeometry --------------------------------------------------------------- PathGeometry pathGeometry = new PathGeometry();
PathGeometry pathGeometry1 = new PathGeometry();
PathGeometry pathGeometry2 = new PathGeometry(); protected override void OnRender(DrawingContext dc) { pathGeometry1 = this.RoundRect(); pathGeometry2 = ellips();
pathGeometry = PathGeometry.Combine(pathGeometry1, pathGeometry2, GeometryCombineMode.Union, null);
dc.DrawGeometry(null, new Pen(new SolidColorBrush(Colors.Red), 1), pathGeometry);
}
//---------------------------------------------------------------
// Output //
---------------------------------------------------------------
But here in outPut ,RoundRect Geometry is not appeared after combined , Only Ellips is appeared Please let me know the mistakee in My Code. Or suggest any other way to achive this functionality
modified 26-May-12 1:38am.
|
|
|
|
|
Please edit your question, reformat your code and put it between <pre> tags so it is readable thus:
public PathGeometry RoundRect()
{
Rect rect = new Rect(30, 30, 200, 200);
...
Programming is work, it isn't finger painting. Luc Pattyn
|
|
|
|
|