Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 30th, 2003, 12:24 AM
Registered User
 
Join Date: Jul 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Spawning a VB EXE from another EXE

I am running into a problem where I am passing COM interface pointers from one EXE process into another (VB) EXE process. In turn, this VB EXE is spawning my ATL based dll - supplying my dll with the COM interface pointers that originated in another EXE. There seems to be a marshalling problem, since some of the interface pointers are viewed as NULL by my dll. Whereas, if my parent VB component is built as a dll rather than as a Active X EXE - everything works fine (no NULL interface pointers).

Any ideas on how I can resolve this problem?

Thank you.
Alan

 
Old July 30th, 2003, 04:52 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

I think the problem is that EXEs run in their own memory space. The interface pointers are relative to the memory space of the EXE that creates them, so when you pass them to another EXE they no longer point to the same place (because they are then assumed to be relative to the 2nd EXE). That would explain why it works from a DLL (DLLs run in the same memory space as the caller).

To solve it you would need to find the offset too, so you could point from the 2nd EXE into the memory space of the 1st EXE.

All sounds a bit iffy to me...can't you get the interfaces directly in your ATL DLL without having to pass in an explicit pointer?

rgds
Phil
 
Old July 30th, 2003, 07:25 AM
Registered User
 
Join Date: Jul 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Phil

Thanks for your reply. I am not sure how one goes about finding the "offset pointers" as you indicated. The explicit pointers are required since they point to data that is contained by the originating EXE.

Alan

 
Old July 30th, 2003, 07:59 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Well I'm not sure how you can do this stuff using VB (which uses Single Threaded Apartment model) but maybe look at this article for starters:
http://msdn.microsoft.com/library/en...nthrd_68s3.asp
Quote:
quote:
If one apartment (Apartment 1) in a process has an interface pointer and another apartment (Apartment 2) requires its use, Apartment 1 must call CoMarshalInterThreadInterfaceInStream to marshal the interface. The stream that is created by this function is thread-safe and must be stored in a variable that is accessible by Apartment 2. Apartment 2 must pass this stream to CoGetInterfaceAndReleaseStream to unmarshal the interface and will get back a pointer to a proxy through which it can access the interface. The main apartment must remain alive until the client has completed all COM work (because some in-process objects are loaded in the main apartment, as described in In-Process Server Threading Issues). After one object has been passed between threads in this manner, it is very easy to pass interface pointers as parameters. That way, distributed COM does the marshaling and thread switching for the application.
hth
Phil





Similar Threads
Thread Thread Starter Forum Replies Last Post
Error spawning cl.exe TypX BOOK: Beginning Visual C++ 6 8 September 25th, 2009 05:44 PM
Membership: aspnet_sql.exe -> aspnet_regsql.exe ricpue BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 August 9th, 2006 11:40 PM
problem creating .exe from MFC AppWizard(exe) c++ method Visual C++ 0 July 7th, 2006 03:28 AM
PHP5 and php.exe php-cgi.exe php-win.exe freddo Beginning PHP 1 August 16th, 2004 09:28 AM
VB Exe triggering another EXE moiyed Beginning VB 6 2 November 6th, 2003 11:48 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.