|
[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
private static extern uint GetWindowsDirectory(
[MarshalAs(UnmanagedType.LPTStr)]
System.Text.StringBuilder lpBuffer,
uint uSize
);
System.Text.StringBuilder buffer = new System.Text.StringBuilder(255);
GetWindowsDirectory( buffer, (uint) buffer.MaxCapacity ); Works here.
I think as a general rule, when you need to pass in a buffer to receive text you use a StringBuilder object.
[edit]Looking at MSDN for the GetWindowsDirectory function it is supposed to accept a TCHAR, so the MarshalAs and DllImport attributes should be changed accordingly as above.[/edit]
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
[DllImport("kernel32.dll", CharSet=CharSet.Auto)]private static extern uint GetWindowsDirectory( [MarshalAs(UnmanagedType.LPTStr)] System.Text.StringBuilder lpBuffer, // buffer for Windows directory uint uSize // size of directory buffer);
Really great language C#. Fast, simple and very comfortable...
|
|
|
|
|
Better get used to it.
|
|
|
|
|
i'm curently writing an application that use winamp , but i can't find any way that i can get informaions about the song it's curently playng(i'm especialy interest in geting the path of the file)
sorry for my english
|
|
|
|
|
I'd like to create an array of references to variables--for example:
void Foo()
{
int a;
string s;
Point p;
Item[] items=new Item[] {new Item(out a), new Item(out s), new Item(out p)};
then pass the array to a function and have the function iterate through the array and populate the data, so that the local vars in the caller get populated--for example:
...
PopulateItems(items);
...
}
void PopulateItems(Item[] items)
{
items[0]=1;
items[1]="abc";
items[2]=new Point(0, 0);
}
Keep in mind this is a simplified example, as ultimately the thing needs to extract the type. The point is I'm looking for something that does this given a dynamic list of items.
Is this possible in C# (and how), the equivalent in C++ being int*, string*, and Point* ?
Thanks!
Marc
Help! I'm an AI running around in someone's f*cked up universe simulator. Sensitivity and ethnic diversity means celebrating difference, not hiding from it. - Christian Graus Every line of code is a liability - Taka Muraoka Microsoft deliberately adds arbitrary layers of complexity to make it difficult to deliver Windows features on non-Windows platforms--Microsoft's "Halloween files"
|
|
|
|
|
Marc, how does your poor girlfriend/wife keep up with this?
I'm not really grasping what you are trying to do, but I have a suggestion or 2. Have you tried this in an unsafe context, that would appear to be the easiest. Secondly, boxing those variables mite do the trick, but I'm not really sure about that.
Hope you win
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
Marc, how does your poor girlfriend/wife keep up with this?
She often has lesson plans to do in the evening, and a thesis paper that she works off&on on.
Basically, I want an array of pointers. You're right, an unsafe context would work, because I can get at the pointer. I'll have to try that.
I'll look at boxing too.
Thanks for the tips!
Marc
Help! I'm an AI running around in someone's f*cked up universe simulator. Sensitivity and ethnic diversity means celebrating difference, not hiding from it. - Christian Graus Every line of code is a liability - Taka Muraoka Microsoft deliberately adds arbitrary layers of complexity to make it difficult to deliver Windows features on non-Windows platforms--Microsoft's "Halloween files"
|
|
|
|
|
Hi all,
I am working on an application that has several file associations. I am wondering how to embed a 2nd icon to be displayed by the shell for the files that are associated with my application. I am able to associate them with the main application icon, but I don't know how to embed a 2nd icon that the shell can access from my exe.
Thanks for your help,
Scott
|
|
|
|
|
How to manipulate the bgcolor of the box within the CheckBox or the RadioButton?
(by System.Windows.Forms)
Can anybody help?
Thanks
|
|
|
|
|
Another question, can anyone tell me how to run an external application from C#! Acctually I want to run cmd.exe from my application and do some thing there!
Thanx...
|
|
|
|
|
Look at System.Diagnostics.Process class.
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
Hello, I have a problem working with binding data to controls!
I have a dataset and windows form with some controls (textboxes, comboboxes) on it. I have binded them to dataset (I used EditValue property or Text, doesn't matter). So when I change data like normal user does (through controls) then everything works properly (data in dataset is also changed). But when I change controls (text/EditValue) property in code, then data in dataset is not changed!! WHY??? Or vice versa, when I change data in dataset, it will not change in controls? Does anyone knows where is the problem?
Thanx...
|
|
|
|
|
What after using EndEdit() after changing property value in code? What happens about changing row after changing value in DataSet? Try to see what's in DataSet using WriteXML( ...DiffGram) May be it will be helpful. There are some errors in DataBinding I think ...
Hi,
AW
|
|
|
|
|
I found a problem!!!!
You cannot call method BeginEdit() when the datarow is already in edit mode!!!
Problem was that I was using valueChanged event, but I had to use validated event!!!
|
|
|
|
|
I'm looking for a guide on creating com+ applications in C#. Anybody know of one?
Thanks!
|
|
|
|
|
A good book that goes over COM+ in C#.NET is "COM and .NET Component Services" from O'REILLY. Give that a try...
Amazon.com Link
|
|
|
|
|
I'm still mere beginner so some questions that might be obvious to you puzzle me.
Is it possible to change to look of the caption bar? Under WindowsNotXP it looks so ugly, when
the form is filled with nice owner drawn controls.
Generally my questio is: is it possible to make a .NET owner drawn caption bar (but no Win32
calls - I know with in standart Win32 programming everything is possible)?
Thank you
|
|
|
|
|
Something went wrong in the registry of my computer. All of a sudden
I cannot compile C# any more. At line 0 of the first source file
fatal error C1102 is generated and the error printed with it
(translated to English) is: "class is not initialized".
When trying to make a new C# project the project cannot be opened and
the error "cannot create the C# compiler" is printed. The suggestion
by the system to repair the installation via the Set-up did not work.
Deleting the C# compiler and then re-installing did not work either.
Next step that I have not taken yet would be to delete all of the
Visual Studio.NET and then re-install.
Then the next step would be to start from scratch with Windows-XP.
A search on the internet also yielded nothing.
Anyone has a better solution?
Harm Salomons
|
|
|
|
|
Do you get the same error running csc.exe from the command line? If so, then the problem is with the C# compiler itself and you need to just reinstall the SDK, not all of VS.NET. However, if you can use csc.exe from the command line, then there's a problem with VS.NET and you need to reinstall that.
any idiot
can write haiku you just stop
at seventeenth syl
-ThinkGeek Fortunes
|
|
|
|
|
I will try it this evening (CET)..
Harm Salomons
|
|
|
|
|
I deleted the Visual Studio and re-installed the Windows Components and the Visual Studio again and
the problem is still there. I sent the question to Microsoft. Let's see what the answer is...
|
|
|
|
|
The following is the last part of a discussion with the
Microsoft help desk:
---
to start with the good news: the C# environment is working properly again.
As you suggested I re-installed the Windows Components Update and then
re-installed the Visual Studio .NET.
Then I tried to create a new C# project, but it still did not open....
When I looked at the re-installation log from the Windows Components
Upgrade I saw that it found that there was nothing to do.
Then I selected
Control Panel->Add/Remove Programs->Microsoft .Net Framework
and I REMOVED the .NET Framework.
Then I installed the .NET Framework again and re-installed the
Visual Studio .NET again.
Now everything works as usual.
Thank you for your support.
Harm Salomons
|
|
|
|
|
Dear experts,
I am trying to create a class that is derived from TextBox that has the ability to automatically resize as text is added to it. It is for use within a diagramming style application.
When the TextBox is created it will have a default width and height (Height is set to allow one line of text to be visible). As the user enters text and reaches the right hand side of the TextBox, I need to increase the height of the text box to allow the second line to be seen and so on. The reverse behaviour is required as text is removed, the box must resize to be the minimal size required to show all lines. Also, the TextBox has the multiline property set to TRUE. I cannot use scrollbars as the user must be able to see all text all once. I've checked the .NET documentation and have not been able to locate a property or event that will allow me to detect this situation and take the appropriate action.
Even the textbox underneath icons on the Windows desktop has the behaviour that I need! If there was anyway of re-using this, it would be great!
Please help! Thanks in advance
Benjamin
|
|
|
|
|
Benjamin,
Try the following:
Initialise a local field, default to the usual height of the textbox:
private int _InitialHeight = 20;
In the constructor of the derived class:
<br />
this.Multiline = true;<br />
this._InitialHeight = this.Height;<br />
Then override the OnTextChanged Method:
protected override void OnTextChanged(System.EventArgs e)<br />
{<br />
System.Drawing.Graphics g = this.CreateGraphics();<br />
<br />
System.Drawing.SizeF s = g.MeasureString(this.Text, this.Font);<br />
<br />
int lines = Convert.ToInt32(s.Width) / this.Width;<br />
<br />
int height = (lines * Convert.ToInt32(s.Height)) + this._InitialHeight;<br />
<br />
this.Height = height;<br />
}<br />
I hope this does what you need. Let me know if you'd like elaboration on any point. Note that this does not take into account the user using the enter key.
|
|
|
|
|
this isnt really for anything im writing but..i was installing a game of mine and it screwed up and didnt actually install...but it did happen to install the registry files so windows xp thinks that it is int stalled...so does the programs install shield installer.....my question is where in the registry does windows store the list of programs installed ? so i can manually delete the entries for this game (Medal of honor)...thanks alot
Jesse M
The Code Project Is Your Friend...
|
|
|
|