By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,219 Members | 2,423 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,219 IT Pros & Developers. It's quick & easy.

Small Problem with Type Casting

P: n/a
Okay, here's my calling code:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
mdiClient = New MDIClientWindow(Me, Me.Handle) '**
SetClassLong(mdiClient.Handle, GCL_HBRBACKGROUND, 0)
End Sub ' End Form1_Load

Here's the Code Being Called:

Public Sub New(ByVal i As IMDIClientNotify, ByVal handle As IntPtr)
'Find the MDI Client window handle:
GetWindows(handle)
If Not hWndMdiClient.ToInt32 = IntPtr.Zero.ToInt32 Then
MyBase.AssignHandle(hWndMdiClient)
End If
notify = i
End Sub ' End Sub New

And here is the Interface:

Public Interface IMDIClientNotify
Sub WndProc(ByRef m As Message, ByRef doDefault As Boolean)
End Interface

Here's the origional C# code for the above functions:

private void mfrmMDIClientPaint_Load(object sender, System.EventArgs e)
{
// Start processing for MDIClient window messages:
mdiClient = new MDIClientWindow(this, this.Handle);
// Stop the default window proc from drawing the MDI background
// with the brush:
UnManagedMethods.SetClassLong(
mdiClient.Handle,
UnManagedMethods.GCL_HBRBACKGROUND,
0);
}

public MDIClientWindow(IMDIClientNotify i, IntPtr handle)
{
// Find the MDI Client window handle:
GetWindows(handle);
if (hWndMdiClient != IntPtr.Zero)
{
this.AssignHandle(hWndMdiClient);
}
this.notify = i;
}

public interface IMDIClientNotify
{
void WndProc(ref Message m, ref bool doDefault);
}

The '** Mark is where things go heywire!

"Additional information: Specified cast is not valid." is the exact error
that comes up, if that helps...

Thanks again,
Sueffel
Nov 20 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
"Tibby" <Bl**@rent.com> schrieb
mdiClient = New MDIClientWindow(Me, Me.Handle) '**
The '** Mark is where things go heywire!

"Additional information: Specified cast is not valid." is the exact error
that comes up, if that helps...


What is the full message? What are the source and destination types of the
cast? What's the type of mdiClient? Is it "MDIClientWindow" or one of it's
base classes? Did you enable Option Strict?
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2

P: n/a

"Armin Zingler" <az*******@freenet.de> wrote in message
news:u6*************@TK2MSFTNGP11.phx.gbl...
"Tibby" <Bl**@rent.com> schrieb
mdiClient = New MDIClientWindow(Me, Me.Handle) '**


The '** Mark is where things go heywire!

"Additional information: Specified cast is not valid." is the exact error that comes up, if that helps...


What is the full message? What are the source and destination types of the
cast? What's the type of mdiClient? Is it "MDIClientWindow" or one of it's
base classes? Did you enable Option Strict?
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


Okay, the zip file is at http://www.tiberiansun.us/Test.zip

Sueffel
Nov 20 '05 #3

P: n/a

"Armin Zingler" <az*******@freenet.de> wrote in message
news:u6*************@TK2MSFTNGP11.phx.gbl...
"Tibby" <Bl**@rent.com> schrieb
mdiClient = New MDIClientWindow(Me, Me.Handle) '**


The '** Mark is where things go heywire!

"Additional information: Specified cast is not valid." is the exact error that comes up, if that helps...


What is the full message? What are the source and destination types of the
cast? What's the type of mdiClient? Is it "MDIClientWindow" or one of it's
base classes? Did you enable Option Strict?
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


Not sure if I can answer those questions, I'm flying blind as is! LOL
But, I can zip up the project and attach it here. I do know that option
strict is off at the moment. I know how much people love it when there's
binary data attached to a thread. But anyhew, I'm trying to implement this
as a nifty to take away the boring MDI Interface and make it look a little
more snatzy.

Thanks again,
Sueffel


