Click here to Skip to main content
15,914,500 members
Home / Discussions / C#
   

C#

 
GeneralRe: zip compression Pin
Christian Graus15-Nov-04 9:37
protectorChristian Graus15-Nov-04 9:37 
GeneralRe: zip compression Pin
Anonymous15-Nov-04 12:32
Anonymous15-Nov-04 12:32 
GeneralRe: zip compression Pin
leppie15-Nov-04 22:14
leppie15-Nov-04 22:14 
Generalputting icons in subitems of listview Pin
BlackDice15-Nov-04 7:59
BlackDice15-Nov-04 7:59 
GeneralRe: putting icons in subitems of listview Pin
Heath Stewart15-Nov-04 8:06
protectorHeath Stewart15-Nov-04 8:06 
GeneralGridItem in PropertyGrid Pin
Irie_Pansen15-Nov-04 6:24
Irie_Pansen15-Nov-04 6:24 
GeneralRe: GridItem in PropertyGrid Pin
Heath Stewart15-Nov-04 6:37
protectorHeath Stewart15-Nov-04 6:37 
GeneralAPI Call to GetProfileString Does Not Fill Buffer Pin
stoked15-Nov-04 6:13
stoked15-Nov-04 6:13 
I'm trying to get printer info from the OS using the GetProfileStringA function in Kernel32.dll. I used this logic in VB.NET for a while now without any problems, but in C#, the return string buffer is not getting filled. Does anyone have any ideas what might causing this?

<br />
//Declaration in Class<br />
		[DllImport("Kernel32.dll")]<br />
		static extern int GetProfileStringA( string lpAppName, string lpKeyName, string lpDefault, string lpReturnedString, int nSize)  ;<br />
<br />
// Function to set default printer once the desired printer has been defined<br />
		public bool SetDefaultPrinter(string printerName) <br />
		{<br />
			bool success = true;<br />
<br />
			string sBuffer = new string(' ',255);<br />
			string sPrinterSetup = "";<br />
			string[] sEle;<br />
			string sDriver;<br />
			string sPort;<br />
<br />
			try<br />
			{<br />
<br />
int i;<br />
<br />
// the next line does not change sBuffer, though the value of the return<br />
// value indicates the call worked.<br />
				i=GetProfileStringA("PrinterPorts", printerName, "", sBuffer, sBuffer.Length);<br />
<br />
				if (sBuffer.Trim() != "")<br />
				{<br />
					sEle = sBuffer.Split(',');<br />
					if (sEle.Length > 0)<br />
					{<br />
						sDriver = sEle[0];<br />
						sPort = sEle[1];<br />
						sPrinterSetup = printerName.Trim() + "," + sDriver + "," + sPort;<br />
						WriteProfileStringA("windows", "Device", sPrinterSetup);<br />
						SendMessageA(HWND_BROADCAST, WM_WININICHANGE, 0, "windows");<br />
						System.Windows.Forms.Application.DoEvents();<br />
					}<br />
				}<br />
				else<br />
				{<br />
					errorMessage = "Printer "+printerName+" not detected.";<br />
					success = false;<br />
				}<br />
<br />
			}<br />
			catch (Exception ex)<br />
			{<br />
				errorMessage = ex.Message;<br />
				success = false;<br />
			}<br />
<br />
			return success;<br />
<br />
		}<br />

GeneralRe: API Call to GetProfileString Does Not Fill Buffer Pin
Heath Stewart15-Nov-04 6:31
protectorHeath Stewart15-Nov-04 6:31 
GeneralRe: API Call to GetProfileString Does Not Fill Buffer Pin
stoked15-Nov-04 7:51
stoked15-Nov-04 7:51 
GeneralRe: API Call to GetProfileString Does Not Fill Buffer Pin
Heath Stewart15-Nov-04 8:02
protectorHeath Stewart15-Nov-04 8:02 
GeneralRe: API Call to GetProfileString Does Not Fill Buffer Pin
stoked15-Nov-04 8:24
stoked15-Nov-04 8:24 
GeneralRe: API Call to GetProfileString Does Not Fill Buffer Pin
Heath Stewart15-Nov-04 9:09
protectorHeath Stewart15-Nov-04 9:09 
GeneralRe: API Call to GetProfileString Does Not Fill Buffer Pin
stoked15-Nov-04 10:51
stoked15-Nov-04 10:51 
GeneralRe: API Call to GetProfileString Does Not Fill Buffer Pin
stoked15-Nov-04 8:03
stoked15-Nov-04 8:03 
General.Net Service &amp; Notifyicon disappearing after log-off/log-on Pin
Steef (Stephan Deckers)15-Nov-04 6:07
Steef (Stephan Deckers)15-Nov-04 6:07 
GeneralRe: .Net Service &amp; Notifyicon disappearing after log-off/log-on Pin
Heath Stewart15-Nov-04 6:45
protectorHeath Stewart15-Nov-04 6:45 
GeneralRe: .Net Service &amp; Notifyicon disappearing after log-off/log-on Pin
Steef (Stephan Deckers)15-Nov-04 8:48
Steef (Stephan Deckers)15-Nov-04 8:48 
GeneralDatetime : Minutes between two date values Pin
Anonymous15-Nov-04 2:42
Anonymous15-Nov-04 2:42 
GeneralRe: Datetime : Minutes between two date values Pin
turbochimp15-Nov-04 3:07
turbochimp15-Nov-04 3:07 
GeneralRe: Datetime : Minutes between two date values Pin
Heath Stewart15-Nov-04 5:50
protectorHeath Stewart15-Nov-04 5:50 
GeneralRe: Datetime : Minutes between two date values Pin
turbochimp15-Nov-04 6:03
turbochimp15-Nov-04 6:03 
GeneralRe: Datetime : Minutes between two date values Pin
Stefan Troschuetz15-Nov-04 3:11
Stefan Troschuetz15-Nov-04 3:11 
GeneralInherited User Control: "System.NullReference" Pin
Jannigje15-Nov-04 2:06
Jannigje15-Nov-04 2:06 
GeneralRe: Inherited User Control: &quot;System.NullReference&quot; Pin
turbochimp15-Nov-04 3:13
turbochimp15-Nov-04 3:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.