473,387 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

PostMessage to VB.NET messageloop

SM
Hello group,
i'm converting a VB6 application for .NET Framework.
The application depends on a DLL written in standard C.

The C DLL code creates an invisible window with CreateWindow()
with the WndProc function located into the VB.NET code.

Until the code was VB6/C code, they was OK.

Now the VB WndProc receives the startup message correctly
(WM_NCCREATE - WM_CREATE - WM_SIZE - .....)
but when i send (from the C code) custom messages (or
whatever kind of message) with PostMessage(....), using
as handle the same one returned from CreateWindow(..),
the WndProc doesn't receive them ....
I see this messages with Spy++ and all the parameters are OK.

What's the problem ?
Can i still use PostMessage() from C code to send a message
to .NET WndProc function ? I need to leave untouched the DLL ..

Thanks
--
Stefano M
email: *@*
(remove *)

Nov 20 '05 #1
6 4734
Hi Stefano,

I probably can't get you. Let's try to broke it all down into smaller
pieces.

1. A C DLL that creates an invisible window and contains a message loop for
that window,
2. A VB .NET WinForms application that can receive WM_xxx messages from the
invisible window.
3. The VB .NET app's main window handle is somehow passed to the DLL.

The problem is that you can't get the right window handle for the VB .NET's
application main window?
Well, Form.Handle should be the property returing the right handle value
(you might need to call its ToInt32() method depending on how you have
declared the DLL's functions in VB .NET).

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"SM" <st**********@hotmail.com> wrote in message
news:u1**************@tk2msftngp13.phx.gbl...
Hello group,
i'm converting a VB6 application for .NET Framework.
The application depends on a DLL written in standard C.

The C DLL code creates an invisible window with CreateWindow()
with the WndProc function located into the VB.NET code.

Until the code was VB6/C code, they was OK.

Now the VB WndProc receives the startup message correctly
(WM_NCCREATE - WM_CREATE - WM_SIZE - .....)
but when i send (from the C code) custom messages (or
whatever kind of message) with PostMessage(....), using
as handle the same one returned from CreateWindow(..),
the WndProc doesn't receive them ....
I see this messages with Spy++ and all the parameters are OK.

What's the problem ?
Can i still use PostMessage() from C code to send a message
to .NET WndProc function ? I need to leave untouched the DLL ..

Thanks
--
Stefano M
email: *@*
(remove *)


Nov 20 '05 #2
Hi Dmitriy,
i try to explain better, i know it is a little complex.. :-)

1. VB .NET application makes a call to C DLL function. One of the function
parameters is a pointer to a VB.NET function.
2. In this C DLL function, the code creates an invisible window with
CreateWindow() using for the message loop the function pointer passed.
3. C DLL saves the window handle in a DLL global variable for future uses
4. C DLL function sends a PostMessage( saved_handle, WM_custom, xx, yy) but this
message is never received from VB.NET function (the message is visible with
Spy++)
5. Even if C DLL sends a message (custom or standard) just after the
CreateWindow(..), VB.NET function never receive it.
6. VB.NET message loop receives startup standard messages as WM_CREATE, WM_SIZE,
WM_MOVE,
.....

Thanks
--
Stefano M
email: *@*
(remove *)

Nov 20 '05 #3
Stefano,
2. In this C DLL function, the code creates an invisible window with
CreateWindow() using for the message loop the function pointer passed.
3. C DLL saves the window handle in a DLL global variable for future uses
4. C DLL function sends a PostMessage( saved_handle, WM_custom, xx, yy) but this message is never received from VB.NET function (the message is visible with Spy++)
It is not clear why should the VB .NET callback receive the message in the
first place? Is this VB .NET function actually a window procedure? If yes, I
would advice to pay maximum attention on HOW do you pass the function
pointer to the C DLL. Ensure you specify the right calling convention
(WINAPI that is), and that all parameters will be marshalled properly.

Then, it's not clear what is meant under "the message is never received". If
you would post some standard message, would it be received by the VB .NET
procedure? Does it gets called at all?

I am just trying to focus on the root of the problem, so please be patient
to tons of my questions :-)

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Ste M" <st**********@hotmail.com> wrote in message
news:bp**********@fata.cs.interbusiness.it... Hi Dmitriy,
i try to explain better, i know it is a little complex.. :-)

1. VB .NET application makes a call to C DLL function. One of the function
parameters is a pointer to a VB.NET function.
2. In this C DLL function, the code creates an invisible window with
CreateWindow() using for the message loop the function pointer passed.
3. C DLL saves the window handle in a DLL global variable for future uses
4. C DLL function sends a PostMessage( saved_handle, WM_custom, xx, yy) but this message is never received from VB.NET function (the message is visible with Spy++)
5. Even if C DLL sends a message (custom or standard) just after the
CreateWindow(..), VB.NET function never receive it.
6. VB.NET message loop receives startup standard messages as WM_CREATE, WM_SIZE, WM_MOVE,
....

Thanks
--
Stefano M
email: *@*
(remove *)


Nov 20 '05 #4
SM
Dmitriy,
thanks again for your attention,
It is not clear why should the VB .NET callback receive the message in the
first place? Is this VB .NET function actually a window procedure? If yes, I
would advice to pay maximum attention on HOW do you pass the function
pointer to the C DLL. Ensure you specify the right calling convention
(WINAPI that is), and that all parameters will be marshalled properly.
Yes, it is a window procedure for the window created into the C DLL.
OK, i'll re-check all the parameters .... but i think if the address was wrong,
i should have a crash !!
Then, it's not clear what is meant under "the message is never received". If
you would post some standard message, would it be received by the VB .NET
procedure? Does it gets called at all?
The VB.NET window procedure receives all the standard messages fired
(internally) from the CreateWindow() call.
When i explicitly want to post a message (custom or not) to the invisible window
from my DLL code,
i think the message will be sent to its window procedure but the .NET window
procedure is not fired !
I am just trying to focus on the root of the problem, so please be patient
to tons of my questions :-)


