473,800 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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;
ProcessStartInf o startInfo = new ProcessStartInf o();
startInfo.FileN ame = this.exeName;
startInfo.Windo wStyle = ProcessWindowSt yle.Normal;
p = Process.Start(t his.exeName);

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

appWin = p.MainWindowHan dle;

//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_OVERLAPPEDWI NDOW;
SetWindowLongA( appWin, GWL_STYLE, newResult);

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

//Move the child window within the parent window
MoveWindow(appW in, 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 4436
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
5995
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 exception of type 'System.ExecutionEngineException' occurred in system.windows.forms.dll Anyone know how to either trap these errors or prevent them from happening?
1
545
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 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...
1
3455
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 going wrong. The program has been written to do the following tasks: - Select remote server - Select from two specific services
3
5750
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 | LVS_REPORT, 300, 100, 100, 100, hWnd, NULL, NULL, NULL); However, I want to create the control with no parent, then add it to the parent form later. Something like this...
4
4185
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 check to see if the status is in stopped or running mode. But that doesn't tell me if it is actually running. I need to know this so that if it happens I can programmatically start the same service on another machine.
6
7876
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 by the function) in main. However, I am getting a segmentation fault. Here is the code: (Please note, the size is fixed in this code, but in my code where I am actually going to use this, the size of the array is not known until you get to the...
0
1606
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, once SetParent() is used, the menu strip on the plugin ceases to function: It will no longer drop down the menu list once it is selected.
1
1605
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 SEARCH function is a dummy text box and doesn't work (apparently I have to pay much more to get it to work). I want to get it to work, but I am unsure how to do it on my own, hopefully nothing too complicated. The banner is in FLASH, so I am...
7
7343
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 happen, the code looks like this: / Remove border and whatnot long style = GetWindowLong(appWin, GWL_STYLE); long new_style = WS_CHILD | WS_VISIBLE;
0
1549
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). By using last error code, its gives 1400 (Means Invalid Handle). I check that handle of toolbar and handle of new parent are valid, but previous parent of toolbar handle has been invalid. Now i want to assign new parent of toolbar but SetParent...
0
9551
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10275
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10253
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5471
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.