|
Good one
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
hello, all.
I am trying to convert a struct from VB to c# in order to use an old DLL. Here is the definition in VB
Public Type CHost
Host As String * 60
Port As String * 5
Info As String * 120 'Inof returned from host
Timeout As String * 10
End Type
In the sample VB code:
Public Declare Function CConnect Lib "OLDDLL.DLL" (Host As CHost) As Integer
iError = CConnect(TheHost)
and then the CHost.Info was set by the remote host.
I converted it to(C#)
public struct CHost
{
[System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr,SizeConst=60)]
public string Host; //host name
[System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr,SizeConst=5)]
public string Port; //host port
[System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr,SizeConst=120)]
public string Info; //Info returned from remote host
[System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr,SizeConst=5)]
public string Timeout; //timeout
};
in my c# code.
[DllImport("OLDDLL",EntryPoint="CConnect")]
public static extern short CConnect(ref CHost Host);
short ierror = CConnect(ref theHost);
I can connect to the remote host but the theHost.Info was not set.
Could anybody let me know what I was doing wrong and what is the right way to do it?
|
|
|
|
|
Hi,
SQLHelpder class is given in "Data Access Application Block". This block sample code is availabe on
Microsoft MSDN. Why am I using this becuase of time saving. Useful overloads are available to do more in less time.
What I need in a form is the newly added IDs in a table. For example I wrote the following code
//This module will insert a new role in the tblRole table by calling the stored procedure uspRoleNew
SqlParameter[] arparam = new SqlParameter[9];
arparam[0] = new SqlParameter("@pRoleName",SqlDbType.VarChar, 50);
arparam[0].Value= mRoleName;
arparam[1] = new SqlParameter("@pRoleDesc", SqlDbType.VarChar,50);
arparam[1].Value= mRoleDescription;
.
.
. .
arparam[8] = new SqlParameter("@pRoleIDout", SqlDbType.Int);
arparam[8].Direction=ParameterDirection.Output;
SqlHelper.ExecuteNonQuery(clsGeneral.conStr, "uspRoleNew", arparam);
int _RoleID;
_RoleID = (int)arparam[8].Value;
In paramerter[8] i want the newly added ID. But SqlHelper is not returning any value.
Below is the alternative solution for the above problem
mSqlCommand.Connection= _Sqlconn;
mSqlCommand.CommandText="uspRoleNew";
mSqlCommand.CommandType=CommandType.StoredProcedure;
mSqlCommand.Parameters.Add("@pRoleName",SqlDbType.VarChar, 50);
mSqlCommand.Parameters[0].Value=mRoleName;
mSqlCommand.Parameters.Add("@pRoleDesc", SqlDbType.VarChar,50);
mSqlCommand.Parameters[1].Value= mRoleDescription;
mSqlCommand.Parameters.Add("@pRoleIDout", SqlDbType.Int);
mSqlCommand.Parameters["@pRoleIDout"].Direction= ParameterDirection.Output;
_Sqlconn.Open();
mSqlCommand.ExecuteNonQuery();
mRoleID = (int)mSqlCommand.Parameters["@pRoleIDout"].Value;
return mRoleID;
QUESTION ????? is Why sqlhelper not doing this. If u r aware of "Data Access Application Block" plz reply.
|
|
|
|
|
Hi,
Would anybody plz screw up this code.
SqlParameter[] arparam = new SqlParameter[3];
int _GroupID;
arparam[0] = new SqlParameter("@pGroupName",SqlDbType.VarChar, 50);
arparam[0].Value= mGroupName;
arparam[1] = new SqlParameter("@pGroupDesc", SqlDbType.VarChar,50);
arparam[1].Value= mGroupDescription;
arparam[2] = new SqlParameter("@pGroupIDout", SqlDbType.Int);
arparam[2].Direction=ParameterDirection.Output;
SqlConnection _Sqlconn = new SqlConnection(clsGeneral.conStr);
SqlCommand mSqlCommand = new SqlCommand();
mSqlCommand.Connection= _Sqlconn;
mSqlCommand.CommandText="uspGroupNew";
mSqlCommand.CommandType=CommandType.StoredProcedure;
mSqlCommand.Parameters.Add(arparam);
_Sqlconn.Open();
mSqlCommand.ExecuteNonQuery();
_GroupID = (int)mSqlCommand.Parameters["@pGroupIDout"].Value;
return _GroupID;
|
|
|
|
|
How would you like us to screw it up? You can start by changing random letters in variable and class names so that it will not compile. If you'd also like some runtime errors, change the name of a couple of stored procedures.
abidkayani1 wrote:
mSqlCommand.Parameters.Add(arparam);
There is no overload of SqlCommand.Parameters.Add that accepts an array of parameters as an argument.
Charlie
if(!curlies){ return; }
|
|
|
|
|
Hi,
I have a rather simple problem, yet I can't find an acceptable solution. It isn't much of a problem for users running my application at high resolution (1280x1024 for example), but it really is for 800x600 users (too bad they still exist!)
My application is a MDI and I use FormStartPosition.WindowsDefaultBounds for each child form in order for them to open underneath the previous one (cascade).
The problem is that if I open 3 or 4 windows, a scrollbar shows up on my MDI form and the user needs to scroll to see the new windows. It happens even when no windows are open (ie: 4 windows were opened, then closed, the user will need to scroll to see the next opened window because it is not positionned at the top of the screen like it should).
Is there an easy solution to this? Anyone else having this problem?
Thanks!
Carl
|
|
|
|
|
You would have to track the position of the last form you opened. Then add whatever offsets you need in order to keep the next window inside the client area. You would be managing the position and size of the child forms yourself. Simply create a new instance of your child form, set its position and size properties, then show it.
RageInTheMachine9532
|
|
|
|
|
Isn't supposed to be done automatically for me???
|
|
|
|
|
The Default behavior doesn't take into account the size of the child window your opening... so no, it won't do it for you.
The Default behavior will walk down the parent window's client area adding up to 10 child windows stepping down and to the right until the new child window's title bar is half way down the client area of the parent window. It will then start at the top-left corner of the parent client area again and start over. It will do this without any reguard to the size of the child windows...
So if you want the entire child window inside the parent client area, you're goin got have to supply your own code for placing the child windows with reguard to it's size.
RageInTheMachine9532
|
|
|
|
|
Urg! Pain in the neck... Let's code!
|
|
|
|
|
What? You want Microsoft to do everything for you, just the way you want it?
That's why we write code! We want it done OUR way!!
RageInTheMachine9532
|
|
|
|
|
We want it our way, but we also want some free time to chill out and watch tv
|
|
|
|
|
I'm having a problem with using the Web Browser ActiveX control in a C# windows form app. The circumstance is easily reproducable:
Create the boiler plate example of this using the VS toolbox to create the ActiveX wrapper and add then drag it into your C# form.
Now, open up a web page with your forms app. For instance, mail.yahoo.com. Click in the user name entry field so that focus is there. Now minimize your form app and then bring it right back up. All of a sudden that entry field no longer has the focus.
I have another example using this control through a VC++ 6 MFC SDI app and ironically, it works fine there (the entry field still has focus).
Any ideas on what to look at? I thought it might have to do with message routing differences between windows forms and MFC SDI but hooking the app up to Spy++ didn't reveal anything. Now I'm thinking it's a problem with the .NET generated wrapper but I'm at a loss as to what to do about it.
???
any help appreciated!
|
|
|
|
|
I'm wanting to create a ToolBarMenu with a few combo boxes... I'm having problems on figuring this out.
Does anyone have any sample code to do this? (for .Net Framwork 1.1)
|
|
|
|
|
I have multiple projects in a solution and I am trying to create dependencied, but when i was trying to add a project reference i got the following message:
A reference to NDMUI could not be added. An assembly must have a "dll" extension in order to be referenced.
I do not not how to resolve it......may someone please help!
Tryin' my best
|
|
|
|
|
VS.NET doesn't let you reference a .exe. It is possible, but you'll have to use the command line compiler (csc.exe) or a build tool like NAnt[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I figure that to draw my little windows style borders, i need to actualy have a valid handle to the grahics device for the control.
Now, I have this section of code i have included in my component constructor that causes a problem:
Graphics clientDC = this.CreateGraphics(); <br />
IntPtr hdc = clientDC.GetHdc(); <br />
pDC = ThemeAPI.CreateCompatibleDC(hdc);<br />
clientDC.Dispose();
That throws the following error on run time:
An unhandled exception of type 'System.InvalidOperationException' occurred in system.drawing.dll
Additional information: The object is currently in use elsewhere.
Now, i know it's caused by the existence of the ClientDC, but i'm not sure how to go about solving this one.
I need to get the creatgraphics for the component in question, but I guess, as i'm creating three duplicate components at initialisation, it's running three seperate threads at once, and it's not liking the use of the Device Context. If i don't dispose of it, the program runs for a while before crashing.
Should I construct a graphics handle in the parent form?
Cata
|
|
|
|
|
Call clientDC.ReleaseHdc(pDC) when you're done with the HDC , then dispose your Graphics object.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Okey dokey, works now.
I was trying to use P/Invoke DeleteDC(pDC). It clearly wasn't happy with that.
But i've still got nothing drawn on my background. I think i have the object values right, and i've tried a number of values for iState. So i'm not entirely sure why nothing is appearing. Here is the code
<br />
pTHEME = ThemeAPI.OpenThemeData(this.Handle,"Window");<br />
<br />
Graphics clientDC = this.CreateGraphics(); <br />
IntPtr hdc = clientDC.GetHdc(); <br />
pDC = ThemeAPI.CreateCompatibleDC(hdc);<br />
<br />
ThemeAPI.Rect rect = new ThemeAPI.Rect();<br />
rect.left = this.Location.X;<br />
rect.top = this.Location.Y;<br />
rect.right = this.Location.X + this.Size.Width;<br />
rect.bottom = this.Location.Y + this.Size.Height;<br />
<br />
int result;<br />
result = ThemeAPI.DrawThemeBackground(pTHEME,pDC,5,1,ref rect,IntPtr.Zero);<br />
result = ThemeAPI.DrawThemeBackground(pTHEME,pDC,7,1,ref rect,IntPtr.Zero);<br />
result = ThemeAPI.DrawThemeBackground(pTHEME,pDC,8,1,ref rect,IntPtr.Zero);<br />
result = ThemeAPI.DrawThemeBackground(pTHEME,pDC,9,1,ref rect,IntPtr.Zero);<br />
<br />
clientDC.ReleaseHdc(pDC);<br />
clientDC.Dispose();
What do you make of it?
|
|
|
|
|
Deleting the HDC that way is fine if you don't use Graphics.GetHdc to get it. The reason is that the unmanaged pointer that the Graphics references needs to be freed, otherwise the Graphics object will complain about having an invalid handle when the Graphics.Dispose method tried to delete it.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
You get that error when the application is not loaded into an STA (single-threaded apartment). Make sure you use the STAThreadAttribute on your entry point and that any controls in your library used in an application are created in the main thread.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Too late m8!
Got to that one on my own
|
|
|
|
|
there are lots of examples on how to set up child form from the MainMDI but i cant find anything on how to open a form from another child form and setting the MDIParent so as it becomes child form, where am i going wrong???
|
|
|
|
|
So long as you're not talking about an MDI child form within another MDI child form (which isn't supported in the .NET FCL), you can simply get the parent MDI form of the first child and add the new child as an MDI child of the parent:
MDIChildForm child = new MDIChildForm();
if (MdiParent != null)
MdiParent.AddOwnedForm(child);
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
fantastic response and worked first time.
|
|
|
|