Oh, don't worry !!! I understand that is not a clear architecture but
i'm migrating from an existent situation (VB6+C DLL), this
situation was created from previous programmer and I'm trying
to leave untouched the just-tested DLL. Maybe in the future I'll
have time to re-write also the DLL.....

Thanks a lot !
--
Stefano M
email: *@*
(remove *)

Nov 20 '05 #5
> The VB.NET window procedure receives all the standard messages fired
(internally) from the CreateWindow() call.
When i explicitly want to post a message (custom or not) to the invisible window from my DLL code,
i think the message will be sent to its window procedure but the .NET window procedure is not fired !
A-ha, now it's much more clear. So my suggestions are:

1. Check the custom message is registered (I believe there's an API function
to do that). Not sure the receiving party should also register the custom
message though.

2. The PostMessage function has some difficulties with marshalling custom
messages. Not sure what they meant in MSDN but here's the quote:

=== Cut ===
The system only does marshalling for system messages (those in the range 0
to WM_USER). To send other messages (those above WM_USER) to another
process, you must do custom marshalling.
=== Cut ===

I'd also suggest asking the more detailed question in the
dotnet.framework.interop newsgroup as it seems to be not related to the VB
..NET lanugage itself.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"SM" <st**********@hotmail.com> wrote in message
news:ue**************@TK2MSFTNGP12.phx.gbl... Dmitriy,
thanks again for your attention,
It is not clear why should the VB .NET callback receive the message in the first place? Is this VB .NET function actually a window procedure? If yes, I would advice to pay maximum attention on HOW do you pass the function
pointer to the C DLL. Ensure you specify the right calling convention
(WINAPI that is), and that all parameters will be marshalled properly.
Yes, it is a window procedure for the window created into the C DLL.
OK, i'll re-check all the parameters .... but i think if the address was

wrong, i should have a crash !!
Then, it's not clear what is meant under "the message is never received". If you would post some standard message, would it be received by the VB ..NET procedure? Does it gets called at all?
The VB.NET window procedure receives all the standard messages fired
(internally) from the CreateWindow() call.
When i explicitly want to post a message (custom or not) to the invisible

window from my DLL code,
i think the message will be sent to its window procedure but the .NET window procedure is not fired !
I am just trying to focus on the root of the problem, so please be patient to tons of my questions :-)


Oh, don't worry !!! I understand that is not a clear architecture but
i'm migrating from an existent situation (VB6+C DLL), this
situation was created from previous programmer and I'm trying
to leave untouched the just-tested DLL. Maybe in the future I'll
have time to re-write also the DLL.....

Thanks a lot !
--
Stefano M
email: *@*
(remove *)


Nov 20 '05 #6
How are you declaring the delegate that is being passed in to the dll for
the Window procedure? If you are not keeping a reference to the delegate it
will be garbage collected.

"SM" <st**********@hotmail.com> wrote in message
news:u1**************@tk2msftngp13.phx.gbl...
Hello group,
i'm converting a VB6 application for .NET Framework.
The application depends on a DLL written in standard C.

The C DLL code creates an invisible window with CreateWindow()
with the WndProc function located into the VB.NET code.

Until the code was VB6/C code, they was OK.

Now the VB WndProc receives the startup message correctly
(WM_NCCREATE - WM_CREATE - WM_SIZE - .....)
but when i send (from the C code) custom messages (or
whatever kind of message) with PostMessage(....), using
as handle the same one returned from CreateWindow(..),
the WndProc doesn't receive them ....
I see this messages with Spy++ and all the parameters are OK.

What's the problem ?
Can i still use PostMessage() from C code to send a message
to .NET WndProc function ? I need to leave untouched the DLL ..

Thanks
--
Stefano M
email: *@*
(remove *)

Nov 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Paul | last post by:
Hi all. Probably a quick one, I'm using PostMessage to send keys to an applicatoin but how do I convert the key string to a long values so that I can pass this to the wParam. The definition is...
15
by: James | last post by:
In my code I have a problem in abtaining a windows handle. I do not know the namespace to obtain the windows hanle. here is the code. using System; using System.Collections; using...
12
by: Wilfried Mestdagh | last post by:
Hi, Using P/Invoke I use PostMessage to send a message from one thread to another. I'm pretty sure this has already worked in dotnet. but I've upgraded version 2 few day ago. Now I have an...
2
by: Lenster | last post by:
When using PostMessage to post myself a message, the msg and wparam parameters somehow get swapped over. They are in the correct order when calling PostMessage but by the time wndproc handles the...
3
by: Max M. Power | last post by:
When I use the SendMessage API I can sucessfully send and receive a user defined message. When I use the PostMessage API I can NOT sucessfully send and receive the same user defined message. ...
3
by: knikkix | last post by:
Hi, I created a form in VB.Net with only one button. This is the code in button click event Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles...
10
by: Sergei | last post by:
Can anyone explain why PostMessage to a Windows Form is considered unsafe and raises InvalidOperationException? I can get rid of that setting CheckForIllegalCrossThreadCalls to false and...
21
by: one2001boy | last post by:
PostMessage() function returns ERROR_NOT_ENOUGH_QUOTA after running in a loop for 700 times, but the disk space and memory are still big enough. any suggestion to resolve this problem? thanks.
0
Plater
by: Plater | last post by:
I have been trying to access a messageloop without opening a form. That is, I want to be able to receive messages from other applications through the message loop without having a form. I've read...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.