|
In my opinion there is nothing wrong with static functions. Just be sure not to use them too much. Otherwise you wont need an object oriented language
In daily programming I declare all functions static which are not accessing/modifying any class fields.
|
|
|
|
|
Yeah! I think that the point! Acctually, i can set all my functions in my class to be static. But in that case my project is not object oriented anymore
I thinks maybe i should reset some functions to be public (may be Insert function to be public and add some properties to my class).
Thanks a lot!
|
|
|
|
|
I am debugging a C# service that opens a file from a folder in the bin/debug folder. I was having issues opening this file and when I finally could get the debugger attached to the process, it wasn't finding the path.
The background of this app is that it started as a console application that worked perfectly. Then the powers that be decided to make it a Windows service.
I finally put in a quick variable to get the path and found out that the path (C:\Windows\Application\Scripts) is prefaced by "@file:\C:\Windows\Application\Scripts".
Is the "file:\" there because of debugging or is that the way the service works in getting it's path?
Any help is much appreciated.
Eric C. Tomlinson
Fear is the mind killer.
|
|
|
|
|
Here's the solution I was able to trace down.
System.Reflection.Module[] modules = System.Reflection.Assembly.GetExecutingAssembly().GetModules();<br />
<br />
string m_ScriptPath = System.IO.Path.GetDirectoryName (modules[0].FullyQualifiedName);<br />
<br />
if ((m_ScriptPath != "") && (m_ScriptPath[m_ScriptPath.Length-1] != '\\'))<br />
{<br />
m_ScriptPath += '\\';<br />
}
Enjoy!
Fear is the mind killer.
|
|
|
|
|
can i detect using code if a connection to the internet is available (preferably without using timers)
|
|
|
|
|
Perhaps you can try a WebRequest/WebResponse. Additionally, System.Windows.Forms.SystemInformation.Network will tell you if a network connection is present.
I'm sure there are many ways to do this, you might want to search around CodeProject as I'm certain this has been asked many times before.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: The Secular Left, the Religious Right, and Prejudice
Judah Himango
|
|
|
|
|
namespace ZetaLib.Windows.Misc
{
#region Using directives.
// ----------------------------------------------------------------------
using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Forms;
// ----------------------------------------------------------------------
#endregion
/////////////////////////////////////////////////////////////////////////
/// <summary>
/// Class that helps in detecting and establishing connections to the
/// Internet.
/// </summary>
public sealed class InternetConnection
{
#region Public types.
// ------------------------------------------------------------------
/// <summary>
/// The type of the Internet connection.
/// </summary>
public enum ConnectionType
{
#region Enum member.
/// <summary>
/// It cannot be determined whether connected or not.
/// </summary>
Unknown,
/// <summary>
/// No connection at all.
/// </summary>
None,
/// <summary>
/// Connected by modem.
/// </summary>
Modem,
/// <summary>
/// Connected through LAN.
/// </summary>
Lan,
/// <summary>
/// Connected through a proxy server.
/// </summary>
Proxy
#endregion
}
/// <summary>
/// Information about an Internet connection state.
/// </summary>
public sealed class ConnectionStateInfo
{
#region Public methods.
/// <summary>
/// Constructor.
/// </summary>
public ConnectionStateInfo(
ConnectionType connectionType,
bool isOnline,
bool isRasInstalled )
{
this.connectionType = connectionType;
this.isOnline = isOnline;
this.isRasInstalled = isRasInstalled;
}
#endregion
#region Public properties.
/// <summary>
/// Get the type of the connection.
/// </summary>
public ConnectionType ConnectionType
{
get
{
return connectionType;
}
}
/// <summary>
/// Check whether currently is online.
/// </summary>
public bool IsOnline
{
get
{
return isOnline;
}
}
/// <summary>
/// Check whether RAS is installed.
/// </summary>
public bool IsRasInstalled
{
get
{
return isRasInstalled;
}
}
#endregion
#region Private helper.
private ConnectionType connectionType;
private bool isOnline;
private bool isRasInstalled;
#endregion
}
// ------------------------------------------------------------------
#endregion
#region Public methods.
// ------------------------------------------------------------------
/// <summary>
/// Query information about the current Internet connection state.
/// </summary>
/// <returns>Returns the information about the current Internet
/// connection state.</returns>
public static ConnectionStateInfo GetConnectionState()
{
InternetConnectionState flags = 0;
bool isConnected = InternetGetConnectedState(
ref flags,
0 );
// --
if ( !isConnected )
{
return new ConnectionStateInfo(
ConnectionType.None,
false,
false );
}
else
{
ConnectionType connectionType = ConnectionType.None;
bool isOnline = false;
bool isRasInstalled = false;
// --
if ( ((int)flags&0xF)==0 )
{
connectionType = ConnectionType.Unknown;
}
else if ( ((int)flags&0xF)==(int)InternetConnectionState.ModemConnection )
{
connectionType = ConnectionType.Modem;
}
else if ( ((int)flags&0xF)==(int)InternetConnectionState.LanConnection )
{
connectionType = ConnectionType.Lan;
}
else if ( ((int)flags&0xF)==(int)InternetConnectionState.ProxyConnection )
{
connectionType = ConnectionType.Proxy;
}
if ( ((int)flags&(int)InternetConnectionState.Offline)==0 )
{
isOnline = false;
}
else
{
isOnline = true;
}
if ( ((int)flags&(int)InternetConnectionState.RasInstalled)==0 )
{
isRasInstalled = false;
}
else
{
isRasInstalled = true;
}
// --
return new ConnectionStateInfo(
connectionType,
isOnline,
isRasInstalled );
}
}
// ------------------------------------------------------------------
#endregion
#region Private helper.
// ------------------------------------------------------------------
[DllImport("wininet.dll", SetLastError=true)]
static extern bool InternetGetConnectedState(
ref InternetConnectionState flags,
int rReserved );
/// <summary>
/// Flags that indicate the different states.
/// </summary>
[Flags]
private enum InternetConnectionState : int
{
ModemConnection = 0x1,
LanConnection = 0x2,
ProxyConnection = 0x4,
RasInstalled = 0x10,
Offline = 0x20,
Configured = 0x40
}
// ------------------------------------------------------------------
#endregion
}
/////////////////////////////////////////////////////////////////////////
}
|
|
|
|
|
i have a small problem. I want to add a fucntionality to my application in which users can drag and .exe file from any window into my form and i can find out the path and icon of the application and add it to my app.
|
|
|
|
|
For getting the icon of files dropped on your app, see the CodeProject article here[^].
For getting the path of files dropped on your app, see this article[^].
Next time you might want to try searching CodeProject or google before posting. That way you'll get an immediate answer and we won't have to post duplicate answers in the forum.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Horrific Minnesota Radio
Judah Himango
|
|
|
|
|
I need help finding out if the user of my program is using Service Pack 2 or not. I tried a spot in registry, but found out that if you uninstall SP2 this registry key stays and the program still says you have SP2. Any help would be great.
|
|
|
|
|
Have you looked as the Environment class and its OSVersion property?
Environment.OSVersion Property[^]
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
As Dave previously mentioned, Environment.OSVersion will contain the name of the service pack, if any. Additionally, in .NET 2.0, the service pack can be accessed directly using Environment.OSVersion.ServicePack.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Horrific Minnesota Radio
Judah Himango
|
|
|
|
|
|
I understood you could mix languages. I created 1 solution with 2 projects with the following code:
C# routine:
using System;<br />
<br />
namespace CSServer {<br />
class CSServer {<br />
<br />
#region Application Start<br />
<br />
static public void Enter_CSServer() <br />
{<br />
int tmp;<br />
Console.WriteLine("Hello World (C#)");<br />
Do_Call_Back("Hello from the CS side", &tmp);<br />
Console.WriteLine("Value={0}",tmp);<br />
} <br />
#endregion<br />
<br />
} <br />
}
CPP Routine: (startup project)
<br />
#include "stdafx.h"<br />
<br />
#using <mscorlib.dll><br />
<br />
using namespace System;<br />
<br />
<br />
int _tmain()<br />
{<br />
Console::WriteLine(S"Hello World(CPP)");<br />
<br />
Enter_CSServer();<br />
<br />
Console::WriteLine(S"Goodbye Cruel World (CPP)");<br />
return 0;<br />
}<br />
int Do_Call_Back(char *str, int *value)<br />
{<br />
Console::WriteLine(str);<br />
*value = 1;<br />
return(1);<br />
} I get routine-not-found on Enter_CSServer and Do_Call_Back.
The real problem is much bigger but this gets the essance.
Scott Krusemark
330-966-1231
|
|
|
|
|
Interesting. Both projects reference each other, I've never done that as I've always kept a heirarchy between projects so there aren't any circular references.
Anyway, you need to reference one project in the other and add the appropriate using statements at the top of the code.
However, because there seems to be a circular reference it might not permit you to do that.
My: Blog | Photos | Next SQL Presentation
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More
|
|
|
|
|
1) I'm new to C# (lots of VB6 coding) how do I 'reference one project in the other'? I went to the Project for the CPP code and did a 'Add Reference' to the C# project and it still got 'identifier not found'. Could it be associated with the namespace?
2) What I'm trying to do with the 'DO_CALL_BACK' routine would be coded WITH EVENTS in VB6, and pass data back from the 'sub-project'. The C# will be handling the TCP/IP and data/events can originate there and must be passed to the CPP code.
Scott Krusemark
330-966-1231
|
|
|
|
|
How should the C++-Compiler know where to find Enter_CSServer() ?
It's a static member of a class CSServer in a namespace CSServer , so the correct call would be
CSServer::CSServer::Enter_CSServer();
Nevertheless, you'll have to reference the C# project, otherwise the compiler won't find the CSServer namespace/CSServer class.
Regards,
mav
|
|
|
|
|
It seems like such a newbie question. I added the 'reference' to the C# project to the C++ project. And added the CSServer::CSServer::Enter_CSServer() for the call. But I get 'CSServer is not a class or namespace name', as well as the Enter_CSServer is not found.
Is there any way you could put this simple sample with .sln file together so it compiles? Seems like such a simple problem but I don't see it.
Scott Krusemark - scott(at)askent.com
Scott Krusemark
330-966-1231
|
|
|
|
|
Apart from the missing namespace and class name the whole thing won't compile because the callback isn't defined either.
Remove the call to Do_Callback(), then you should be able to compile the C# class library at least.
After this you should add a reference in your C++ project to the C# class library and, by using the fully qualified name including namespace, be able to call the static function.
Regards,
mav
|
|
|
|
|
Already did that. The C# compiles just fine. But then the C++ does not find the namespace.
I tried adding the using namespace CSServer; to the C++ code, it errors out.
I tried adding a #using <testmix.dll> and it finds the .dll but no change on compile.
I tried adding a namespace CSServer; to C++ code and the intelisense finds the _tmain and do_call_back entry points for CSServer::[intelisense here] but not the CSServer class.
I tried making sure everything has the same namespace but looks like C++ does not have a 'default' namespace.
It's probably just some simple setting I'm missing (I suspect on the C# side) but I sure don't see it.
I appreciate your help btw.
Scott Krusemark
330-966-1231
|
|
|
|
|
How to modify the location of a dynamically created control in a asp.net page using c#?
|
|
|
|
|
The ASP.NET forum will help you will ,i think.
|
|
|
|
|
Actually i tried transforming the region of the control to a rotation...
for example,
Region reg = new Region();
Matrix matObj = new Matrix();
matObj.RotateAt(/*some angle*/, /*with respect to some point*/);
reg.Transform(matobj);
myControl.Region = reg;
Iam able to attain the rotation...but supposing the region (reg in this example)is in another shape(than rectangle)...say ellipse, then the shape of the ellipse is not visible completely....reason is that the rectangle coordinates(i.e. the original rectangle size) used to draw the ellipse is smaller than the rotated structure...(after rotation, the location of points are actually out of the bounds of the controls client rectangle...)
So i tried to get the size of the outer rectangle which has completely both the original and the rotated rectangles... by some trignometry...
but nope, im not getting the exact coordinates...
can you help me in this??
Thanks and Regards,
Rajesh
|
|
|
|
|
<Message>
<Questions>
...
</Questions>
<Answers id = 1>
..
</Answers>
<Answers id = 2>
..
</Answers>
</Message>
If , we have to get the node corresponding to the Answers node with id = 1 ,
how can we do that?
Shankar C
|
|
|
|
|
A good idea would be to load the contents of your XML file into a dataSet and do your searching on the dataSet instead. This gives you the advantage of handling XML data as if it was an ordinary Database.
Regards,
Polis
Can you practice what you teach?
|
|
|
|