473,387 Members | 3,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

accessing reference parameter in managed C++ from C#

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(filenam e);
bool result = m_objSourceSafe->FindFileItem(pFilename, founditem);


Marshal::FreeHGlobal(pFilename);
return result;

}




Nov 17 '05 #1
1 3020
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.

"sklett" <as***@asdfasdfsd.com> wrote in message
news:us**************@TK2MSFTNGP14.phx.gbl...
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(filenam e);
bool result = m_objSourceSafe->FindFileItem(pFilename, founditem);

Marshal::FreeHGlobal(pFilename);
return result;

}





Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Dmitry | last post by:
Hi, I have defined interface for COM components which inludes an argument being filled with additional error info, if such occurs. If inside I raise COM Error, I populate that parameter. In COM...
16
by: Ekim | last post by:
hello, I'm allocating a byte-Array in C# with byte byteArray = new byte; Now I want to pass this byte-Array to a managed C++-function by reference, so that I'm able to change the content of the...
7
by: Gilad Walden | last post by:
I use C# in .NET framework. I have an ActiveX implemented in C++ that has a COM interface method that gets as it’s out parameter a BSTR* . The interop translates this BSTR* into C# string. From...
3
by: simon.duvall | last post by:
Hey all, Was referencing various COMs, and tried using the Windows Genuine Advantage 1.0 Type Library. There's a cool method called GetMachineDetails() that I wanted to try, but for some...
1
by: Frustrated | last post by:
Since C# and VB.NET are similar, I am posting this here also I have a C++ DLL that I need to access from VB.NET or C#. The following is my attempt via VB.NET. The function I am trying to call...
1
by: omantawy | last post by:
Hi, I have some legacy ASP web applications that use an unmanaged COM component to connect to a third party application. The third part application has moved to the managed code in the current...
10
by: amazon | last post by:
Our vender provided us a web service: 1xyztest.xsd file... ------------------------------------ postEvent PostEventRequest ------------------------------------- authetication authentication...
7
by: David Lowndes | last post by:
The following example illustrates something that's taken me a while to suss out (debugging someone else's code :( )... The crux is that the code compiles cleanly at W4, and the issue is that I'm...
15
by: arnuld | last post by:
-------- PROGRAMME ----------- /* Stroustrup, 5.6 Structures STATEMENT: this programmes *tries* to do do this in 3 parts: 1.) it creates a "struct", named "jd", of type "address". 2. it...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.