|
Can anyone tell me how to find which specific processes are running on opened TCP ports??
As far as I sacnned the MSDN documentation, the information is found in GetExtendedTcpTable
and we have to import iphlpapi.dll for this..
Here is the snippet of my code:
class ProcessClass<br />
{<br />
public:<br />
[DllImport("iphlpapi.dll")]<br />
DWORD GetExtendedTcpTable(PVOID tcpTable, PDWORD tcpTableLength, BOOL sort, ULONG ipVersion, TCP_TABLE_CLASS tcpTableType, ULONG reserved);<br />
MIB_TCPROW_OWNER_PID tcpTable[2000];<br />
<br />
void GetProcesses();<br />
};<br />
<br />
void ProcessClass ::GetProcesses()<br />
{<br />
DWORD size = 2000;<br />
GetExtendedTcpTable(&tcpTable, &size, FALSE, AF_INET, TCP_TABLE_OWNER_PID_ALL, 0); <br />
}
But the problem is that I get an empty 'tcpTable'..
How to get the process ID's??
Som
|
|
|
|
|
Why are you using DllImport when you are developing in C++?
What OS and SP are you running on?
led mike
|
|
|
|
|
What's the return value from GetExtendedTcpTable?
You are incorrectly using the first two parameters in the call.
The structure pointed to should be a MIB_TCPTABLE_OWNER_PID struct,
inside of which should be an array of MIB_TCPROW_OWNER_PID structs.
You also have no idea if 2000 is enough bytes for the struct. You need to use the API
correctly to get the actual size you need and allocate the struct as an array of bytes.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi all
Could anyone please let us know the C++ API (do not want Windows API) which will give the base address of the current stack ?
Thanks in advance
redindian
|
|
|
|
|
|
Server
<br />
Socket ^s....<br />
FileStream ^fs..<br />
array<byte>^data=gcnew array<byte>(4096);<br />
int len;<br />
do<br />
{<br />
len=fs->Read(data,0,4096);<br />
s->Send(data,0,len);<br />
}<br />
</byte></byte>
file Send but don't Complete i think socket send byte with Speed and data Replace with data!
|
|
|
|
|
javad_2005 wrote: file Send but don't Complete
Send to what?
Don't Complete means what?
javad_2005 wrote: i think socket send byte with Speed and data Replace with data!
I have no idea what that means but it sounds like something I would not believe.
led mike
|
|
|
|
|
None of the Socket::Send() overloads matches your code. Which one are you using?
What type of array is data?
Where's the loop logic code?
Is the socket blocking or non blocking?
You don't check the number of bytes sent? What if they all don't get sent in one Send() call?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
We are like a double decker Filet-o-Fish in this thread. Do they make one of those?
led mike
|
|
|
|
|
Server Code:
<br />
enum Command<br />
{<br />
NULL,<br />
Message,<br />
CreateFile,<br />
WriteFile,<br />
Close<br />
};<br />
<br />
Object ^ RawDeserialize(array<Byte> ^rawdatas, Type ^anytype ) <br />
{ <br />
int rawsize = Marshal::SizeOf(anytype ); <br />
if( rawsize > rawdatas->Length ) <br />
return nullptr; <br />
IntPtr buffer = Marshal::AllocHGlobal( rawsize ); <br />
Marshal::Copy( rawdatas, 0, buffer, rawsize ); <br />
Object ^retobj = Marshal::PtrToStructure( buffer, anytype ); <br />
Marshal::FreeHGlobal( buffer ); <br />
return retobj; <br />
} <br />
[StructLayout(LayoutKind::Sequential, Pack=1, CharSet=CharSet::Ansi)] <br />
ref struct TcpPacket<br />
{<br />
[MarshalAs(UnmanagedType::ByValArray,ArraySubType=UnmanagedType::LPWStr,SizeConst=4096)]<br />
array<Byte>^data; Command cmd; int Length; public:<br />
TcpPacket()<br />
{<br />
cmd=Command::NULL;<br />
data=gcnew array<Byte>(4096);<br />
}<br />
};<br />
ref struct ClientInfo<br />
{<br />
Socket ^socket;<br />
array<Byte> ^Buffer;<br />
};<br />
<br />
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)<br />
{<br />
Socket ^TcpSocket=gcnew Socket(AddressFamily::InterNetwork,SocketType::Stream,ProtocolType::Tcp);<br />
IPEndPoint ^ipEndPoint=gcnew IPEndPoint(IPAddress::Any,5400);<br />
TcpSocket->Bind(ipEndPoint);<br />
TcpSocket->Listen(0);<br />
TcpSocket->BeginAccept(gcnew AsyncCallback(this,&Form1::OnAccept),TcpSocket);<br />
}<br />
<br />
void OnAccept(IAsyncResult ^ar)<br />
{<br />
ClientInfo ^info=gcnew ClientInfo;<br />
Socket ^socket=safe_cast<Socket ^>(ar->AsyncState);<br />
Socket ^SockAccept=socket->EndAccept(ar);<br />
TcpPacket ^Packet=gcnew TcpPacket; int PSize=Marshal::SizeOf(Packet);<br />
info->socket=SockAccept;<br />
info->Buffer=gcnew array<Byte>(PSize);<br />
SockAccept->BeginReceive(info->Buffer,0,PSize,SocketFlags::None,gcnew AsyncCallback(this,&Form1::OnReceive),info);<br />
}<br />
void OnReceive(IAsyncResult ^ar)<br />
{<br />
ClientInfo ^info=safe_cast<ClientInfo ^>(ar->AsyncState);<br />
info->socket->EndReceive(ar);<br />
<br />
TcpPacket ^Packet=gcnew TcpPacket; <br />
Type ^typeTcpPacket=Type::GetType(String::Format("{0}",Packet));<br />
Packet=(TcpPacket ^)RawDeserialize( info->Buffer,typeTcpPacket);<br />
ReleasePacket(Packet);<br />
int PSize=Marshal::SizeOf(Packet);<br />
info->Buffer=gcnew array<Byte>(PSize);<br />
info->socket->BeginReceive(info->Buffer,0,PSize,SocketFlags::None,gcnew AsyncCallback(this,&Form1::OnReceive),info);<br />
}<br />
FileStream ^file;<br />
void ReleasePacket(TcpPacket ^Packet)<br />
{<br />
switch(Packet->cmd)<br />
{<br />
case Command::CreateFile:<br />
{<br />
file=gcnew FileStream("c:\\2.jpg",FileMode::Create);<br />
break;<br />
}<br />
case Command::WriteFile:<br />
{<br />
file->Write(Packet->data,0,Packet->Length);<br />
break;<br />
}<br />
case Command::Close:<br />
{<br />
file->Close();<br />
MessageBox::Show("File Complete");<br />
break;<br />
}<br />
<br />
}<br />
}<br />
<br />
Client Source
<br />
array<Byte> ^ Serialize(Object ^Struct)<br />
{<br />
<br />
int len=Marshal::SizeOf(Struct);<br />
IntPtr ptr=Marshal::AllocHGlobal(len);<br />
array<Byte>^ rawdatas = gcnew array<Byte>(len);<br />
Marshal::StructureToPtr(Struct,ptr,false);<br />
Marshal::Copy( ptr, rawdatas, 0, len ); <br />
Marshal::FreeHGlobal( ptr ); <br />
return rawdatas; <br />
}<br />
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)<br />
{<br />
Socket ^TcpSocket=gcnew Socket(AddressFamily::InterNetwork,SocketType::Stream,ProtocolType::Tcp);<br />
TcpSocket->BeginConnect(gcnew IPEndPoint(IPAddress::Parse("127.0.0.1"),5400),<br />
gcnew AsyncCallback(this,&Form1::OnConnect),TcpSocket);<br />
}<br />
void OnConnect(IAsyncResult ^ar)<br />
{<br />
Socket ^socket=safe_cast<Socket ^>(ar->AsyncState);<br />
socket->EndConnect(ar);<br />
FileStream ^file=gcnew FileStream("c:\\1.jpg",FileMode::Open);<br />
TcpPacket ^Packet=gcnew TcpPacket; <br />
array<Byte>^ Data=gcnew array<Byte>(Marshal::SizeOf(Packet));<br />
Packet->cmd=Command::CreateFile; <br />
Data=Serialize(Packet);<br />
socket->Send(Data,Data->Length,SocketFlags::None);<br />
int len;<br />
do<br />
{<br />
Packet->cmd=Command::WriteFile;<br />
len=file->Read(Packet->data,0,4096);<br />
Packet->Length=len;<br />
Data=Serialize(Packet);<br />
socket->Send(Data,Data->Length,SocketFlags::None);<br />
}while(len>0);<br />
<br />
Packet->cmd=Command::Close;<br />
Data=Serialize(Packet);<br />
socket->Send(Data,Data->Length,SocketFlags::None);<br />
}<br />
<br />
|
|
|
|
|
Hi, I'm attempting to create a collapsible property in the the PropertyGrid. I've got it to work properly, the only issue I'm having is the sub-properties in the collapsible section are all in bold. I've set their DefaultValueAttributes to be the same as their value, and still they are bold. Is there something different I have to do when they are collapsible? Below is the code for the collapsible section.
<br />
ref class PointF3D : public System::Object<br />
{<br />
protected:<br />
float x;<br />
float y;<br />
float z;<br />
<br />
public:<br />
<br />
<br />
PointF3D(float fx, float fy, float fz)<br />
{<br />
x = fx;<br />
y = fy;<br />
z = fz;<br />
}<br />
<br />
void FromString(System::String^ s);<br />
<br />
virtual System::String^ ToString() override;<br />
<br />
[System::ComponentModel::RefreshProperties(<br />
System::ComponentModel::RefreshProperties::Repaint), <br />
System::ComponentModel::DefaultValueAttribute(0)]<br />
property float Z {<br />
float get() { return z; }<br />
void set(float value) {<br />
z = value;<br />
}<br />
}<br />
<br />
[System::ComponentModel::RefreshProperties<br />
(System::ComponentModel::RefreshProperties::Repaint),<br />
System::ComponentModel::DefaultValue(0)]<br />
property float Y {<br />
float get() { return y; }<br />
void set(float value) {<br />
y = value;<br />
<br />
}<br />
}<br />
<br />
[System::ComponentModel::RefreshProperties(<br />
System::ComponentModel::RefreshProperties::Repaint),<br />
System::ComponentModel::DefaultValue(0)]<br />
property float X {<br />
float get() { return x; }<br />
void set(float value) {<br />
x = value;<br />
<br />
}<br />
}<br />
<br />
<br />
<br />
};
Thanks!
|
|
|
|
|
TheBerk wrote: Hi, I'm attempting to create a collapsible property in the the PropertyGrid.
Do you mean you are using System::ComponentModel::ExpandableObjectConverter? I don't see that anywhere in your post.
What version of .NET are you using?
led mike
|
|
|
|
|
Forgot to include that, I've used the ExpandableObjectConverter as a base class and inherited from it with:
[System::ComponentModel::TypeConverter(PointF3DConverterSystem::typeid)].
The new class just allows for the main line of the collapsible property to display the correct string.
|
|
|
|
|
TheBerk wrote: the sub-properties in the collapsible section are all in bold.
what specifically is in bold?
I just ran my app ( in XP Pro .NET 2.0) where I am using it and the editable values are all in bold. The property names are not in bold even for the ExpandableObject implementation. So it looks like all the other items in the PropertyGrid accept you can expand/collapse it.
led mike
|
|
|
|
|
Its not the property names, but the values that can be altered when the collapsible property is expanded. The header value for the collapsible property is not in bold, but its sub values are. Values are only suppose to be in bold when they are altered from their default values, but my values match the default and they still appear bold.
Thanks!
|
|
|
|
|
I was able to solve this problem by using 'ShouldSerializeXXX' (where XXX is the property name) function instead of the 'DefaultValueAttribute'. Thanks for the help!
|
|
|
|
|
Hi guys I'm new in programming but I need help with one task in visual c++ 2005 express edition. So the task is:
Put Textbox button(I've made this with the toolbox)
1.When click on the textbox button must show MessageBox with Yes and No buttons. Catch the answer and show it in the Textbox.
I made the MessageBox(look under) but don't know how to make it to show in the TextBox??? Can someone help me please?
private: System::Void textBox1_MouseClick(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) {
MessageBox::Show( "Yes or no?",
"Choose", MessageBoxButtons::YesNo);
|
|
|
|
|
You need to get the return value of the message box, then use it to set the text of the textbox.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
As I said I'm begginer and I created the following:
private: System::Void textBox1_MouseClick(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) {
DialogResult::get();
MessageBox::Show("Caption", "Message", MessageBoxButtons::YesNo, MessageBoxIcon::Question);
if(ShowDialog()==System::Windows::Forms::DialogResult::Yes)
{
//-----
this->textBox1->Text == L"Yes";
}
else if(ShowDialog()==System::Windows::Forms::DialogResult::No)
{
//---
this->textBox1->Text == L"No";
}
}
};
}
When I press F5 it gives me the folllowing error: "An unhandled exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll
Additional information: Form that is already visible cannot be displayed as a modal dialog box. Set the form's visible property to false before calling showDialog." I make this but the textBox dissapears. I guess the wrong is here:this->textBox1->Text == L"Yes"; Help me pls???
|
|
|
|
|
Read te error message. The problem is that you're calling ShowDialog on a dialog that is visible. Why are you doing that ? The call above that is showing the messagebox.
if(MessageBox::Show("Caption", "Message", MessageBoxButtons::YesNo, MessageBoxIcon::Question)==System::Windows::Forms::DialogResult::Yes)
{
// etc
will work just fine
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
thank you very much this time it works
|
|
|
|
|
Why cant we have a static or global managed string array?
Any particualar reasons for it??
What if we need one?
Any way to get around this problem??
Som
|
|
|
|
|
Som.Paul wrote: Any particualar reasons for it??
No. They just did it so that one day when you came along you would get stumped. They are mean that way.
led mike
|
|
|
|
|
Som.Paul wrote: Why cant we have a static or global managed string array?
The GC is unable to manage any managed objects outside of managed code.
Som.Paul wrote: Any way to get around this problem?
You could use GCHandle to hold a handle in unmanaged code:
#include <vcclr.h>
...
gcroot<array<String^>^> GlobalStringArray = gcnew array<String^>(20);
Better yet, don't use globals. Wrap your "global" scoped variables in a class - create one object of this
class in the app's initialization. Store it wherever it's appropriate (scope-wise).
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: The GC is unable to manage any managed objects outside of managed code.
So how does one manage to enable the GC to manage managed objects outside of managed code? Also how does one manage to read this stuff without getting dizzy and falling over onto ones managed code?
led mike
|
|
|
|