Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / September 2003

Tip: Looking for answers? Try searching our database.

CCW problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alexander Paar - 08 Sep 2003 19:05 GMT
I successfully exported the following C# class and its method to COM.

namespace SRCSN
{
   [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
   public interface _SRCSAux
   {
       void DisplayDLLInfo();
   }

   [ClassInterface(ClassInterfaceType.None)]
   public class SRCSAux : _SRCSAux
   {
       public SRCSAux()
       {
       }

       public void DisplayDLLInfo()
       {
           MessageBox.Show("Hello World!");
       }
   }
}

Everything works fine when I call DisplayDLLInfo()
from an unmanaged MFC application as follows.

#import "C:\...\bin\Debug\SRCSN.tlb"
using namespace SRCSN;

SRCSN::_SRCSAuxPtr com_ptr;
CoInitialize(NULL);
SRCSN::_SRCSAuxPtr p(__uuidof(SRCSN::SRCSAux));            // OK
com_ptr = p;
com_ptr->DisplayDLLInfo();
// OK

However, exactly the same code throws an exception when executed
within an exported function in an unmanaged C++ DLL.

#define DLLExport extern "C" _declspec(dllexport)
#import "C:\...\bin\Debug\SRCSN.tlb"
using namespace SRCSN;

DLLExport BOOL Func()
{
   AFX_MANAGE_STATE(AfxGetStaticModuleState());
   SRCSN::_SRCSAuxPtr com_ptr;
   CoInitialize(NULL);
   SRCSN::_SRCSAuxPtr p(__uuidof(SRCSN::SRCSAux));        // EXCEPTION :-(
   com_ptr = p;
   com_ptr->DisplayDLLInfo();
}

What's the problem with SRCSN::_SRCSAuxPtr p(__uuidof(SRCSN::SRCSAux)) ?

Any help would be greatly appreciated.

TIA,
-Alex
Alexander Paar - 09 Sep 2003 10:05 GMT
I nailed down the problem a little bit more.

I can call the CCW from an unmanaged MFC application and from an unmanaged
C++ DLL (using MFC) if and only if this DLL has been called from the
unmanaged MFC application. Does it matter _who_ called the unmanaged DLL
that employs my CCW?

-Alex

> I successfully exported the following C# class and its method to COM.
>
[quoted text clipped - 57 lines]
> TIA,
> -Alex

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.