accessing reference parameter in managed C++ from C#

S

sklett

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;

}
 
S

sklett

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top