|
GCHandle hnd = GCHandle.Alloc(object);
InPtr ptr = hnd.AddrOfPinnedObject();
But seriously what are you going to do with it ?
|
|
|
|
|
If you are trying to read the contents of a specific address without knowing what type of data is held there, then one way of doing it is to call:
Marshal.PtrToStringAnsi(ptr, length)
where 'ptr' represents the address of the first byte and 'length' the number of bytes to be read.
This returns the data in the form of a managed string (with each byte expanded to a 2-byte unicode character), which you can then examine
Naveen
|
|
|
|
|
i need help in dot net relating to mobile computing ..
i need to connect my server from mobile using c# and perform some functions on server from mobile..
where I can get resourses and what i need to study ........ urgent help ..
do best whereever you are...
|
|
|
|
|
Hi,
I put a DataGrid in form and I can browse the fields of a query. Now I want to show some string contents istead of numeric values of a field.
For example I have a field Enabled with (0/1) values and I want to show Enabled/Disabled instead of 0/1 numbers.
How can I do it?
Mehdi
|
|
|
|
|
I'm working on application, that will recive multiple Excel files
and displaing it in a DataGrid.
The problem is, that when I select 2 or 3 files from OpenDialog, it
displays only the data from the first selected file, the other values
in DataGrid are null values. Why is that? And how can I solve this, that
the DataGrid will display all values. Thank you.
Here is the code:
private void btnOpen_Click(object sender, System.EventArgs e)
{
try
{
Stream myStream;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "E:\\" ;
openFileDialog1.Filter = "txt files (*.txt)|*.txt|Allfiles(*.*)|*.*" ;
openFileDialog1.FilterIndex = 2 ;
openFileDialog1.RestoreDirectory = true ;
openFileDialog1.Multiselect = true;
if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
if((myStream = openFileDialog1.OpenFile())!= null)
{
DataSet ds = new DataSet();
foreach (string strFileName in openFileDialog1.FileNames)
{
string connStr =
@"Driver={Microsoft Excel Driver (*.xls)};DBQ=" + strFileName;
string sql = "SELECT * FROM [Sheet1$]";
OdbcDataAdapter adapter = new OdbcDataAdapter(sql,connStr);
adapter.Fill(ds,"[Sheet1$]");
}
gridPorocila.DataMember = "[Sheet1$]";
gridPorocila.DataSource = ds.DefaultViewManager;
myStream.Close();
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
|
|
|
|
|
how do you turn a 'Text' into a number variable since I wanted to get some input through textboxes and do mathamatical operations on them, and what is the namespace for mathamatical operations by the ways?
|
|
|
|
|
Sry I forgot to mention Im using VS.NET 2005 beta 1 with the .net framework v2.0 so if anyone has this problem email me..
|
|
|
|
|
Sry again, I figured it out but now I have another (?) how would you convert a string into an integer or double or whatever??
|
|
|
|
|
By using the Convert[^] class.
Paul Lyons, CCPL Certified Code Project Lurker
|
|
|
|
|
Thx but now I don't have any errors exept
Error 3 Cannot implicitly convert type 'uint' to 'string'
|
|
|
|
|
This is something like what I have.
UInt32 A = 0;<br />
UInt32 O = 0;<br />
A = Convert.ToUInt32(tbA.Text);<br />
O = Convert.ToUInt32(tbO.Text);<br />
tbResults.Text = A/O;<br />
tbResults.Text = Math.Pow(A, 2)/Math.Sqrt(O);
Error 3 Cannot implicitly convert type 'uint' to 'string'
|
|
|
|
|
just use a cast...
UInt32 A = 0;<br />
UInt32 O = 0;<br />
A = Convert.ToUInt32(tbA.Text);<br />
O = Convert.ToUInt32(tbO.Text);<br />
tbResults.Text = (string)(A/O);<br />
tbResults.Text = (string)(Math.Pow(A, 2)/Math.Sqrt(O));
if these inputs are coming from a textbox, which it looks like they are, you should consider putting a try/catch block around those Convert statements to make sure the input is valid:
UInt32 A = 0;<br />
UInt32 O = 0;<br />
try<br />
{<br />
A = Convert.ToUInt32(tbA.Text);<br />
}<br />
catch<br />
{<br />
tbA.Text = "0";<br />
A = 0;<br />
}<br />
try<br />
{<br />
O = Convert.ToUInt32(tbO.Text);<br />
}<br />
catch<br />
{<br />
tbO.Text = "0";<br />
O = 0;<br />
}<br />
tbResults.Text = A/O;<br />
tbResults.Text = Math.Pow(A, 2)/Math.Sqrt(O);
I have always used Parse, such as UInt32.Parse(string); instead of Convert, so I'm not sure if it will handle incorrect strings or not, but this is good just to make sure. Obviously you don't have to use 0 to assign to A and O in the try/catch blocks, you can make them whatever you want. Good luck!
|
|
|
|
|
DougW48 wrote:
have always used Parse, such as UInt32.Parse(string); instead of Convert,
Convert is safer than parse IIRC, in the sense that it wont throw an exception. Could be wrong
top secret xacc-ide 0.0.1
|
|
|
|
|
You're probably right, I've never used Convert. Thanks!
|
|
|
|
|
Error 1 Cannot implicitly convert type 'uint' to 'string'
It still says that even if I had it like DougW48's example... I don't know can this be a bug since I'm testing out Visual Studio 8 2005 beta 1
|
|
|
|
|
NVM I got it, anyways Thx for the quick help I got at codeproject, will be visiting this site more often;P
|
|
|
|
|
Hello,
i am developing a web service in c# and i have the following problem. The requests and the responses are signed with CAPICOM.SignedData, when the server receives the request and verify the signature, he builds a response which is serialized and signed before going to the client. When the client receives the response, the signature is correctly verified, but when the data are going to be deserialized comes the exception InvalidaCastException (when i try to cast the object returned bu the formatter to the data type defined in a separated class).
Thank you in advance for your help!
|
|
|
|
|
Just an idea. You probably checked this already.
Make sure that both your webservice and your client reference the same library (data type that is serialized). Make sure that you have identical version of the libary on both the client and webservice.
|
|
|
|
|
Could we see some code? probably the entire function that includes the part where InvalidCastException occurs?
|
|
|
|
|
Hi
How can I replace the Task Managar with another Task Manager.
I mean, when I press Ctrl+Alt+Delete my Task Manager opens.
Thanks
Mohammad-Reza Taikandi(HM)
|
|
|
|
|
Ctrl+Alt+Delete is a special key combination that cannot be intercepted (at least on NT). On windows 9x branch it might be possible but i haven't checked.
I strongly recomend against replacing anything that is considered standard windows UI, unless you are trying to do something that is specifically designed to modify the entire user experience.
|
|
|
|
|
Hi
I try to execute an *.exe file that i renamed it to *.sec unfortunately
Process.start() method can't execute it.
Is there any other way to do this?
Thanks
Mohammad-Reza Taikandi(HM)
|
|
|
|
|
Of course *.sec is not going to execute. Its not a executable extension.
Another way to do this would be to rename the filename part instead of the extension. ie Myprogram.exe to abcdef.exe or myprogram.sec.exe
|
|
|
|
|
Hi I have a text file with the following layout:
[PROFILE1]
SYSTEM=home
DEBUG=true
[PROFILE2]
SYSTEM=laptop
DEBUG=true
What I want to do is insert a new line after the FIRST DEBUG LINE in PROFILE1 so the whole of PROFILE2 then moves down a line. My problem is that I keep overwriting the start of PROFILE2 e.g
[PROFILE1]
SYSTEM=home
DEBUG=true
testline
2]
SYSTEM=laptop
DEBUG=true
Can you take a look at my code and see what I am doing wrong!!
if( File.Exists( "d:\\networld.ini" ) )
{
long lFilePos = 0;
string sLine = null;
FileStream fs = new FileStream("d:\\networld.ini",
FileMode.Open, FileAccess.ReadWrite);
// Create a new streams to read and write to the file
StreamReader sr = new StreamReader( fs );
StreamWriter sw = new StreamWriter( fs );
while( sr.Peek() > -1 )
{
sLine = sr.ReadLine();
if( sLine.CompareTo( "[" + "PROFILE1" + "]" ) == 0 )
{
lFilePos = sLine.Length;
while( sr.Peek() > -1 )
{
sLine = sr.ReadLine();
lFilePos += sLine.Length + 2;
if( sLine.CompareTo( "" ) == 0 )
{
fs.Seek( lFilePos,SeekOrigin.Begin );
sw.Write( "testline\r\n" );
sw.Flush();
break;
}
}
}
}
sr.Close();
fs.Close();
MessageBox.Show( "Finished Writing To File." );
}
Thanks a million.
|
|
|
|
|
Why would not you consider the old fashion way read the old file and create
simultaneously a new file -> copy each line while they are identical, then insert the change and so on. When you finish you can delete the old file and rename the new file to the old name. You can use File class. I think it will save you much trouble
DavidR
|
|
|
|