|
Heap memory is allocated when the 'newobj' or 'newarr' IL instructions are executed. In C# this means in two places:
MyType foo; // no heap allocation
foo = new MyType(); // heap allocation here
int[] bar = {1,2,3}; // heap allocation here, even without a 'new'
--
-Blake (com/bcdev/blake)
|
|
|
|
|
How do i convert an image to cursor in C# (runtime)? Any hints?
/gywox
|
|
|
|
|
Hi !!
I've got a problem on an windows application in C#
My connection are made with the Windows Users parameters. And they give an number of rights over my I/O System.
But for a spécific function, i need to change this users to have rights on an other directory.
I know that there is a class Impersonation but it seems to work only over XP. And i need to make that on Win 2000 station.
Does anybody know, how to make that ???
Thanks.
|
|
|
|
|
I can point you in the right direction as I have had to do something similar recently.
To impersonate you need to call LogonUser using PInvoke to get a user token, this call requires that the current user has the SE_TCB_NAME privilege (also called "Act as Part of Operating System") but you shouldn't just grant this to any account because it opens security holes. The way around it is to create a windows service to make the call. A windows service works because the LocalSystem and LocalService users automatically have SE_TCB_NAME. The reason it works on XP is that the requirement is no longer there....
Try looking up LogonUser in the platform SDK docs on MSDN...
HTH
-----------------------------------------------------------------------
Shaun Austin: .NET Specialist. Spreading the word of .NET to the world... well the UK... well my tiny corner of it!!
|
|
|
|
|
Is it possible to show columns from to seperate dataTables in the same datagrid simoultanously?
maybee using dataView or something else?
(in windows forms)
Yes or no?
true or false?
|
|
|
|
|
how can i convert the path(C:\..) to a binary and store it into the database
btw i am using ms sql database
thx!!
|
|
|
|
|
Hiya...
Firstly, do you definitely need to save it to the DB as binary as presumably when you read it out you will want to convert it back to a string anyway..??
Secondly, assuming you still do then I tend to have an SqlHelper class with useful methods for dealing with data layer stuff... one of them is...
public static byte[] ObjectToByteArray(Object obj)
{
if(obj == null)
return null;
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
bf.Serialize(ms, obj);
return ms.ToArray();
}
Which will allow you to convert any object to a byte array....
HTH...
-----------------------------------------------------------------------
Shaun Austin: .NET Specialist. Spreading the word of .NET to the world... well the UK... well my tiny corner of it!!
|
|
|
|
|
hi guys. i am using tlbimp.exe toll to convert my Dll which i develop in VB6.0 to .Net component. that Dll shows the Print preview of Report.
but when i call the method of that DLL i am getiing the exception
"An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in Reports.exe
Additional information: Exception from HRESULT: 0x800A0196";
did anyone has any idea about it.
|
|
|
|
|
I have a SMS modem, and how can I use it to send a message to a mobile phone? could somebody show me a demo?
|
|
|
|
|
Hello,
How can one set up a RichTextBox so that the box shows an integral number of text lines, say 17, when the text box is scrolled all the way down? Possibly this would involve making the RichTextBox have a particular size.
The example below shows what I tried: set ClientSize.Height to be a multiple of Font.Height. It didn't work. When the text box is scrolled all the way down, a piece of a line shows at the top, which looks bad. I don't know how to calculate the amount by which the sizing is off.
(This rich text box will always be scrolled all the way down. Thanks to posters who responded to "help me, how to autoscroll in richtextbox" by KETUINHA for showing me how to do this.)
By the way, how can one post code in these forums and have the code's indentation be preserevd? Using 'code' tags ended up with no indentation, at least according to the preview.
using System;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
class TextBoxTesterForm : Form
{
public TextBoxTesterForm()
{
int lines = 5;
d_rtb = new RichTextBox();
d_rtb.SuspendLayout();
d_rtb.Parent = this;
d_rtb.Location = new Point(10,10);
int desiredTextHeight = lines * d_rtb.Font.Height;
d_rtb.ClientSize = new Size(200, desiredTextHeight);
d_rtb.ResumeLayout();
Console.WriteLine("lines={0}", lines);
Console.WriteLine("rtb Font.Height = {0}",
d_rtb.Font.Height);
Console.WriteLine("rtb Font.GetHeight() = {0}",
d_rtb.Font.GetHeight());
Console.WriteLine("desiredTextHeight = {0}",
desiredTextHeight);
Console.WriteLine("rtb ClientSize = {0}",
d_rtb.ClientSize);
Console.WriteLine("rtb DisplayRectangle = {0}",
d_rtb.DisplayRectangle);
Console.WriteLine("rtb Size = {0}", d_rtb.Size);
Console.WriteLine("rtb Multiline = {0}", d_rtb.Multiline);
}
RichTextBox d_rtb;
}
class TextBoxTestMain {
static void Main()
{ Application.Run(new TextBoxTesterForm()); }
}
|
|
|
|
|
Use the <pre> tag for posting code with indentations, and go read Raymond's blog for _everything_ you ever wanted to know about scrolling and were afraid to ask. An eleven part series on all the intricacies.
--
-Blake (com/bcdev/blake)
|
|
|
|
|
Thanks.
I glanced at Raymond's blog. Before I search through it in detail for the iota I'm looking for, can you tell me why you think this has something to do with scroll bars?
|
|
|
|
|
Because, despite the scrollbars title, it's about a lot more. Have a look at parts 7 & 8 in particular, titled "Integrality" and "Integral interactive resizing" respectively.
--
-Blake (com/bcdev/blake)
|
|
|
|
|
And here's a chunk of code that does exactly what you are looking for with a pair of RichEdit controls separated by a splitter. Digging out the bit that applies to just the top RichEdit is left as an exercise to the reader. Warning - old Win32 code, no MFC, no WTL, no CLR, just C++/Win32. The math however is still the same.
void CConsole::ReSize(int *pcx, int *pcy, BOOL bSnap)
{
int cx = GetSystemMetrics(SM_CXEDGE);
int cy = GetSystemMetrics(SM_CYEDGE);
int nScrollWidth = GetSystemMetrics(SM_CXVSCROLL) +
GetSystemMetrics(SM_CXBORDER);
int nSepHeight = GetSystemMetrics(SM_CYFIXEDFRAME);
RECT r;
SendMessage(m_hOutput, EM_GETRECT, 0, LPARAM(&r));
cx += r.left;
cy += r.top;
if (pcx && pcx) {
if (bSnap) {
RECT r;
r.top = r.left = 0;
r.right = m_nCols * m_nCharWidth + 2 * cx + nScrollWidth;
r.bottom = (m_nOutputRows + m_nInputRows) * m_nCharHeight + 4 * cy
+ nSepHeight + m_nStatusHeight;
AdjustWindowRectEx(&r, GetWindowLong(m_hWnd, GWL_STYLE),
BOOL(GetMenu(m_hWnd)), GetWindowLong(m_hWnd, GWL_EXSTYLE));
*pcx = r.right - r.left;
*pcy = r.bottom - r.top;
} else {
int cxClient = *pcx, cyClient = *pcy;
RECT r;
r.left = 0; r.top = 0;
r.right = *pcx; r.bottom = *pcy;
AdjustWindowRectEx(&r, GetWindowLong(m_hWnd, GWL_STYLE),
BOOL(GetMenu(m_hWnd)), GetWindowLong(m_hWnd, GWL_EXSTYLE));
int cxOld = cxClient -= r.right - r.left - *pcx;
int cyOld = cyClient -= r.bottom - r.top - *pcy;
m_nCols = max(0, (cxClient - 2 * cx - nScrollWidth
+ m_nCharWidth / 2) / m_nCharWidth);
cxClient = m_nCols * m_nCharWidth + 2 * cx + nScrollWidth;
int nTotalRows = max(0, (cyClient - 4 * cy - nSepHeight
- m_nStatusHeight + m_nCharHeight / 2) / m_nCharHeight);
cyClient = nTotalRows * m_nCharHeight + 4 * cy
+ nSepHeight + m_nStatusHeight;
m_nOutputRows = nTotalRows - m_nInputRows;
if (m_nOutputRows < 0) {
m_nInputRows += m_nOutputRows;
m_nOutputRows = 0;
}
*pcx += cxClient - cxOld;
*pcy += cyClient - cyOld;
}
}
HDWP hdwp = BeginDeferWindowPos(3);
hdwp = DeferWindowPos(hdwp, m_hOutput, NULL, 0, 0,
m_nCols * m_nCharWidth + 2 * cx + nScrollWidth,
m_nOutputRows * m_nCharHeight + 2 * cy,
SWP_NOACTIVATE | SWP_NOZORDER);
hdwp = DeferWindowPos(hdwp, m_hInput, NULL, 0,
m_nOutputRows * m_nCharHeight + 2 * cy + nSepHeight,
m_nCols * m_nCharWidth + 2 * cx + nScrollWidth,
m_nInputRows * m_nCharHeight + 2 * cy,
SWP_NOACTIVATE | SWP_NOZORDER);
hdwp = DeferWindowPos(hdwp, m_hStatus, NULL, 0,
(m_nInputRows + m_nOutputRows) * m_nCharHeight + 4 * cy + nSepHeight,
m_nCols * m_nCharWidth + 2 * cx + nScrollWidth, m_nStatusHeight,
SWP_NOACTIVATE | SWP_NOZORDER);
EndDeferWindowPos(hdwp);
}
--
-Blake (com/bcdev/blake)
|
|
|
|
|
Blake, that code uses a variable called m_nCharHeight that is not defined in the code. How is the value of this variable computed?
|
|
|
|
|
It's just a cached copy of the tmHeight height value from the TEXTMETRIC for the currently selected font. Here's the relevent bit out of the middle of an EnumFontFamilies callback:
HDC hdc = GetDC(NULL)
LOGFONT lf = pelf->elfLogFont;
lf.lfHeight = -MulDiv(pParam->pCon->m_nPointSize,
GetDeviceCaps(hdc, LOGPIXELSY), 72),
lf.lfWidth = 0;
HFONT hf = CreateFontIndirect(&lf);
TEXTMETRIC tm;
HFONT hfOld = (HFONT)SelectObject(hdc, hf);
GetTextMetrics(hdc, &tm);
SelectObject(hdc, hfOld);
ReleaseDC(NULL, hdc);
SendMessage(pParam->pCon->m_hOutput, WM_SETFONT, WPARAM(hf), 0);
SendMessage(pParam->pCon->m_hInput, WM_SETFONT, WPARAM(hf), 0);
DeleteObject(hf);
pParam->pCon->m_nCharWidth = tm.tmAveCharWidth;
pParam->pCon->m_nCharHeight = tm.tmHeight;
--
-Blake (com/bcdev/blake)
|
|
|
|
|
What is the equivalent quantity in managed .NET (perhaps accessible through the Font class)?
|
|
|
|
|
Ah. Well, thanks, I took a look. I don't know the Win API but it appears that the idea in the blog is to compute the difference between the vertical extents of the window and the client area, and use the difference to adjust the size of the window so that the client area comes out to be an integral number of text lines.
In the example I gave, getting the client area to be a desired size is not the problem. The desired vertical size of the client area is 110 pixels, and that is what the area is as measured with a screen dump. It appears that setting the ClientSize property of the rich text box to use a height of 110 does in fact set the client area to 110.
So I think the blog might be solving a different problem than what's needed here.
One problem I did notice is that the font's Font.Height value is given as 22 pixels, but the baseline-to-baseline spacing in the rich text box is 24 pixels. Does anyone know why this might be? It's certainly necessary to account for this in order to get an integral number of text lines. Maybe there is some Font or RichTextBox property that needs to be used besides Font.Height.
|
|
|
|
|
I need to wait on a native handle to be signaled from within a managed application. I am trying to pinvoke to WaitForSingleObject but keep getting a missing method exception.
I successfully pinvoked into SetEvent and CreateEvent. But when I try to call WaitForSingleObject, the exception "missingmethodexception" is thrown, so something is probably wrong with my managed WaitForSingleObject definition and the marshaler is complaining. My managed definitions are:
[DllImport("coredll.dll")]
private static extern int CreateEvent(
IntPtr lpEventAttributes, //?? set as NULL
bool bManualReset,
bool bInitialState,
string lpName
);
[DllImport("coredll.dll")]
private static extern bool SetEvent(
int hEvent
);
[DllImport("coredll.dll")]
private static extern uint WaitForSingleObject(
int hHandle,
uint dwMilliseconds
);
What's wrong with my WaitForSingleObject definition that would cause the exception? I am developing on windows ce.net and the api says WaitForSingleObject exists in coredll.dll.
Any help will be extremely appreciated.
|
|
|
|
|
WaitHandle wh = new WaitHandle();
wh.Handle = myNativeEventHandle;
wh.WaitOne();
--
-Blake (com/bcdev/blake)
|
|
|
|
|
I assume you mean ManualResetEvent since WaitHandle is abstract and you can't have an instance of it?
|
|
|
|
|
Yes - sloppy on my part. The important point was, don't P/Invoke at all, let the framework do it for you. You can wrap native sync objects in WaitHandle derived classes easily enough.
--
-Blake (com/bcdev/blake)
|
|
|
|
|
I am writing a C# application that will send canned email messages to specified email addresses. The spec for this project is pretty simple. I want to pass a string to my object in the form of "LastName, FirstName" and I want to be able to verify that this is a valid name in the global address book from Outlook. I have so far been unable to access the global address book? After I find the name in the GAB I want to send a canned message to that person's email address. I am also not sure of how to get their email adress once I verify their name in the GAB. I plan on using MAPI to send the messages which I am also not very familiar with. I am a newbie with C# and I would really appreciate any help anyone has to offer. Thanks for your time and happy coding!
Frank
|
|
|
|
|
I can't get what you mean by canned mail... anyway, MAPI is no longer our darling... to send an email... follow following steps...
Add reference of System.Web into your project... and do following in code...
<br />
using System.Web.Mail;<br />
.......<br />
.......<br />
.......<br />
.......<br />
.......<br />
MailMessage mail = New MailMessage()<br />
<br />
mail.To = ToMail;<br />
mail.From = FromMail;<br />
mail.Subject = Subject;<br />
mail.Body = Msg;<br />
<br />
SmtpMail.SmtpServer = "localhost";<br />
<br />
try<br />
{<br />
SmtpMail.Send(mail)<br />
Return true;<br />
<br />
} Catch ex As Exception<br />
{<br />
Return false;<br />
}<br />
Explore more... you can send attachments and blah blah with it too..
Good Day; <wish me="" one="" too="" coz="" need="" today="" ="">
mE
---------------------
A gasp of breath,
A sudden death:
The tale begun.
A rustled page
Passes an age:
The tale is done.
|
|
|
|
|
Does .NET framework have the facility to write objects to the underlying steams (as in Java)?
|
|
|
|
|