|
thx...but I solved other way, I changed the format of the DateTimePicker to custom and then I declare in the customFormat field 'dd-MM-yyyy' and it works fine. But thx for the help anyway, have a nice day
|
|
|
|
|
That controls the display, the underlying DateTime may still have other values for the time-of-day.
And please use an ISO 8601 format: yyyy-MM-dd
|
|
|
|
|
I wrote code to access structre from C# .net where structure is in C dll .here are the two files .When i build i get the error message saying that "Cannot take the address of, get the size of, or declare a pointer to a managed type ('StructureExample.Program.Detail')"
------------------------- StrcutreDisplay.dll---------------------------------
#include<iostream.h>
#include<conio.h>
#include<malloc.h>
#include<string.h>
extern "C"
{
typedef struct
{
char *fname;
char *lname;
char abc[5];
}Detail;
__declspec(dllexport) Detail * Disp()
{
Detail *ptr=(Detail *)malloc(sizeof(Detail));
ptr->fname = (char*)malloc(50);
memset(ptr->fname, 0x00, 50);
ptr->lname = (char*)malloc(50);
memset(ptr->lname, 0x00, 50);
memset(ptr->abc, 0x00, 5);
strcpy(ptr->fname, "larson");
strcpy(ptr->lname, "scolari");
strcpy(ptr->abc, "ABC");
return ptr;
}
}
----------------------------StructureExample---------------------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace StructureExample
{
class Program
{
[StructLayout(LayoutKind.Explicit)]
public struct Detail
{ // [MarshalAs(UnmanagedType.LPStr)]
public unsafe sbyte* fname;
public unsafe sbyte* lname;
public char[] arr;
}
// strucure DLL
[DllImport("StructureDisplay.dll")]
public static unsafe extern Detail * Disp();//here i get error
static void Main(string[] args)
{
unsafe
{
Detail * var = Disp();
string a = new string(var->fname);
string b = new string(var->lname);
string e = new string(var->abc);
}
Console.WriteLine("hello world");
Console.WriteLine(a);
Console.WriteLine(b);
Console.WriteLine(e);
Console.Read();
}
}
}
------------------------------------------------------------------------------------------------
How to solve this problem?can anyone help me out?
Any help appreciated.
Thanks in advance.
|
|
|
|
|
cristi_alonso wrote: [StructLayout(LayoutKind.Explicit)]
Thats wrong. It is not needed.
Also public char[] arr; will need some fixed size attribute. Look at System.Runtime.InteropServices.MarshalAsAttribute .
|
|
|
|
|
I changed my declaration of array to
[MarshalAs(UnmanagedType.LPArray, SizeConst=5)] char[] abc;
but still its giving me an error.
Any help appreciated
Thanks in advance.
|
|
|
|
|
What does sizeof(struct Detail) give you in C? Use that to figure out the layout.
|
|
|
|
|
I removed the line [StructLayout(LayoutKind.Explicit)] from my code .
Any help appreciated.
Thanks in advance.
|
|
|
|
|
cristi, i see your new here...
please get in the habit of using pre tags if your posting code blocks...
thanx
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.passion != Programming)
|
|
|
|
|
Hello everyone,
I am using the following code to read a string. The content of message is ends with a lot of \0 characters. Why and how to remove them?
(context is an instance of HttpListenerContext, and my code is read Http request from begin to end)
using (StreamReader requestStream = new StreamReader(context.Request.InputStream))
{
message = requestStream.ReadToEnd();
}
thanks in advance,
George
|
|
|
|
|
George_George wrote: message = requestStream.ReadToEnd();
Try:
message = new string(requestStream.ReadToEnd());
That should stop at the first \0.
|
|
|
|
|
Thanks leppie,
Your code is magic. What is the root cause of my original issue? And why your code can fix?
regards,
George
|
|
|
|
|
George_George wrote: Your code is magic.
George_George wrote: What is the root cause of my original issue? And why your code can fix?
It was probably in the File/Resource you were reading. But because you need to read the whole file, ReadToEnd actually does not seem to stop at \0. This is probably by design.
My code fixes it as creating a string, will make sure it is only up to the first \0. After that, the rest is never considered.
To add: It is interesting that you found this. I have never come across it, but at least I am aware of it now (thanks).
|
|
|
|
|
Thanks leppie!
Where in your code trims the string with ends \0?
regards,
George
|
|
|
|
|
\0 is the equivalent of null. Strings used to be null terminated but are not anymore (at least in .NET) however, the new String method is probably designed to stop reading on an null character in a string. I wonder, however, about the memory allocation. It is possible that the entire string is stored in memory, including the nulls but only the non-null portion is workable. (happens in C sometimes)
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
Thanks Ennis!
Does your reply answers why leppie's code trims endding \0?
regards,
George
|
|
|
|
|
George_George wrote: What is the root cause of my original issue?
I had a think about this. I suspect you are reading a binary file as a text file.
|
|
|
|
|
Thanks leppie!
I am reading from HttpListenerContext.Request.InputStream. Just send one XML file from a client, and my code read from another end.
1.
In this process, why do you think I experienced "reading a binary file as a text file", which causes \0 at the end?
2.
Do you have a scenario to reproduce this issue?
regards,
George
|
|
|
|
|
Hello
yesterday i have asked a question for a connection between a client and a server using a c# application,and that client should send a file to the server.
Someone tell me to use the tcp/ip.
But the client and the server are connected only trough internet.So does this tcp/ip run,Do someone have some other idea??
best regards
dghdfghdfghdfghdgh
|
|
|
|
|
The ip part stands for 'internet protocol'. I guess you didn't bother to look it up.
If it were me, if the web were involved, I'd have a webservice on the server, and send using that.
Christian Graus
Please read this if you don't understand the answer I've given you
"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 )
|
|
|
|
|
when i create a service on the server, how can i connect to that web service from the client.
Note : there is not a web site or an ftp. I mean by a server a pc connected to the internet only( ).
So can i instanciate that service from the client.
dghdfghdfghdfghdgh
|
|
|
|
|
If the two machines are just connected to the web and the server is not an actual server on the internet, then you probably want to go back to creating a TCP/IP connection. How does the client discover the server at all ?
Christian Graus
Please read this if you don't understand the answer I've given you
"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 )
|
|
|
|
|
I am using visual studio 2003. My application is a window application and i am using C#. I want to put double click event for each row in the datagrid.
Can anyone help me please.
|
|
|
|
|
If there isn't one, you can catch a single click, store the time it occured and on the next click see if they were close enough together to make a double click.
Christian Graus
Please read this if you don't understand the answer I've given you
"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 )
|
|
|
|
|
Hehe, so you get blamed for the lack of functionality. I sometimes wonder what goes through the minds of some characters.
|
|
|
|
|
Christian Graus wrote: you can catch a single click, store the time it occured and on the next click see if they were close enough together to make a double click.
I guess then page need to post back two times, right ? How about hooking JS double click event and raising postback manually ? I haven't tried it, but a wild guess.
BTW, don't know why you got down voted.
|
|
|
|