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 / Languages / Managed C++ / October 2004

Tip: Looking for answers? Try searching our database.

accessing reference parameter in managed C++ from C#

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
sklett - 19 Oct 2004 22:38 GMT
STILL trying to wrap an unmanaged C++ class that is itself a wrapper to some
COM stuff, not sure, it is littered with LPDISPATCH and InvokeHelper, etc.

Problem is, when something goes wrong, I'm having a hard time debugging.

In my managed C++ class(the one wrapping the unmanaged C++) I have a method
that looks like this:
bool FindFileItem(String* filename, IVSSItem& founditem);

that method calls the unmanaged method:
bool FindFileItem(PCSTR filename, IVSSItem& founditem);

identical.  When I call the managed method from my C# code, the IVSSItem&
reference is a pointer (intellisense says that I need to specify a
IVSSItem*)

I suspect somewhere in here is where my crash is originating.  I can avoid
the crash by created an IVSSItem object in the body of my unmanaged method
and assign to it rather than the IVSSItem reference.

I really am in over my head.  Once I get this wrapper class to behave, I can
move past all this and get back to C# only, but for now I'm stuck here.
Does anyone have any clues or hints for me?

Thanks for any help.

Just in case, I have posted the relevant code below:

------- C# code that calls managed C++ wrapper class --------
private bool AssetExists(string extension, ref string filename)

{

   unsafe

   {

       IVSSItem    item;

       if(sourceSafe.FindFileItem(filePath, &item) == true)

       {

           return true;

       }

   }

   return false;

}

------  Managed C++ code that wraps the unmanaged C++ code -------

bool CSUSSWrapper::FindFileItem(String* filename, IVSSItem& founditem)

{

     char* pFilename =
(char*)(void*)Marshal::StringToHGlobalAnsi(filename);

     bool result     = m_objSourceSafe->FindFileItem(pFilename, founditem);

     Marshal::FreeHGlobal(pFilename);

     return result;

}
sklett - 19 Oct 2004 23:15 GMT
The crash is moving around , but it happens on this line often:
IVSSItem(const IVSSItem& dispatchSrc) : COleDispatchDriver(dispatchSrc) {}

With this error:
An unhandled exception of type 'System.NullReferenceException' occurred in
suabwrapper.dll

Additional information: Object reference not set to an instance of an
object.

> STILL trying to wrap an unmanaged C++ class that is itself a wrapper to some
> COM stuff, not sure, it is littered with LPDISPATCH and InvokeHelper, etc.
[quoted text clipped - 65 lines]
>
> }

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.