|
Hi all,
What is the best way to convert C style structures to C#.
I have converted the following C structure
typedef struct {
ISC_DATE timestamp_date;
ISC_TIME timestamp_time;
} ISC_TIMESTAMP;
to
public struct ISC_TIMESTAMP
{
long TIMESTAMP_DATE;
ulong TIMESTAMP_TIME;
};
Is this correct or should I be using another more C# style like..
[StructLayout(LayoutKind.Sequential)]
public class ISC_TIMESTAMP
{
// rest of code goes here
}
How about this more complicated C structure...
typedef struct blobcallback {
short (ISC_FAR *blob_get_segment)
(void ISC_FAR* hnd, unsigned char* buffer, ISC_USHORT buf_size, ISC_USHORT* result_len);
void ISC_FAR *blob_handle;
ISC_LONG blob_number_segments;
ISC_LONG blob_max_segment;
ISC_LONG blob_total_length;
void (ISC_FAR *blob_put_segment)
(void ISC_FAR* hnd, unsigned char* buffer, ISC_USHORT buf_size);
ISC_LONG (ISC_FAR *blob_lseek)
(void ISC_FAR* hnd, ISC_USHORT mode, ISC_LONG offset);
} ISC_FAR *BLOBCALLBACK;
What is the best way to handle this type of conversion.
Sincerely,
Dominique.
|
|
|
|
|
Dominique wrote:
public struct ISC_TIMESTAMP
{
long TIMESTAMP_DATE;
ulong TIMESTAMP_TIME;
};
Is this correct or should I be using another more C# style like..
[StructLayout(LayoutKind.Sequential)]
public class ISC_TIMESTAMP
{
}
You need to use a combination of the two, keep it a struct but apply the StructLayout attribute its your only guarantee that the data will stay in that order; otherwise the compiler could move fields around to better align the data.
Dominique wrote:
struct blobcallback {
short (ISC_FAR *blob_get_segment)
(void ISC_FAR* hnd, unsigned char* buffer, ISC_USHORT buf_size, ISC_USHORT* result_len);
void ISC_FAR *blob_handle;
ISC_LONG blob_number_segments;
ISC_LONG blob_max_segment;
ISC_LONG blob_total_length;
void (ISC_FAR *blob_put_segment)
(void ISC_FAR* hnd, unsigned char* buffer, ISC_USHORT buf_size);
ISC_LONG (ISC_FAR *blob_lseek)
(void ISC_FAR* hnd, ISC_USHORT mode, ISC_LONG offset);
}
Call backs are done with delegates, there is an article somewhere on CP that shows how to use a callback for the EnumWindows function, i think it was how to programmatcally control IE.
void is usually a object
When you have a character buffer pass in a StringBuilder object
A ** (pointer to a pointer) usually uses the 'out' keyword followed by its type, a pointer is usually a reference ('ref').
HTH,
James
Sonork: Hasaki
"I left there in the morning
with their God tucked underneath my arm
their half-assed smiles and the book of rules.
So I asked this God a question
and by way of firm reply,
He said - I'm not the kind you have to wind up on Sundays."
"Wind Up" from Aqualung, Jethro Tull 1971
|
|
|
|
|
Hello!
I'm a computer science student and want to start coding with Visual Studio .Net in C#. As I want to use my Apps commercially, the Student-licence doesn't seem to be usefull for me. On the other hand I doesn't have the money to buy the professional version of .NET. And I don't nedd any Server things or other languages than C#. So The Visual C# .NET Standard edition seems to be the right thing for me. So I looked at the comparison-table at http://msdn.microsoft.com/vcsharp/howtobuy/choosing.asp and there it says, that NOT supported are:
-Class Libraries
Create reusable class library components using the Class Library template
Does that mean, I cannot program class libraries?!? Or is only the template missing?
-Windows Control Libraries
Construct custom user interface controls for Windows Forms using the Windows Control Library template.
The same question: Does that mean, I cannot program custom control libraries, or is only the template missing?
If you have any serious warnings NOT to buy this edition, please let me know.
Mario
|
|
|
|
|
Mario, I bought the standard version as well and ran into the same issues you have. There are quiet a few templates that are missing. However, after doing some searches, MS has claimed that they inadvertently left of some of the templates in the standard edition and will be providing an update (Not sure which templates they are referring to). With that said some people have found ways to add various templates back in. Here is a link for the class library template. It works great.
http://groups.google.com/groups?hl=en&lr=lang_en&ie=ISO-8859-1&oe=ISO-8859-1&th=1610d3f841479209&rnum=1
In response to your questions, you can create libraries and controls, it's just a manual process. The templates make things much easier
|
|
|
|
|
Must i write the codes to parse a email message from a pop3 server myself ?
thanks
Thanks to those people with an "opensource" heart. they make me love what I am doing.
|
|
|
|
|
SoftArtisans has created a free POP3 control that you can use.
SoftArtisans POP3 Control - Source Code is included.
It doesn't look like it has been upgraded from Beta 2 yet, but the changes should be fairly minor.
James
Sonork: Hasaki
"I left there in the morning
with their God tucked underneath my arm
their half-assed smiles and the book of rules.
So I asked this God a question
and by way of firm reply,
He said - I'm not the kind you have to wind up on Sundays."
"Wind Up" from Aqualung, Jethro Tull 1971
|
|
|
|
|
James T. Johnson wrote:
SoftArtisans has created a free POP3 control that you can use.
SoftArtisans POP3 Control - Source Code is included.
It doesn't look like it has been upgraded from Beta 2 yet, but the changes should be fairly minor
Thanks James
regards,
Paul Watson
Bluegrass
Cape Town, South Africa
The greatest thing you'll ever learn is just to love, and to be loved in return - Moulin Rouge
Brian Delahunty wrote:
one of my boys on the inside instead of the outside
benjymous wrote:
All the male CP inhabitants cross their legs in unison
|
|
|
|
|
I wanna expand the ability of some class provided by framework like Bitmap, but I find it modified by sealed.
How can i do with it?
Another similar problem is when i try to inherit XmlElement, I find its construction is modified by internal. Then the compiler find it as an error. any solution to bypass?
|
|
|
|
|
I had the same problem with SqlDataReader. I just created a new class that wrapped each SqlDataReader method and property and then inherited from my class. It kind of sucks but I don't think there is any other way.
|
|
|
|
|
Well, the wrapper is boring but i fininally made it.
I think if Microsoft holds its position on sealing their class, then it will be a good idea to design a wizard to automatively build a wrapper. Hope C#'s reflection ability will make it possible.
Do you think so?
|
|
|
|
|
Yes it stinks. The reason for Bitmap being sealed is because it is a wrapper around GDI+ which is a native DLL. .NET doesn't support inheritence from a native image, yet anyway
James
Sonork: Hasaki
"I left there in the morning
with their God tucked underneath my arm
their half-assed smiles and the book of rules.
So I asked this God a question
and by way of firm reply,
He said - I'm not the kind you have to wind up on Sundays."
"Wind Up" from Aqualung, Jethro Tull 1971
|
|
|
|
|
I can't speak for them all...
but some are sealed for performance reasons.
and I quote from "Applied Microsoft .NET Framework Programming":
" the CLR knows the exact layout of the fields defined within the String type, and the CLR accesses these feilds directly." ... If String were not sealed, "you could add your own fields, which would break the assumptions the CLR makes, In addition, you could break some assumptions that the CLR has made about String objects being immutable."
|
|
|
|
|
Andy Smith wrote:
and I quote from "Applied Microsoft .NET Framework Programming":
" the CLR knows the exact layout
Here is Mircosoft "knowing" everything again...
Nick Parker
|
|
|
|
|
How can I draw a bitmap button with a transparent background.
Im using the code below to try and do this but its not working how it should.
Bitmap b = new Bitmap("D:\\-=[Pics]=-\\test.jpg");
b.MakeTransparent(b.GetPixel(0,0));
pe.Graphics.FillRectangle (Brushes.Transparent,ClientRectangle);
pe.Graphics.DrawImage(b,ClientRectangle);
Im trying to paint the button transparent then draw an image whose transparency key is the same as the color at 0,0 of the bitmap. It sort of works but when the image is drawn on the button the background looks more like swiss cheese than transparent.
Any help would be great.
Thanks Danny
|
|
|
|
|
Try opening the JPEG in an image viewer, I bet your background color got mangled during the compression of the file resulting in a slightly different color in spots (but nothing the human eye would notice).
If possible you should stick to lossless image formats such as: BMP, GIF, PNG
HTH,
James
Sonork: Hasaki
"I left there in the morning
with their God tucked underneath my arm
their half-assed smiles and the book of rules.
So I asked this God a question
and by way of firm reply,
He said - I'm not the kind you have to wind up on Sundays."
"Wind Up" from Aqualung, Jethro Tull 1971
|
|
|
|
|
What could be done in C# which would add much in language expressiveness
without any penalties to security and efficiency.
Before implement any language feature I think designers discussed them many
times and surely they analyzed any similar implementation in all the languages
(not only C,C++, but Java, FoxPro, Pascal, ADA, etc). So C# is not just a
revamped dialect version of C++ + garbage collection (such attempts to create
garbage collection feature to C++ have been made many times), that's why my
question is purely ritoric: why they didn't do that? What is that ... read
below.
In language description we read that in order to go out of innermost
cycle we should use goto operator. Yes, of course, but wouldn't it be better to
write something like this?
for (condition_1)
{
....
while(condition_2)
{
....
break level; // level see next comment
/* level - int expression, if 0 means regular break;
1 - means one level up, in this particular case
means exit from for cycle
*/
...
continue level; // see comments above
}
...
}
I've been wondering why it hadn't been done since the first C-compilers
appeared, I worked then on PDP11. Java made it better, but still it is too
similar to goto..
Another question: Look at this snippet of code
if(codition_1)
{
....//do smth
}
else
{
if(codition_2)
{
....//do smth
}
else
{
if(codition_3)
{
....//do smth
}
else
{
}
}
}
isn't it ugly? Imagine 20 conditions analyzed, what will happen to nesting
level? Then compare to this: (borrowed from FoxPro,Clipper...)
switch
{
case (condition_1)
.... // no need of break, that has become obligatory in C# !!!
case (condition_1)
...
default:
}
By the way switch operator in old C-style definition could be used as well,
they wouldn't interfere with each other.
I don't see any reasons not to implement such useful features.
Alex .
ovarlamov@sprint.ca
|
|
|
|
|
I agree with you that C# switch statement is unneccesarily poor. It is such things that make me almost want to move to VB.Net.
VB and C# are on the same level, performance-wise, and VB has some _great_ syntax niceties such as a GOOD switch statement ( Select/Case ) and the With statement.
Although, in the long run I doubt i'll ever switch to vb.net... if only for the reason that I fully expect that a programmer who has "c#" on his resume can demand a higher pay than one with "VB.net" on it; regardless if that is an intelligent decision.
|
|
|
|
|
Hi Guys,
I need a little help.
The scenario is as follows,
I have an interface I,
Class C implements I.
C compiles to dll.
In another project
I want to Assembly.Load C
and cast it to interface I so that I can use the methods in C
Is this possible. What do I need to do? I'm very new to Assemblies!
If not what the alternatives?
Please help!
- Tariq
|
|
|
|
|
Yes its quite possible, I've written an article that does just that Using reflection to extend .NET programs.
James
Sonork: Hasaki
"I left there in the morning
with their God tucked underneath my arm
their half-assed smiles and the book of rules.
So I asked this God a question
and by way of firm reply,
He said - I'm not the kind you have to wind up on Sundays."
"Wind Up" from Aqualung, Jethro Tull 1971
|
|
|
|
|
Hi, I would like to check if there is running any instance of my application, in order to set the focus on it if the user try to start a new one.
Any idea?
Thank you.
|
|
|
|
|
Something like this:
Int32 RunningProcesses = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName ).Length;
if ( RunningProcesses >= 1 ) {
MessageBox.Show( "already running the program" );
}
--
David Wengier
Sonork ID: 100.14177 - Ch00k
|
|
|
|
|
Just wanted to say thanks for posting this, because you probably saved me hours of trying to figure this out in C#!
Thanks!
Marc
|
|
|
|
|
Hi all,
I've been trying to have a simple checkbox in my datagrid using C# and it's being a pain to get it to work.
Here is the cenario.
I have a DataSet populated with a table "Employees" let's say. This table has fields such id, name, email.
All I want to do is to display an extra column in my datagrid that will display a checkbox for each row.
Note, there is no data associated with this checkbox. I just wanted the user to select some of the Employees from the datagrid by checking the checkbox. Then, when they click the button "Print", I will loop through the datagrid, get the selected ones and print.
Anyone can give me some instructions or example of how to do that?
I've been looking some people examples that do something similar. But they don't really show how to add an extra column to the datagrid with a checkbox for each record of your already populated dataset.
Please, any help will be appreciated.
Thanks to all.
Anderson
Anderson F.
afraga22@hotmail.com
|
|
|
|
|
You can add an unbound column to your datagrid and use a bool columnstyle for that unbound column. You can download a sample showing how to add an unbound column from:
http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q787q
Clay Burch
www.syncfusion.com
|
|
|
|
|
Hello Clay,
Thanks a lot.
That's a pretty good link.
I will try it and I let you know when I get it to work.
Thanks again.
Anderson
Anderson F.
afraga22@hotmail.com
|
|
|
|