|
Do you mean the IP of the host computer (the one the app is running on?) In a Windows Forms app use this code:
string strHostName = "";
string strIP;
try
{
strHostName = Dns.GetHostName();
IPAddress [] ips = Dns.Resolve(strHostName).AddressList;
if(ips.Length >= 1)
strIP = ips[0].ToString();
else
strIP = "(error)";
}
catch
{
if(strHostName == null || strHostName.Length == 0)
strHostName = "(error)";
strIP = "(error)";
} If you are developing an ASP.NET application and you want to get the IP of the computer connecting to you, I suppose it's possible, but I have no idea.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
I means to How do I find the IP address of the Client App connecting to a dot NET remoting service(C#).
program jys 2003 77 60 kill Japan.
|
|
|
|
|
Well, then I have no idea.
This is why you should explain your question the best you can the first time. "How to get client IP" is just to vague. There are many situations where that phrase makes sense and there's no way for us to know which in particular is your situation. By asking better questions, you can be sure of getting better answers that really address your problem, and not, like in this case, an answer that took some time to write that is totally unrelated.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
i want some information about all port
|
|
|
|
|
I live in Hobart. Hobart is a port, but not a busy one. Melbourne is a busier port, but Sydney is busier again.
If you wanted other information, be a little more specific about what you're trying to do.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Maybe he meant something like this.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
The really sad part is this is the second time he's posted this very same statement! He deleted the first one after getting a similar response.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi,
I have a big array n*n matrix in an .xls (Excel Spreadsheet) and I want to read it into the my C# which calculates the inverse of it. I am not sure how to read the xls file into a 2D array.
n is variable, i.e. it is not known beforehand. It can be 300, 400 0r 500 or any value. Basically, the user gives the input as the file name in which he has storted the matrix.
And does anyone aware of any fast and qucik algorithm by which I can check if a large matrix is singular or not.
Regards
|
|
|
|
|
Hey folks,
I am not very good at C# programming.
I want to write a piece of C# code to change the Pool size in Application pooling of a COM+ component?
Do you guys know how can I do that.
Thanks a bunch.
Tommy.
|
|
|
|
|
Hi! Im creating a form in which i retrieve data from a database and attach it to a grid. I need to have a function in which if i click the save button the results of the retrieved data will be saved as a "text" file. cane someone please tell me what's wrong with my code bcoz whenever i click my save button it doesn't save at all. here's my code:
private void btnSave_Click(object sender, System.EventArgs e)
{
OdbcConnection cnn = new OdbcConnection();
cnn.Open();
OdbcCommand cmmd = new OdbcCommand();
OdbcDataAdapter adp = new OdbcDataAdapter (cmmd);
DataSet ds_emp = new DataSet();
adp.Fill(ds_emp);
System.Text.StringBuilder sb = new System.Text.StringBuilder();
for(int i=0;i<=ds_emp.Rows.Count - 1; i++)
{
for(int q=0;q<=ds_emp.Columns.Count - 1; q++)
{
sb.Append(ds_emp.Rows[i][q].ToString());
}
sb.Append(" ");
}
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=*.txt");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.text";
System.IO.StringWriter strWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(strWrite);
Response.Write(sb.ToString());
}
where ds_emp is the retrived data. Is there something wrong with my code? It builds but it doesn't work. Thanx for all your replies! I appreciate it
thanx
|
|
|
|
|
I have the following URL:
http://patft.uspto.gov/netacgi/nph-Parser?Sect1=PTO2&Sect2=HITOFF&u=/netahtml/search-adv.htm&r=2&p=1&f=G&l=50&d=ptxt&S1=((teeth+OR+member)+OR+provide)&OS=+(teeth+OR+member)+OR+provide&RS=((teeth+OR+member)+OR+provide)
Accessing it with the following code snippet (which works for other sites):
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
throws a WebException (timeout). Accessing the same URL with IE works fine. I compared the request header sent by the code and the one sent by IE and they are identical. The user agent has been set to "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50215)"
I even increased the request timeout to a massively huge value and it didn't make any difference.
|
|
|
|
|
There is something wrong with the headers. I was getting this error: "The underlying connection was closed: The server committed an HTTP protocol violation." put this in your config file and it should resolve the issue.
<configuration>
<system.net>
<settings>
<httpwebrequest useunsafeheaderparsing="true">
|
|
|
|
|
Put what? It looks like you forgot to check the box below the message window that says "Do not treat <<s as HTML tags".
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Sorry dude. Here it is:
<configuration>
<system.net>
<settings>
<httpWebRequest useUnsafeHeaderParsing="true" />
</settings>
</system.net>
</configuration>
|
|
|
|
|
You might want to reply to the original poster with this, not me. He'll get a notification e-mail that says you replied to him that way.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Is it possible to insert a jpg,gif or a bitmap file into a crystal report programmatically? If so can someone point me in the right direction. I've been looking on the web but can't seem to find anything about it.
|
|
|
|
|
Hello!
I have an old notebook with no display (don’t ask - long story). Now I want to put it back in use by developing a Text-to-Speech-based menu, e.g. I press ‘m’ and the program outputs something like “You are in the main menu. Press 1 to do …., press 2 to do ….., …” via TTS – all just for fun. The TTS part isn’t much of a problem but I was wondering if I could reassign keys like the windows key. Essentially, I would like to globally (before Windows does) intercept any keyboard events and then pass them directly to an application of my choice or simply drop them.
Am I looking for a hook? Or do they, as I’ve read, only allow for monitoring system events but not altering or discarding them all together?
If I’m wrong with that assumption I would appreciate any help concerning hooks and especially their interop side. I’ve read that global hooks require the code to reside in a DLL? I guess this doesn’t include managed DLLs and I would have to do it in unmanaged C++.
If I’m right I’m open to any suggestions and any useful resources you can provide.
Thanks in advance.
Regards,
Florian
|
|
|
|
|
I've done something kind of similar to what your thinking of. I did it in C++ though. I found it much easier than trying to Interop the thing. You'll also be able to rebuild/customize keyboard messages easier too. If you want to eat a keyboard message, it's easy enough. You just don't pass it up the hook chain when you're done processing it, if any.
Global, low-level hooks, can be in an .EXE and still work. The latest example I used of this was to eat any Windows key message. (This effectively disables hitting Windows-E and starting Explorer, even though Group Policy disabled running it!)
You're only problem, that I see, is going to be maintaining control of focus while you send keyboard messages around.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thank you so far.
I haven't been programming C++ for 2 years now so I would prefer doing as much as possible in C#.
I guess I could write a C++ DLL and then wrapp it with some managed code.
I think I'm going to read a few MSDN articles about hooks.
|
|
|
|
|
I didn't say it couldn't be done entirely in C#, I just said I found it easier to do in C++. If you wanted to, you could write the thing in Managed C++ so it's easier to build an interface to your C# app.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I found an interesting article on .NET 247 (http://www.dotnet247.com/247reference/msgs/26/134226.aspx) and rewrote the code to match the new C++ syntax introduced with .NET 2.0.
#pragma once
#include <windows.h>
#undef MessageBox
#using <system.dll>
#using <system.windows.forms.dll>
using namespace System;
using namespace System::Windows::Forms;
using namespace System::Reflection;
using namespace System::Runtime::InteropServices;
#pragma data_seg(".Share")
HHOOK g_Hook = 0;
#pragma data_seg()
#pragma comment(linker, "/section:.Share,rws")
namespace Hooks
{
int __stdcall KeyboardProc(int code, int wparam, int lparam)
{
String^ text = String::Concat("You pressed : ", ((Keys)wparam).ToString());
MessageBox::Show(text, "Hook Message", MessageBoxButtons::OK);
return CallNextHookEx(g_Hook, code, wparam, lparam);
return 0;
}
public ref class KeyboardHook
{
private:
KeyboardHook() {};
public:
static void SetHook() {
if (g_Hook != 0)
return;
Module^ mod = Assembly::GetExecutingAssembly()->GetModule("Hooks.dll");
IntPtr hinst = Marshal::GetHINSTANCE(mod);
g_Hook = SetWindowsHookEx(WH_KEYBOARD, reinterpret_cast<HOOKPROC>(KeyboardProc), static_cast<HINSTANCE>(hinst.ToPointer()), 0);
}
static void Unhook() {
if (g_Hook != 0) {
UnhookWindowsHookEx(g_Hook);
g_Hook = 0;
}
}
};
};
At first I don’t understand exactly why the g_Hook variable is declared after #pragma data_seg(“.Share”).
Besides this I need a more flexible way to integrate it into C# so I declared a managed class KeyboardHookEventArgs and a delegate KeyboardHookDelegate which I wanted to pass in from C#.
The delegate should then be called and pass all information about the keyboard event in my C# app.
The problem is I can’t invoke the delegate from inside the HOOKPROC callback because the delegate is managed but the callback is not (__stdcall).
Another issue: How do I check that the callback variable is assigned? In C# I would check if the variable is null but in C++, using NULL, I get the error that my delegate type can’t be implicitly casted to int.
Here the code for the KeyboardHookEventArgs and the delegate:
public ref class KeyboardHookEventArgs
{
private:
bool block;
int code;
int wParam;
int lParam;
public:
property bool Block
{
bool get()
{
return block;
}
void set(bool value)
{
block = value;
}
}
property int Code
{
int get()
{
return code;
}
void set(int value)
{
code = value;
}
}
property int WParam
{
int get()
{
return wParam;
}
void set(int value)
{
wParam = value;
}
}
property int LParam
{
int get()
{
return lParam;
}
void set(int value)
{
lParam = value;
}
}
KeyboardHookEventArgs()
{
block = false;
code = 0;
wParam = 0;
lParam = 0;
}
KeyboardHookEventArgs(int code, int wParam, int lParam)
{
this->code = code;
this->wParam = wParam;
this->lParam = lParam;
this->block = false;
}
KeyboardHookEventArgs(int code, int wParam, int lParam, bool block)
{
this->code = code;
this->wParam = wParam;
this->lParam = lParam;
this->block = block;
}
};
public delegate void KeyboardHookDelegate(KeyboardHookEventArgs^ e);
The Block property in the event args is used to determine wether the event should or should not be passed on.
I’m really stuck here and hope somebody can give me some hints.
|
|
|
|
|
|
Ok i need to know how to figure out how many milliseconds have passed over a period of time. I do this with two... "time stamps" - dtmCurrent & dtmPrevious - I then just subtract (dtmCurrent-dtmPrevious) and i get a TimeSpan. How do i convert that TimeSpan into an int? I need that int to be how many milliseconds have passed in that TimeSpan, though.
Of course if there is a better way to do this... without a timer... then i'm all up for suggestions.
Here's a snipet of my code thats used.
bool FirstRun = true;<br />
DateTime dtmCurrent;<br />
DateTime dtmPrevious;<br />
<br />
private void MainGame()<br />
{<br />
if (FirstRun == true)<br />
{<br />
this.ObjectEngine.Create_Unit(1,0,1,400,400,0);<br />
FirstRun = false;<br />
dtmCurrent = DateTime.Now;<br />
}<br />
dtmPrevious = dtmCurrent;<br />
dtmCurrent = DateTime.Now;<br />
<br />
for (int i=0; i<ObjectEngine.ActiveUnitQPt; i++)<br />
{<br />
Sprite_Update((dtmCurrent - dtmPrevious), i);<br />
}<br />
SpriteEngine.Draw();<br />
}
|
|
|
|
|
|
Hi..
I am getting this Error while DateTime.Parse(txtActStartDate.ToString())
where the textbox contains - 31-01-2004 -- in dd-MM-yyyy format
The string was not recognized as a valid DateTime. There is a unknown word starting at index 0.
Whats the problem?
Thanks
|
|
|
|