|
smurfy34 wrote: what path do I hardcode
:SMACK: Stop right there! You don't hardcode paths into your code, ever! This is because sometimes people don't have their Program Files folder on the C: drive, or someone might not install your app in the folder you think they will.
Two rules: Don't ever hardcode paths. never assume that the current directory is what you think it is. And always use comlete, full qualified paths when specifying a file to work with.
You'll save yourself many a headache trying to troubleshoot a problem on a customers machine when you can't replicate the problem on your test machine.
So, if I can't hardcode a path, how can I possibly build a fully qualified filepath?
Easy. If you put the configuration file in the same folder as the .EXE, you can use <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsapplicationclassstartuppathtopic.asp" rel="nofollow">Application.StartupPath</a>[<a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsapplicationclassstartuppathtopic.asp" target="_blank" rel="nofollow" title="New Window">^</a>] to get the path to the folder that the .EXE is in, then just use <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemiopathclasscombinetopic.asp" rel="nofollow">Path.Combine</a>[<a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemiopathclasscombinetopic.asp" target="_blank" rel="nofollow" title="New Window">^</a>] to combine the StartupPath with the filename of your config file to get the complete path to the file.
string configFilePath = Path.Combine( Application.StartupPath, @"config.filename" );
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Or you may use
Environment.CurrentDirectory
which will give the the directory from where the process starts.
Hope this helps...
Bikash Rai
|
|
|
|
|
Bikash Rai wrote: which will give the the directory from where the process starts.
It will give you the folder that was current when the process started, not necessarily the folder that the .EXE is in.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Exactly what I said. The process starting directory.....
Bikash Rai
|
|
|
|
|
Wait a minute... He's not looking for the directory from where the app was started. He's looking to get the directory that the .EXE is in, so it knows where to pick up this config file.
Environment.CurrentDirectory will return the current directory can never be relied on to be the directory the .EXE is in. This is because there are many ways to launch an .EXE, each of which can have a different current directory:
If the .EXE is launched directly, by double-clicking it's icon, the current directory will be the folder that the .EXE is installed in.
If the .EXE is launched by a shortcut, the current directory will be the directory specified in the shortcut, if it's specified. If not, then the current directory can be anything!
If the .EXE is launched by a batch file, then the current directory will be the last directory listed in the command prompt, i.e. C:\WINDOWS.
Application.StartupPath will give you the directory that the .EXE is in, no matter what it is or where it's launched from.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Dave Kreskowiak wrote: Wait a minute... He's not looking for the directory from where the app was started. He's looking to get the directory that the .EXE is in, so it knows where to pick up this config file.
Environment.CurrentDirectory will return the current directory can never be relied on to be the directory the .EXE is in. This is because there are many ways to launch an .EXE, each of which can have a different current directory:
If the .EXE is launched directly, by double-clicking it's icon, the current directory will be the folder that the .EXE is installed in.
If the .EXE is launched by a shortcut, the current directory will be the directory specified in the shortcut, if it's specified. If not, then the current directory can be anything!
If the .EXE is launched by a batch file, then the current directory will be the last directory listed in the command prompt, i.e. C:\WINDOWS.
Application.StartupPath will give you the directory that the .EXE is in, no matter what it is or where it's launched from.
Yes Dave, I am aware of what I have written. I was just trying to be more helpful by giving other options which could be tried out, if for some bizzare reason the Application.Startup solution was not the one he was looking for.
Just trying to be helpful, no hard feelings.
Bikash Rai
|
|
|
|
|
Special folder can be got from the
Environment.SpecialFolder enumeration.
If a folder path of one the enumerations is needed then
Environment.GetFolderPath(Environment.SpecialFolder.Desktop) gives you the full path of the destop folder of the currently logged in user.
If you are talking about the SetupWizard then the variable
TARGETDIR gives you the directory where the application is getting installed.
Hope this helps...
Bikash Rai
|
|
|
|
|
Hi,
I have a native DLL exporting somes functions (__declspec( dllexport )).
I have converted the project in VS 2005... all work fine.
I try now to compile the project with /clr option.
All work fine.
But when I compile my other project (this project call functions from the native DLL)
(it's in native compiled in VS 2005 with /clr option),
when it link I got lot of error like this:
NodeRDTiff.obj : error LNK2028: unresolved token (0A00024C) "int __cdecl file_Close(void *)" (?file_Close@@$$FYAHPAX@Z) referenced in function "public: virtual void __thiscall CNodeRDTiff::ReleaseFile(void)" (?ReleaseFile@CNodeRDTiff@@$$FUAEXXZ)
But if I compile the first project without /clr, the second project will link correctly.
Someone can help me ?
Best regards,
===================
Martin Bonneville
Analyst-programmer
|
|
|
|
|
Go To->Project Properties->Linker->Input Screen
In the additional dependencies add msvcmrt.lib.
Check it out if it helps to solve the issue.
HV
|
|
|
|
|
Hi,
I added msvcmrt.lib to the dependencies of my 2 projects... I got the same error.
Best regards,
==========================
Martin Bonneville
Analyst-programmer
|
|
|
|
|
Hi,
The picture box in VB6 could be used as a container too but it seems like the one in .NET cannot be used as a container. Am I correct? If this is correct then why did MS remove this feature from the PictureBox? It was great when it acted as a container..
Thanks,
Bikash Rai
|
|
|
|
|
Bikash Rai wrote: but it seems like the one in .NET cannot be used as a container. Am I correct?
No, it is a container (see its .Controls property), but that is not it's primary purpose. If you need a control container, use a Panel control instead.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
But it cannot contain controls like the old VB6 way??
Bikash Rai
|
|
|
|
|
What are you talking about??
But, no matter what, the ultimate solution is for you to adapt to the situation and re-write your code a little bit.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Dave Kreskowiak wrote: What are you talking about??
I think in Visual Basic 6, a picture box behaved very much like the Gourp box control, i.e. controls could be dragged and dropped in the Picturebox and etc. This is not possible in .NET.
---
With best regards,
A Manchester United Fan
The Genius of a true fool is that he can mess up a foolproof plan!
|
|
|
|
|
I know it's not possible to drag and drop controls into a PictureBox in .NET. It's a frickin' PictureBox control, not a GroupBox or a Panel! If you're going to do something, use the correct control for the job, not because "it used to work in VB6".
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Dave Kreskowiak wrote: I know it's not possible to drag and drop controls into a PictureBox in .NET. It's a frickin' PictureBox control, not a GroupBox or a Panel! If you're going to do something, use the correct control for the job, not because "it used to work in VB6".
Look sometimes situations arise wherein you wish special features existed and using the Picture Box is one of them. I wouldn't normally use a picturebox to group controls, but there are cases when you wished that it would. I guess you haven't come across one but believe me when you come across one, you would also wish the same. And I do know which controls are used for what purpose.
I was just getting an insight as to whether the PictureBox has the same functionality as it used to have in VB6. Not because I think a PictureBox is used to group controls...........
---
With best regards,
A Manchester United Fan
The Genius of a true fool is that he can mess up a foolproof plan!
|
|
|
|
|
Save My Soul - (SMS) wrote: Look sometimes situations arise wherein you wish special features existed and using the Picture Box is one of them.
Not in my opinion. It's too heavy a control to be used as just a Group Box.
Save My Soul - (SMS) wrote: I wouldn't normally use a picturebox to group controls, but there are cases when you wished that it would. I guess you haven't come across one but believe me when you come across one, you would also wish the same.
I have never and will never wish that a PitureBox control supported anything other than displaying an image, or any other control supported anything other than what it was written for.
If I need a control to support something, I either find a library that supports what I need or I write it! I never wish some other control supported what it wasn't written to do.
I've been writing code since 1976. Don't tell me "when you come acrossed ... you will". I've handled these situations hundreds of times.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Now this whole thing is getting outta hand. I just wanted to know if a picture box can group controls and look where this has landed me in. Dave, I am sorry if I said anything bad. I didn't mean to. And I am sure you are a great programmer. .... Peace Bro...
---
With best regards,
A Manchester United Fan
The Genius of a true fool is that he can mess up a foolproof plan!
|
|
|
|
|
Save My Soul - (SMS) wrote: I wouldn't normally use a picturebox to group controls, but there are cases when you wished that it would. I guess you haven't come across one but believe me when you come across one, you would also wish the same. And I do know which controls are used for what purpose.
If I ever came across such a situation I'd create my own custom control for the purpose. A PicutreBox is designed for displaying picutres not grouping controls. If the old VB6 way allowed you to group other controls inside its PictureBox then there was a very clear violation of the OO tenant of separation of concerns, which, in my opinion, would mean that it was very badly designed.
My: Blog | Photos
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
|
|
|
|
|
Colin Angus Mackay wrote: If I ever came across such a situation I'd create my own custom control for the purpose.
I will surely keep that in mind. Thanks..
---
With best regards,
A Manchester United Fan
The Genius of a true fool is that he can mess up a foolproof plan!
|
|
|
|
|
Has anyone been able to locate a managed code RTP stack?
Looking to do some VoIP work (SIP) and will need one.
... and I would rather not roll my own if I would help it.
George Carlin wrote:
"Don't sweat the petty things, and don't pet the sweaty things."
Jörgen Sigvardsson wrote:
If the physicists find a universal theory describing the laws of universe, I'm sure the a**hole constant will be an integral part of that theory.
My Blog[^]
|
|
|
|
|
create dll whose code cannot be decoded by reflector
Anuj Kamthan
Software Developer
Solversa Technologies,
Pune - 411007, India.
http://www.solversa.com
|
|
|
|
|
use C++
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Christian's right. Any of the Managed Languages, C#, VB.NET, Managed C++, ..., can all be decoded using Reflector.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|