|
Hi everyone,
I have a C# based COM DLL that uses an old ocx. The ocx is placed within a panel inside a form that the C# COM DLL displays as a dialog.
In the InitializeComponent call, I get the "Call is rejected by callee" exception with the EndInit call on the ocx wrapper.
Here are the relevant portions of the code:
namespace KVXUI
{
public class KVXUIForm : System.Windows.Forms.Form
{
...
private AxKVXLib.AxKVX m_kvx;
...
public KVXUIForm()
{
InitializeComponent();
...
}
private void InitializeComponent()
{
...
this.m_kvx = new AxKVXLib.AxKVX();
...
((System.ComponentModel.ISupportInitialize)(this.m_kvx)).BeginInit();
...
m_MainPanel.Controls.Add(this.m_kvx);
...
//
// m_kvx
//
... m_kvx initialization code here
...
((System.ComponentModel.ISupportInitialize)(this.m_kvx)).EndInit();
...
}
...
}
}
The exception occurs when the EndInit shown above is called. However, this does not happen always. Here are a couple of scenarios showing how the DLL is invoked:
The following scenario works fine.
MFC app --> some other ocx --> ATL COM object --> my C# COM DLL
The scenario below results in an exception.
Adobe Acrobat 5.0 -> some other dll -> ATL COM object -> my C# COM DLL
There were some posts on the net that indicated that this may be a timing related problem. I sprinkled some sleep calls but that didn't help.
Any help will be greatly appreciated.
Thanks.
Hari
|
|
|
|
|
Hi
I need to implement a synchoronous operation through sockets.I need to send data from my client to the server,have the server read that data,process it,generate a response,and then send it back to me.I need to wait for this response on my client end.Im trying to use tcpclient and tcplistener.However the problem is when i have sent the data from the client side,how do i wait for the server response before i proceed?How can i know when the server has done with its processing and is pushing data back on my stream?
How are synchoronous operations done??
Please help.
Thanks
Jay sai
|
|
|
|
|
I'm trying to use an ocx written in VB6 in my C# app and
when i try to show a form ("click a button") i get an error message
"run-time error 406 Non Modal Forms cannot be displayed ... "
what can be done if i need these forms Non Modal?
thanks
sharon
|
|
|
|
|
Hi,
I want to overload the == and != operators on my custom class, and my trusty "C# and the .NET platform, second edition" suggests that I overload the System.Object.Equals and does something like this:
public override bool Equals(object obj)
{
try
{
Row r = (Row)obj;
if (obj == null)
return false;
bool retval = (this.m_style == r.m_style) &&
(this.m_text == r.m_text) &&
(this.m_sortOrder == r.m_sortOrder) &&
(this.m_parentId == r.m_parentId);
return retval;
}
catch
{
return false;
}
}
public override int GetHashCode()
{
return m_id.GetHashCode();
}
public static bool operator ==(Row r1, Row r2)
{
return r1.Equals(r2);
}
public static bool operator !=(Row r1, Row r2)
{
return !r1.Equals(r2);
}
This will let the .Equals() method take care of any needed comparison, and looks good. My problem is now when I write code like
Row row = null;
if (blaha blaha)
row = some_row
if (row != null)
- if the "if (blaha blaha)"-statement isn't true, we'll end up comparing null and null with the == operator. This will call "return r1.Equals(r2);" where r1 is null and we have a crash.
Could someone please help me with an example of a correct implementation of overloading the == and != operators, that handles checking for member variable equalness as well as null-values correctly. I seem to keep running into problems that must have been solved a million times before - but I can't find any useful examples on google - nor here on CP.
Thanks in advance, guys 'n' gals !
/Jan
Do you know why it's important to make fast decisions? Because you give yourself more time to correct your mistakes, when you find out that you made the wrong one. Chris Meech on deciding whether to go to his daughters graduation or a Neil Young concert
|
|
|
|
|
Add the following lines to your operator== method:
if (Object.ReferenceEquals(r1, null) || Object.ReferenceEquals(r2, null))
{
return Object.ReferenceEquals(r1, 2);
}
The operator!= is left as an exercise to the reader
Yes, even I am blogging now!
|
|
|
|
|
HAH !!
Thanks a LOT !!!
I tried that... well, almost.. I just used the == operator like "if (r1 == null)" and of course it just called itself and gave me a stack overflow (great.. ). But that's it - use the Object.ReferenceEquals.
Once again, thanks.
This is why I CP
/Jan
Do you know why it's important to make fast decisions? Because you give yourself more time to correct your mistakes, when you find out that you made the wrong one. Chris Meech on deciding whether to go to his daughters graduation or a Neil Young concert
|
|
|
|
|
I would implement it the following way:
public static bool operator ==(Row r1, Row r2)
{
try
{
if (r1 == null || r2 == null)
return false;
bool retval = (r1.m_style == r2.m_style) &&
(r1.m_text == r2.m_text) &&
(r1.m_sortOrder == r2.m_sortOrder) &&
(r1.m_parentId == r2.m_parentId);
return retval;
}
catch
{
return false;
}
}
public static bool operator !=(Row r1, Row r2)
{
return !(r1 == r2);
}
public override bool Equals(object obj)
{
Row row = obj as Row;
return this == row;
}
public override int GetHashCode()
{
return m_id.GetHashCode();
}
NOTE: Your GetHashCode method is inconsistent with your equality criteria. Ur basing the hash code generation on 'm_id' when in ur == operator ur stating that the two objects are equal only when 'Style', 'Text', 'SortOrder' and 'ParentId' are the same.
This will lead to having two Row objects with the same HashCode (Same 'm_id') not being equal, which should never happen. If, on the other hand, 'm_id' is a unique identifier of your row, then maybe you should consider using it also as your equality criteria.
Always keep in mind that two objects with the same hashchode should be equal.
|
|
|
|
|
I am trying to use a datagrid with columns of different width. I have found several methods posted on various sites, but unfortunately am unable to make any of them work. The following code seems to be the most straightforward, but none of the formatting is actually applied to the datagrid.
What am I missin?
private void FormView_Load(object sender, System.EventArgs e)
{
string connection = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=reminder.mdb";
//string query ="SELECT Date,Time,Message,TicklerDate,TicklerTime FROM Ticklers";
string query ="SELECT * FROM Ticklers";
// Initialize the connection using the connection string
conn = new OleDbConnection(connection);
// Open the db connection
conn.Open();
//Initiate the OleDbDataAdapter using the SQL select commmand on the db connection
adapter=new OleDbDataAdapter(query,conn);
// Initiate and fill the dataset
ds = new DataSet();
//initiate the datatable
adapter.Fill(ds,"Customers");
dt = ds.Tables[0];
// Get the database schema
adapter.FillSchema(dt, SchemaType.Source);
conn.Close();
// Format the data grid
DataGridTableStyle ts = new DataGridTableStyle();
this.dataGrid1.TableStyles.Clear();
//ts.MappingName="Ticklers";
ts.MappingName=dataGrid1.DataMember;
DataGridTextBoxColumn column1 = new DataGridTextBoxColumn();
column1.MappingName="Index";
column1.HeaderText="Index";
column1.Width = 0;
ts.GridColumnStyles.Add(column1);
DataGridTextBoxColumn column2 = new DataGridTextBoxColumn();
column2.MappingName="Date";
column2.HeaderText="Event Date";
column2.Width = 75;
ts.GridColumnStyles.Add(column2);
DataGridTextBoxColumn column3 = new DataGridTextBoxColumn();
column3.MappingName="Time";
column3.HeaderText="Event Time";
column3.Width = 75;
ts.GridColumnStyles.Add(column3);
DataGridTextBoxColumn column4 = new DataGridTextBoxColumn();
column4.MappingName="Message";
column4.HeaderText="Description";
column4.Width = 150;
ts.GridColumnStyles.Add(column4);
DataGridTextBoxColumn column5 = new DataGridTextBoxColumn();
column5.MappingName="TicklerTime";
column5.HeaderText="Tickler Time";
column5.Width = 75;
ts.GridColumnStyles.Add(column5);
DataGridTextBoxColumn column6 = new DataGridTextBoxColumn();
column6.MappingName="TicklerDate";
column6.HeaderText="Tickler Date";
column6.Width = 75;
ts.GridColumnStyles.Add(column6);
dataGrid1.TableStyles.Add(ts);
// Bind the datatable to the datagrid control
this.dataGrid1.DataSource=dt;
// Show the datagrid
this.dataGrid1.Visible=true;
}
ngb
|
|
|
|
|
I'm making a graphical display, but the image refresh is very jerky. I added a tick counter to the behaviour thread, and it takes 0ms, so the issue was not there.
On adding it to the graphical thread however, I discovered that rendering tends to jump a lot, on average a few small objects take 16ms, but jump to 35-40 once or twice a second. When I add a large image to the rendered scene, (640x480 or higher), the rendering time increases to 70, and jumps to over 100 a couple of times a second.
I'm using the following threaded loop:
<br />
int start = Environment.TickCount;<br />
g.DrawImage(Background,0,0);<br />
r.Draw(g, new Point(0,0));<br />
s.Draw(g, new Point(0,0));<br />
t.Draw(g, new Point(0,0));<br />
pb_Display.Refresh();<br />
tb_Text.Text = (Environment.TickCount - start).ToString();<br />
Note: I'm rendering this image to a picturebox Image, and redrawing the image on every itteration. I'm still looking for a better way to do this.
I have two questions about this, why does this jump occur?
And are there any techniques to increase the speed at which rendering occurs?
CHeers
Tris
|
|
|
|
|
The Catalyst wrote:
And are there any techniques to increase the speed at which rendering occurs?
If you care about speed, use GDI or DirectX (in extreme cases) for drawing.
GDI calls should provide enough speed for most uses.
The Catalyst wrote:
Note: I'm rendering this image to a picturebox Image, and redrawing the image on every itteration. I'm still looking for a better way to do this.
Actually, you should only call Invalidate/Update on the control and let it redraw itself when needed (on the Paint event or an overrided OnPaint method). This will keep you from drawing faster than the video card/driver can handle. You'll need only to draw 60 times per second, as the video does not refresh more than this. This means that times you have around 160ms to draw, and flip the buffer when the monitor's vertical retrace happen. What do I mean about "flip the buffer"? Do a bit of search and read about double-buffering, and you'll understand better how to achieve high frame rates, even with a slow drawing.
The .NET framework offers suport for double-buffering, but I suggest you to read more about how it works before using it.
Yes, even I am blogging now!
|
|
|
|
|
I'm already double buffering it actualy, but thanks for the point.
I will look at GDI, I don't think i'll need DirectDraw. Although I did notice they took it out of the latest version of the DirectX9 SDK. Why do that?
Cheers
Tris
|
|
|
|
|
I did a little investigation, and the native .NET draw methods are all based on GDI plus, so there's not much I can do there. I'm downloading the DX9 SDK now.
I think you might be wrong about the 160ms... when I wrote the following code:
start = Enviroment.TickCount;
Thread.Sleep(Timespan.FromSeconds(1));
MessageBox.Show((Enviroment.TickCount - Start).ToString());
It displayed 1000.
Therefore, to get 30fps, I would need to do all the rendering in less than 33.3 ms. Which currently, I'm unable to do, even on a simple scene.
I'll look into DX9, and see what I can do, but do you have any more suggestions?
Cheers
Tris
|
|
|
|
|
The Catalyst wrote:
I did a little investigation, and the native .NET draw methods are all based on GDI plus, so there's not much I can do there.
The problem is with the "plus" part: GDI+ is not hardware accelerated (although some top-notch cards do accelerate it), while the standard GDI is. GDI is way more difficult to use, and you'll need to resort to API calls. Search for BitBlt and you'll understand what I mean. BitBlt performance is almost the same as DirectDraw, as it's intercepted by the video card and uses its capabilities fully. GDI+ is suitable only for drawings that don't need speed.
About the frame rate, you're right: I divided 1000 ms / 60 and I don't know why I got 160ms, when I should get 16ms. Probably a typo on calculator
Yes, even I am blogging now!
|
|
|
|
|
I was being such a Schmuck. I was rendering to the bitmap and then setting it to the image... no wonder it crippled my drawing process.
I'm now rendering to a bitmap and flipping it to a graphics object derived from the window handle. I've added a few dozen objects to the screen and it's still taking only 16ms to render.
There are however a few issues with the regular jump to 32ms, which is still frustrating. I've tried adding a GC.Collect() command after each graphics itteration to ease things out, and that worked a bit, but i've also had to add a 10ms wait on the rendering loop to finish the smoothing, anything else and it still jumps regularly occasionaly.
|
|
|
|
|
The Catalyst wrote:
ut i've also had to add a 10ms wait on the rendering loop to finish the smoothing,
Sorry, but I don't understand: why do you need this delay? Aren't you just invalidating the picture control?
About the delays, it's hard to predict what's going on in a GC environment. Beware that adding GC.Collect() to a loop may do more harm than good to time predictability: it may move objects to Gen 2 too soon, and increase the delays, instead of reducing them.
Yes, even I am blogging now!
|
|
|
|
|
Hi
I got a little Form with a Textbox. With a Barcode Scanner I
put a Database ID into this Textbox. By onclick the Button "Show"
the DatabaseRecord will be shown in a new Form. It works great.
But I think the user should not click a Button. It's too much work
So I made a TextCahanged Event on this Textbox. The Scanner read the
Barcode and the Record should be shown. But it don't work! Why??
This is for the Button:
private void btnShow_Click(object sender, System.EventArgs e)
{
string id = this.textBoxScan.Text;
frmShow x = new frmShow(id);
x.Show();
this.textBoxScan.Text="";
}
This for the TextChanged:
private void textBoxScan_TextChanged(object sender, System.EventArgs e)
{
string id = this.textBoxScan.Text;
frmShow x = new frmShow(id);
x.Show();
this.textBoxScan.Text="";
}
And this happens on the second Form:
public frmShow(string id)
{
InitializeComponent();
string x = null;
x = id;
dc.Connection(System.Convert.ToInt32(x));
fnGetDataBindingForTextBoxes();
}
dc is an Instance from the Connection Class.
|
|
|
|
|
Don't know why the TextChanged event handler didn't work (maybe it's not submitted correctly.?).
Anyway, as you want to automatically show the second form after reading with the Barcode scanner in my opinion the textbox is pretty useless, because you write a value to it and in the TextChanged event show your form and clear the textbox. So why not showing the form directly after reading from the scanner.
Besides, you should dispose your form after using it, so the resources get cleaned up. Or use the using statement as shown by the following code snippet:
using(frmShow x = new frmShow(id))
{
x.Show();
}
www.troschuetz.de
|
|
|
|
|
But how can I call an Application or Form by only scanning a Barcode?
It's only an low Cost Scanner. During Debugging my App. a green Arrow
appears in the Solution Explorer of the second Form. The Message is
that the Code have called another Function. When this Function is done,
the next one will be called.
The mark the following row..
dc.Connection(System.Convert.ToInt32(x));
|
|
|
|
|
In your first post you wrote: "I got a little Form with a Textbox. With a Barcode Scanner I put a Database ID into this Textbox."
Thought you already do the latter in your application, so that instead of putting the Database ID into the textbox and catching the TextChanged event to open an extra form you could directly open the extra form.
Or what exactly do you mean with the phrase: "With a Barcode Scanner I put a Database ID into this Textbox."
www.troschuetz.de
|
|
|
|
|
The Cursor is set in the TextBox. I read the Barcode and the Value
appears in the TextBox. Submit the Button and the new Form, that includes
the Record, will be open. The Barcode was created from a Database ID.
ID 222 -> create a Barcode from 222 -> print a label with the Barcode
and put it on Hardware. If the Hardware is defected, we want to audit wether
Warranty is given.
|
|
|
|
|
Does your BarCode scanner send an ENTER key after the code? Most scanners can be configured to send a termination character after the code. If not, the TextChanged event won't fire until the user hits enter in the TextBox or, like in your case, clicks a button to do it.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I got it.. I think so..
I can not clean the TextBox when I use the TextChanged Event.
this.textBoxScan.Text="";
When I delete this row from my Code it works. But I need
an empty TextBox.Ahrgggg...
|
|
|
|
|
You could unsubscribe the TextChanged event handler before cleaning the TextBox and then resubscribe it afterwards.
www.troschuetz.de
|
|
|
|
|
Does somebody know how to create an array of textboxes with the designer?
Please reply, if you know the answer. Thank you very much.
|
|
|
|
|
OK lets say that I have a very big DB and I want to put it in a grid now when i load the app it takes very long how can i fix that or if is not fixable how can i make a progress bar incrementing while it loads?
The second problem is that all records are in the grid and when i try to filter the grid by some values writen in an edit box again it take long to filter?
Thx
|
|
|
|
|