|
You cannot get unmanaged size of a class.
See this example :
Abc abc = new Abc();
int size = System.Runtime.InteropServices.Marshal.SizeOf(abc);
Console.WriteLine(size);
If Abc is a class, then you get an exception.
If you change Abc to a struct, then you get a size (12).
|
|
|
|
|
Yes I got an exception since Abc is a class.
So how is to calculate the size?
|
|
|
|
|
Using some memory profiling tools. BTW, could you tell why you are worried with the size?
|
|
|
|
|
stancrm wrote: You cannot get unmanaged size of a class.
You can if you specify the class' layout (explicit or sequential).
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
hi
you can use the Marshal.SizeOf(typeof(MyClass)) method in the
System.Runtime.InteropServices namespace.
regards
|
|
|
|
|
When I given as per your suggestion I got an exception as follows.
An unhandled exception of type 'System.ArgumentException' occurred in exe
Additional information: Type 'class' cannot be marshaled as an unmanaged structure; no meaningful size or offset can be computed.
|
|
|
|
|
San wrote: no meaningful size or offset can be computed.
I think you now have the answer to your question.
|
|
|
|
|
San wrote: I need to get the size of the class.
Why?
IIRC, a class like that would use 20 bytes on a 32 bit system and 28 bytes on a 64 bit system. Each object consists of two pointers plus the instance data.
As you see, the size differs depending on the version of the CLR (which determines the memory layout). Also, you have a pretty simple example. If you have members of different data types, they may be aligned on an even word boundary which may add to the size, and they might get rearranged to make best use of memory when aligned. So, it might not be possible to predict exactly how large the object can be.
Despite everything, the person most likely to be fooling you next is yourself.
modified on Monday, September 8, 2008 9:31 AM
|
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
public class Abc
{
private UInt32 x;
private UInt32 y;
private Int32 z;
};
int size = Marshal.SizeOf(typeof(Abc));
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
HI!! i've a problem: i have a listview, and i wont that when i click in a line, the program should show me the printpreview of that object. in the listview there are only the file path to the file(ex: C:\filename.doc) ...how can i do??
sorry for my english, i'm not very good...(i'm italian)
thank you!!
|
|
|
|
|
If I understand correctly, your listview contains a list of documents. If they are all word documents, you will possibly need to use the Office Interop and open up the documents using Word (don't use Process.Start to open the docs). Then, your application will call the Print Preview command.
|
|
|
|
|
how can i use the Office Interop??
for exemple:
private void listView1_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
{
//what can I write here?
}
|
|
|
|
|
You'd have to import the Word automation library through the COM portion of the Add References dialog. Once that's in place, you've got the Word Interop library. If you have a google for word interop, there should be plenty of examples of the exact code you'll need for your application.
|
|
|
|
|
|
You're welcome. Glad to help.
|
|
|
|
|
Hi all,
I have a very long form, so I need to use vertical scrollbar to see all parts of it.
I need to capture the image of WHOLE form, but using standard CopyFromScreen method only captures the displayed area, while the scrolled part isn't captured.
Can anyone help me how to solve it?
Thanks a lot.
-mia-
|
|
|
|
|
try to make a panel and put the ControlCollection "Controls" from the Form into the panel and set the Panel "AutoSize" and make from the Panel the Screenshot...
i don't know if it works, but that would be my first try to solve this.
|
|
|
|
|
hey ppl! Any freeware source code for bmp to jpeg image converter??. Thx ahead
|
|
|
|
|
Err... kinda. I'm pretty sure that if you open an image, you can then call the save method, and choose the format you want.
Bitmap myImage = new Bitmap("myImage.bmp");<br />
myImage.Save(...);
My current favourite word is: Nipple!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
Image image = Image.FromFile(@"d:\test.jpg");
image.Save(@"d:\test.bmp", ImageFormat.Bmp);
|
|
|
|
|
Can any one give an ideal but beginner example of Web Services
|
|
|
|
|
Before posting your question you should had done 2 things
1. searched google.
2. Posted in correct forum i.e asp.net
click here[^]
Ahsan Ullah
Senior Software Engineer
|
|
|
|
|
Hi,
I have a reference to Interop.PRNADMINLib
I would like to run the code on the print server i.e (myServer) and pickup the installed printers i.e. (printer1) and install this printer on machineB on the network. So machineB will have this in it's printer's list i.e. \\myServer\printer1
Question:
The following code installs the printer on the remote machine but I would like it to point to the print server and not directly connect to the printer itself.
For example, after running the below code you will see the printer1 in the printers list on machineB but I would like it to show \\myServer\printer1
instead of just printer1
How can this code be modified to achieve my goal please?
The code I am using:
PRNADMINLib.Printer p = new PRNADMINLib.Printer();
PRNADMINLib.PrintMaster pm = new PRNADMINLib.PrintMaster();
p.ServerName = "\\\\machineB";
p.PrinterName = "printer1";
pm.PrinterAdd(p);
Any thoughts please?
Thanks
modified on Monday, September 8, 2008 5:52 AM
|
|
|
|
|
Hi All,
I have a button on page.
when user click this button it will call a server side function, which check some data in database. then there will be confirmation message like "Record already exist, Do you want to continue?". if user click (OK)Yes then it will process further in database using another server side function. otherwise it will not process further.
Please tell me how can I do this using javascript ?
I need to show confirmation message.
Thanks.
Regards,
Sunil
|
|
|
|
|
This is not ASP.Net Forum.
Have a look at how RegisterClientScriptBlock [^]works..
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|