|
I'm using reflection API's to find the argument types of a methods (such as
in or out etc). For example, consider this method in a class written in C#
public int outerFoo(string strIn, ref double dbRef, out double dbOut) { return 42; }
When using reflection in C++/CLI, I would like to know if an argument is of in or out type. In this case, I should see strIn as in, dbRef as
ref (or in and out type) and dbOut as out type. I got the code written like this
for each ( ParameterInfo^ pi in (((MethodInfo^) methInfo)->GetParameters()))
{
if(pi->IsIn)
..do something
else if(pi->IsOut)
..do something else
}
But IsIn and IsOut always return false. Are these deprecated? Any workarounds?
Any help would be appreciated
Thanks
Fiz
|
|
|
|
|
First of all, this post is also on msdn - but Im not getting any help I hope some of you can help me...
Hi!
I have a small webserver on a pda, which upon request can return some data. The problem is, that after the data to transmit has been buffered, and the socket is called with the shutdown and close command, the socket connection is terminated before all data has been transmitted.
If I add a delay before the shutdown is called on the socket, all data is send correctly. What am I doing wrong?
If I add a delay before the close methode, but after the shutdown methode, the transmission is also stopped before all data has been send.
It seems very wired, since the LingerOption of the socket is enabled...
Really hope someone can tell me what is going on...
Best regards
Martin Jørgensen
Here is the code (I have removed a lot of unnecessay code...):
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Net;
using System.Net.Sockets;
namespace DeviceApplication2
{
class RegulationStatusService
{
private const int PORT = 13000;
private static RegulationStatusService s_Instance = null;
private Thread m_Thread;
private TcpListener m_TCPServer;
private string m_HTTPVersion;
private bool m_IsRunning = false;
public static RegulationStatusService Instance
{
get
{
if (s_Instance == null)
{
s_Instance = new RegulationStatusService();
}
return s_Instance;
}
}
public void Start()
{
if (!m_IsRunning)
{
try
{
IPAddress ipAddr = IPAddress.Any;
m_TCPServer = new TcpListener(ipAddr, PORT);
m_TCPServer.Start();
m_Thread = new Thread(new ThreadStart(Runner));
m_Thread.IsBackground = true;
m_Thread.Start();
m_IsRunning = true;
}
catch { }
}
}
public bool Running
{
get
{
return m_IsRunning;
}
}
private void Runner()
{
while (Running)
{
Socket socket = m_TCPServer.AcceptSocket();
if (!socket.Connected)
continue;
try
{
LingerOption lo = new LingerOption(true, 0);
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, lo);
IList<byte> buffer = new List<byte>(100);
using (NetworkStream stream = new NetworkStream(socket))
{
int b;
while ((b = stream.ReadByte()) != -1 && (b != '\r'))
buffer.Add(Convert.ToByte(b));
}
byte[] ba = new byte[buffer.Count];
buffer.CopyTo(ba, 0);
string httpRequest = Encoding.ASCII.GetString(ba, 0, ba.Length).ToUpper();
bool validRequest = false;
string instruction = string.Empty;
try
{
// Retrieve the HTTP text and version (e.g. "HTTP/1.1")
m_HTTPVersion = httpRequest.Substring(httpRequest.IndexOf("HTTP"), 8);
instruction = httpRequest.Substring(5, (httpRequest.IndexOf(" HTTP") - 5));
validRequest = (httpRequest.Substring(0, 3) == "GET");
}
catch { }
if (validRequest)
{
if (instruction.IndexOf("GETALLROOMS") != -1)
{
byte[] contentData = Encoding.UTF8.GetBytes("Hello World!");
int contentLength = contentData.Length;
string now = DateTime.Now.ToLongDateString();
StringBuilder txbuffer = new StringBuilder();
txbuffer.Append(m_HTTPVersion).Append(" 200 OK\r\n");
txbuffer.Append("Server:This Computer\r\n");
txbuffer.Append("Content-Type:text/xml\r\n"); // Mime type is always text/xml
txbuffer.Append("Last-Modified:").Append(now).Append("\r\n");
txbuffer.Append("Accept-Ranges:bytes\r\n");
txbuffer.Append("Connection:close\r\n");
txbuffer.Append("Content-Length:").Append(contentLength).Append("\r\n");
txbuffer.Append("\r\n");
String s = txbuffer.ToString();
byte[] headerData = Encoding.UTF8.GetBytes(s);
try
{
if (socket.Connected)
{
int bytesSend;
bytesSend = 0;
while (bytesSend < headerData.Length)
bytesSend += socket.Send(headerData, bytesSend, headerData.Length - bytesSend, SocketFlags.None);
bytesSend = 0;
while (bytesSend < contentData.Length)
bytesSend += socket.Send(contentData, bytesSend, contentData.Length - bytesSend, SocketFlags.None);
}
else
{
}
}
catch { }
}
}
}
catch { }
finally
{
try
{
//Thread.Sleep(5000);
socket.Shutdown(SocketShutdown.Both);
//Thread.Sleep(5000);
socket.Close();
}
catch { }
}
socket = null;
}
}
}
}
|
|
|
|
|
Not sure why that is happening. Is there a reason why you are sending data byte by byte? If you use a stream (for example, StreamWriter) then you can call the Flush method on it. Here is an example:
void Send()
{
NetworkStream ns = new NetworkStream(aSocket);
StreamWriter w = new StreamWriter(ns);
w.WriteLine(aString);
w.Flush();
}
When you write to the stream, the stream is sent over the network.
Let me know if further needed.
|
|
|
|
|
Hi CodingYoshi.
Just to make sure I have mentioned it, the program runs on the compact framework V2..
The streamwriter does not solve the problem. I have made this small console app, which does not use the sockets directly. It still closes the connection before all data is send, if I dont add a delay. To add a delay is not good enough for me...
The small program accepts a connection from e.g. iexplorer via standard http port 80. It replies any request... so just type ( http://ip/ ). The program replies with xml: Hello world!
In this exaple no socket communication is made directly...
Im I doing something really wrong? Really hope someone can help me!
Here is the code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Net;
using System.Net.Sockets;
using System.IO;
namespace TestNetworkConsoleApp
{
class Program
{
static void Main(string[] args)
{
TcpListener m_TCPServer;
try
{
m_TCPServer = new TcpListener(IPAddress.Any, 80);
m_TCPServer.Start();
TcpClient tcpClient = m_TCPServer.AcceptTcpClient();
tcpClient.LingerState = new LingerOption(true, 100);
if (tcpClient != null)
{
try
{
string content = Hello World!";
string now = DateTime.Now.ToLongDateString();
StringBuilder txbuffer = new StringBuilder();
txbuffer.Append("HTTP/1.1").Append(" 200 OK\r\n");
txbuffer.Append("Server:This Computer\r\n");
txbuffer.Append("Content-Type:text/xml\r\n"); // Mime type is always text/xml
txbuffer.Append("Last-Modified:").Append(now).Append("\r\n");
txbuffer.Append("Accept-Ranges:bytes\r\n");
txbuffer.Append("Connection:close\r\n");
txbuffer.Append("Content-Length:").Append(content.Length).Append("\r\n");
txbuffer.Append("\r\n");
txbuffer.Append(content);
String s = txbuffer.ToString();
try
{
using (NetworkStream stream = tcpClient.GetStream())
{
StreamWriter w = new StreamWriter(stream);
w.Write(s);
w.Flush();
//Thread.Sleep(2000);
}
}
catch
{
}
}
catch
{
}
}
}
catch { }
}
}
}
|
|
|
|
|
When I go to the design window and drag some control say label in that, I can't be able to see that.
When I switch to Source control, I can the tag like
"?xml namespace="" prefix="asp" ?"
<asp:label id="Label1" runat="server" text="Label">ABCD"
Also in properties window I can't see the control's property,
Can anybody have any idea?
How can I get the controls visible and see the properties?
Thanks in advance,
|
|
|
|
|
I'm looking for a way to get the proper path name, for example if I have:
"c:\\program files"
I would expect "C:\\Program Files".
Any ideas?
I'm using the code below now, but the use of GetFileSystemInfos is going to be a performance problem some time...
<br />
private string fixPathName(string path) {<br />
string[] pathParts = path.Split(Path.DirectorySeparatorChar);<br />
<br />
string fixedPath = null;<br />
for (int index = 0; index < pathParts.Length; index++) {<br />
string pathPart = pathParts[index];<br />
<br />
if (index == 0) {<br />
fixedPath = pathPart;<br />
fixedPath = Path.GetFullPath(fixedPath);<br />
} else {<br />
fixedPath = Path.Combine(fixedPath, pathPart);<br />
DirectoryInfo parent = Directory.GetParent(fixedPath);<br />
FileSystemInfo[] paths = parent.GetFileSystemInfos(Path.GetFileName(fixedPath));<br />
string pathProperName = paths[0].FullName;<br />
fixedPath = pathProperName;<br />
}<br />
}<br />
return fixedPath;<br />
}<br />
www.wickedorange.com
www.andrewvos.com
|
|
|
|
|
There is no "proper name", since path specifications are not case sensitive.
So, it begs the question, why would you care about the case of the characters??
|
|
|
|
|
Well, so it looks right to the user.
I'm working on a bit of autocomplete code (like the Run dialog).
I do know about ComboBox/TextBox autocomplete, but it doesn't meet the specs.
www.wickedorange.com
www.andrewvos.com
|
|
|
|
|
AndrewVos wrote: else {
fixedPath = Path.Combine(fixedPath, pathPart);
DirectoryInfo parent = Directory.GetParent(fixedPath);
FileSystemInfo[] paths = parent.GetFileSystemInfos(Path.GetFileName(fixedPath));
If I read this correctly, you can replace all this sutff with this:
FileInfo fileObject = new FileInfo(fixedPath);
fixedPath = fileObject.FullName;
|
|
|
|
|
<br />
string fixedPath = @"c:\program files\";<br />
FileInfo fileObject = new FileInfo(fixedPath);<br />
fixedPath = fileObject.FullName;<br />
MessageBox.Show(fixedPath);<br />
This would return "c:\program files".
www.wickedorange.com
www.andrewvos.com
|
|
|
|
|
Ok, I've got everything working.
It seems GetDirectories is actually fast enough when using a search pattern.
Thanks for reading through the code, and here's what I'm using now.
<br />
public List<string> Generate(string generationString) {<br />
List<string> results = new List<string>();<br />
<br />
string[] pathParts = generationString.Split(Path.DirectorySeparatorChar);<br />
DirectoryInfo currentDirectory = null;<br />
<br />
for (int index = 0; index < pathParts.Length;index++ ) {<br />
string pathPart = pathParts[index];<br />
<br />
if (index == 0) {<br />
DriveInfo[] drives = DriveInfo.GetDrives();<br />
foreach (DriveInfo drive in drives) {<br />
if (drive.Name.StartsWith(pathPart, StringComparison.InvariantCultureIgnoreCase)) {<br />
currentDirectory = drive.RootDirectory;<br />
}<br />
}<br />
if (currentDirectory == null) {<br />
break;<br />
}<br />
} else if ((index == pathParts.Length - 1) ) {<br />
try {<br />
results.AddRange(Directory.GetDirectories(currentDirectory.FullName, pathPart + "*"));<br />
results.AddRange(Directory.GetFiles(currentDirectory.FullName, pathPart + "*"));<br />
} catch { }<br />
} else {<br />
DirectoryInfo[] searchResults = currentDirectory.GetDirectories(pathPart);<br />
if (searchResults.Length == 0) {<br />
break;<br />
} else {<br />
currentDirectory = searchResults[0];<br />
}<br />
}<br />
}<br />
<br />
return results;<br />
}<br />
</string></string></string>
www.wickedorange.com
www.andrewvos.com
|
|
|
|
|
I have the following event handlers for a button and a text box:
private: System::Void button_Click(System::Object^ sender, System::EventArgs^ e)
{ function(0);
}
private: System::Void textBox_Validating(System::Object^ sender, System::ComponentModel::CancelEventArgs^ e)
{ if(!CheckIfTextBoxNumeric(textBox))
e->Cancel = true;
}
bool CheckIfTextBoxNumeric(TextBox^ myTextBox1)
{ //checks text input only contains numbers
//returns true if so
}
void function(int select)
{ int result = 0;
//validate text is digit
try
{ result = Convert::ToInt32(insrtMnytxtBox->Text); -- line A
}
catch(Exception^ myException)
{ cstmrInfolabel->Text = "Exception : ",myException->Message;
}
//rest of code
}
When program execution reaches line A in function, program does not pause for text input from user, that is, program does not allow user the chance to enter numbers. In C++ it would be the equivalent of cin >> result; How can I cause the program to pause so that the user has a chance to enter something.
|
|
|
|
|
This question belongs in the Visual C++/CLI forum.
I'm guessing you haven't written code for Windows before, have you? What you mentioned with the cin stream applies to console applications, not Windows.
Windows is follows an event driven model where your code normallly sits idle, waiting for the user to click on things and type. You caannot do what you want, the way you want. The best method for filtering out keystrokes is to create a custom TextBox control that does just that. Another method would be to handle the TextBox's Keydown event and do your filtering in that handler.
|
|
|
|
|
If I use the SetWindowLong in VB, I get the positive return value. Now we are migrating to vb.net and if I tried using SetWindowLong in vb.net, I get negative value. The third parameter in SetWindowLong is dwNewLong, am using delegate here to point to the address of the function I wanted to point to. (for example - AddressOf MyFunction)
I tried using different function definition but no success.
I used following -
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hWnd As Integer, _
ByVal nIndex As Integer, _
ByVal dwNewLong As MyFunction) As Integer
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hWnd As IntPtr, _
ByVal nIndex As Integer, _
ByVal dwNewLong As MyFunction) As Integer
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hWnd As Int64, _
ByVal nIndex As Int64, _
ByVal dwNewLong As MyFunction) As Int64
Can anyone help me with this?
|
|
|
|
|
This should have been asked in the VB/VB.NET Forum.
Read the Community Content Section at the bottom of this page[^] for information on how to do this.
|
|
|
|
|
Thanks for that. I tried using those function but getting two errors -
Messages.WndProc - Type is not defined
Messages.WindowMessages - Type is not defined
|
|
|
|
|
You have to define those enums yourself. They just represent the message numbers found in the Windows header (*.h) files. You can find an example of some of the window message numbers here[^]. Messages.WndProc is the delegate that's listed in the code.
|
|
|
|
|
Am sorry to trouble you again. I'm confused. I might not getting what you are saying. I am not a much experienced developer. I'm using VB.Net with .Net Framework 1.1. Please see below what have tried -
Public Enum WindowMessage As Integer
WM_ACTIVATE = 6 ' can't use Hex value WM_ACTIVATE = 0x0006 giving error 'End of statement expected so converted that hex value to decimal as 6.
End Enum
Public Delegate Function WndProc(ByVal hWnd As Integer, ByVal msg As Messages.WindowMessages, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Error - Messages.WindowMessages - Type is not defined
Friend Declare Auto Function SetWindowLong Lib "user32.dll" (ByVal hwnd As Int32, ByVal nIndex As WindowProcs, ByVal NewProc As Messages.WndProc) As Boolean
Error - Messages.WndProc - Type is not defined
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hWnd As Integer, _
ByVal nIndex As Integer, _
ByVal dwNewLong As MyFunctionDelegate) As Integer
My hook function looks like this -
Public Sub Hook()
Try
Dim intError As Integer = GetLastError
MsgBox(intError)
SetLastError(1)
Dim intError1 As Integer = GetLastError
lpPrevWndProc = SetWindowLong(ghW, GWL_WNDPROC, AddressOf MyFunction)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Note - Getting Last Error as 126 which means 'Module not found.'
MyFunction Delegate is like this -
Public Delegate Function MyFunctionDelegate(ByVal hw As Integer, ByVal uMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
MyFunction looks like this -
Public Function MyFunction(ByVal hw As Integer, _
ByVal uMsg As Integer, _
ByVal wParam As Integer, _
ByVal lParam As Integer) As Integer
Select Case uMsg.ToString
Case ABC
do this
Case DEF
do this
Case Else
MyFunction= CallWindowProc(lpPrevWndProc, hw, uMsg, wParam, lParam)
End Select
End Function
Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _
(ByVal lpPrevWndFunc As Integer, _
ByVal hWnd As Integer, _
ByVal Msg As Integer, _
ByVal wParm As Integer, _
ByVal lParam As Integer) As Integer
|
|
|
|
|
bhawaniprasad wrote: Public Enum WindowMessage As Integer
WM_ACTIVATE = 6 ' can't use Hex value WM_ACTIVATE = 0x0006 giving error 'End of statement expected so converted that hex value to decimal as 6.
End Enum
This is because you have to use VB's syntax to specify a Hex value:
WM_ACTIVATE = &H6
bhawaniprasad wrote: I am not a much experienced developer.
You've taken on something that is a very advanced technique for a beginner.
bhawaniprasad wrote: Messages.WindowMessages - Type is not defined
This means that YOU have to define the enumeration called WindowMessages. You can drop the Messages. part. The values come from the Windows.h C++ header files that describe each window message.
bhawaniprasad wrote: Messages.WndProc - Type is not defined
Again, drop the Messages. part. You have to leave the WndProc part.
|
|
|
|
|
what event happens immediately fater user changes the collection selection.
I want to get access to the selected item collection before it is actually changed so I can either rollback or acces the previous selected collection indexes.
thanks
Shimi
|
|
|
|
|
meanwhile I am using CellMouseEnter
this does the work though it reduces performance
Shimi
|
|
|
|
|
|
|
He actually put it in three forums and then deleted them all. Pathetic.
|
|
|
|
|
leckey wrote: He actually put it in three forums and then deleted them all. Pathetic.
Another entry for the blog of shame.
|
|
|
|
|