Nov 20 '05 #4

P: n/a
"Sueffel" <so*****@somewhere.com> schrieb


Okay, the zip file is at http://www.tiberiansun.us/Test.zip


You did not enable Option Strict!

You get the exception because Form1 does not implement IMDIClientNotify.
Implement the interface and the project will be compilable (after removing
the other two errors).
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #5

P: n/a

"Armin Zingler" <az*******@freenet.de> wrote in message
news:eN**************@TK2MSFTNGP10.phx.gbl...
"Sueffel" <so*****@somewhere.com> schrieb


Okay, the zip file is at http://www.tiberiansun.us/Test.zip


You did not enable Option Strict!

You get the exception because Form1 does not implement IMDIClientNotify.
Implement the interface and the project will be compilable (after removing
the other two errors).
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


That was the one thing I was missing, the implementation! Thank you
sooooooo much! No I just have to figure out the PInvoke Errors and I'm good
to go!

Thanks again,
Tibby

PS - Sorry bout the Option Strict, I have a long time aversion to it.
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.558 / Virus Database: 350 - Release Date: 1/2/2004
Nov 20 '05 #6

P: n/a

"Sueffel" <so*****@somewhere.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...

"Armin Zingler" <az*******@freenet.de> wrote in message
news:eN**************@TK2MSFTNGP10.phx.gbl...
"Sueffel" <so*****@somewhere.com> schrieb
>

Okay, the zip file is at http://www.tiberiansun.us/Test.zip
You did not enable Option Strict!

You get the exception because Form1 does not implement IMDIClientNotify.
Implement the interface and the project will be compilable (after removing the other two errors).
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


That was the one thing I was missing, the implementation! Thank you
sooooooo much! No I just have to figure out the PInvoke Errors and I'm

good to go!

Thanks again,
Tibby

PS - Sorry bout the Option Strict, I have a long time aversion to it.
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.558 / Virus Database: 350 - Release Date: 1/2/2004


BTW, how can I trap a "Unhandled exception of type
'System.StackOverflowException' occured in system.dll" ? I know that that
one has something to do with circular reference, but I'm not seeing it...
*sigh* All kinds of nifty errors with this code. Unfortunatly, I don't have
the time to "Learn" what is going on, so I may have to scrap this project
:(

Thanks again
Sueffel
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.558 / Virus Database: 350 - Release Date: 1/2/2004
Nov 20 '05 #7

P: n/a
"Sueffel" <so*****@somewhere.com> schrieb
That was the one thing I was missing, the implementation! Thank
you sooooooo much! No I just have to figure out the PInvoke Errors
and I'm good to go!

....and:
Why do you need pInvoke here? Native window sub classing is often not
necessary anymore. You can override WndProc.
--
Armin

Nov 20 '05 #8

P: n/a

"Armin Zingler" <az*******@freenet.de> wrote in message
news:OH**************@TK2MSFTNGP09.phx.gbl...
"Sueffel" <so*****@somewhere.com> schrieb
That was the one thing I was missing, the implementation! Thank
you sooooooo much! No I just have to figure out the PInvoke Errors
and I'm good to go!

...and:
Why do you need pInvoke here? Native window sub classing is often not
necessary anymore. You can override WndProc.
--
Armin


API Calls... That is the example that was shown to me.... I'm not spiffey
with graphics, try to avoid them if possible actually, but I just thought it
would be a nice touch to the GUI, but I do have time contraints and can go
back later and insitute it.... Or maybe just take the origional C# code,
throw it into a DLL, and inherit from that.?.?. That may not work. Hmmmmmm

Thanks agian,
Sueffel
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.558 / Virus Database: 350 - Release Date: 1/2/2004
Nov 20 '05 #9

P: n/a
"Armin Zingler" <az*******@freenet.de> schrieb
...and:
Why do you need pInvoke here? Native window sub classing is often
not necessary anymore. You can override WndProc.


Ignore my message... you do override windproc.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.