473,325 Members | 2,870 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,325 software developers and data experts.

SetParent Windows API function notworking with VB 6 forms

I have a requirement where I need to embed a VB 6 forms application into .Net
forms application. Basically the new .Net application would act as a wrapper
application and would control the embedded VB 6 application.

I tried to start the VB 6 in a separate process from dot net app and
acquired the handle of the handle to the main window of the process.

Next I used to use Win32 API function SetParent to set the parent of the VB
6 application window to the dot net application window.

But when I run the dot net app, it creates the VB 6 app and window is
launched. But the SetParent does not work as the VB 6 app window stays
separately outside the dot net app window.

I have pasted the code below for better clarity:
//Creating VB 6 app process
Process p = null;
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = this.exeName;
startInfo.WindowStyle = ProcessWindowStyle.Normal;
p = Process.Start(this.exeName);

//Waiting till the VB 6 process finishes its execution
p.WaitForInputIdle();

appWin = p.MainWindowHandle;

//Change the window attributes of the VB 6 app so that it can become a
//child window to another window...
long result = GetWindowLongA(appWin, GWL_STYLE);
long newResult = result | WS_CHILD | WS_OVERLAPPEDWINDOW;
SetWindowLongA(appWin, GWL_STYLE, newResult);

//Use SetParent for changing the parent...
IntPtr a = SetParent(appWin, this.Handle);

//Move the child window within the parent window
MoveWindow(appWin, 0, 0, this.Width, this.Height, true);

This method works roughly for embedding app window in another dot net
application. But do not work for the embedding a VB 6 app window.

What am I missing here?
Nov 22 '05 #1
1 4390
I tried to start the VB 6 in a separate process from dot net app and
acquired the handle of the handle to the main window of the process.

Next I used to use Win32 API function SetParent to set the parent of the VB
6 application window to the dot net application window.


SetParent is only meant to be used with windows in the same process.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 22 '05 #2

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

Similar topics

1
by: gregory_may | last post by:
This code seems to "work" but I get the following errors: An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll then this one: An unhandled...
1
by: Raghavendran Muraleetharan | last post by:
I have a requirement where I need to embed a VB 6 forms application into .Net forms application. Basically the new .Net application would act as a wrapper application and would control the embedded...
1
by: Scott Davies | last post by:
Hi, I'm looking for some help on a small program that I'm trying to develop in VB.NET. I'm having trouble getting the code that I've written to work, can anyone shed some light as to where I'm...
3
by: miben | last post by:
I am creating a ListView through CreateWindowEx(). It works fine when I create it as a child window as so: hControl = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEW, NULL, WS_VISIBLE | WS_CHILD |...
4
by: tshad | last post by:
What would be a good way to check programmatically whether a service was running? We have a service that dies periodically and I need to check to see if this service is running. I know how to...
6
by: Kiran | last post by:
Hi all, What I am trying to do is to pass a pointer to the first element of an array to a function, modify it in that function, and then print out the values of the array (which has been modified...
0
by: clarionprogrammer | last post by:
Problem info: 1. My application runs in AppDomain1. 2. My plugin runs in AppDomain2. I am able to place the plugin form inside an application panel via the SetParent() API call. However,...
1
by: David De | last post by:
Need help with my site - search function within my site not working?!? I purchased this template, customized it and found out it has a search function for within the site - the challenge is that...
7
by: Matt | last post by:
Hello to all, I'm having something of a problem with the WinAPI call SetParent. Here's the scenario. I am trying to take an existing program, and run it within my own window. I can make this...
0
by: ramveers | last post by:
I ma creating a toolbar for IE. I am setting a parent of toolbar dynamically by using SetParent method of window API. My problem is that SetParent method does not set parent and return zero(IntPtr)....
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.