473,586 Members | 2,870 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

calling C++ method from C# code - 2nd attempt

I'm having a really hard time with wrapping an unmanaged class with a
managed class, then calling that managed class from my C# code.

I will show you the three pieces, then explain:
-------- Unmanaged C++ code ---------
bool FindFileItem(PC STR filename, IVSSItem& founditem); // note that
founditem is a REFERENCE
-------- Managed C++ code ---------
bool CSUSSWrapper::F indFileItem(Str ing* filename, IVSSItem& founditem)
{
char* pFilename = (char*)(void*)M arshal::StringT oHGlobalAnsi(fi lename);
bool result = m_objSourceSafe->FindFileItem(p Filename, founditem);
// m_objSourceSafe is the unmanaged class
Marshal::FreeHG lobal(pFilename );
return result;
}
-------- C# code ---------
IVSSItem item;
sourceSafe.Find FileItem(shortY ear, &item) // sourceSafe is
themanaged wrapper object


so, far starters you may have noticed that the C# code appears to be sending
a IVSSItem* instead of IVSSItem&, this I can't help. I get compiler errors
if I pass just IVSSItem, intellisense tells me that it wants a ptr, sooo...?
BTW, IVSSItem is a class derived from COleDispatchDri ver
The problem I'm having is I get this error (somewhat randomly):

An unhandled exception of type 'System.NullRef erenceException ' occurred in
suabwrapper.dll
I suspect that the problem is happening in the wrapper C++ class. I'm
passing in a pointer to an IVSSItem from the C# code, but the C++ code is
treating it as a reference(I think) - to be honest, I really don't know what
is happening. I get random crashes and I have been able to snuff them out
by modifying the body of the UNMANAGED method FindFileItem() to ignore the
passed in IVSSItem reference and instead create a local IVSSItem (rendering
the function useless, but stops crashes)
I would REALLY appreciate any help you can offer, I don't know what else to
try.
Nov 17 '05 #1
0 1093

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

Similar topics

4
9625
by: Murat Tasan | last post by:
i have a quick question... is there a way to obtain the reference to the object which called the currently executing method? here is the scenario, i have a class and a field which i would like to populate with a reference to the object that constructed this current object. i would attempt to accomplish this by setting the appropriate field...
14
9569
by: Michael Winter | last post by:
In an attempt to answer another question in this group, I've had to resort to calling the DOM method, Node.removeChild(), using a reference to it (long story...). That is, passing Node.removeChild. In Opera (7.23/Win), the call appears to do nothing - the node remains - but no errors are shown. In Netscape (7.0/Win), an exception results....
7
2023
by: JJ | last post by:
Hi, I call a class in my windows service app and in that class I access a method that returns an OleDbReader. Now It does have records in the reader when I step through the method but when I return to calling class the OleDbReader dr is null. What am I missing here? Class1 calls Class2.Method which returns a OleDbReader. Class1's...
1
2892
by: Jesse McGrew | last post by:
Hi all, I'm trying to make a plugin DLL for a third-party application, using VC++ .NET 2003. This DLL acts as a bridge between the C++ plugin API of the application, and my actual plugin code written in C#. When the app calls my unmanaged functions, they work fine. But as soon as my unmanaged functions call managed functions (in the same...
4
1596
by: Mervin Williams | last post by:
I have several tables involved in my application, but the two in question here are the company and address tables. The company table has business_address_id and mailing_address_id columns, which are both foreign keys to the address table. So, the stored procedure to which my SelectCommand points to reads as: ALTER PROCEDURE...
1
2694
by: Dominic via DotNetMonster.com | last post by:
I am a CA-OpenROAD programmer, but I attempting to build some VB.NET DLLs and access them through OpenROAD as an external Windows TypeLib. I have managed to build a simple DLL (code follows) but the only method that I can see exposed is "DisplayNumber" which is a sub declared in a public interface definition rather than "DisplayNumbers"...
10
3142
by: Max Yuzhakov | last post by:
Hello! It is correct behaviour for python to call __del__ on some identity of a class object more than once? In brief I shall describe a situation. Sorry for my english. For debugin purposes I'm put in my module global counters for counting __init__ and __del__ calls.
11
3252
by: PvtBillPilgrim | last post by:
I'm very new to Java and I was looking for some help on this particular problem. I need to create a method that takes a String as a parameter and returns "true" if the parameter is the letter Y or the letter N (in either upper or lower case), or false otherwise. Most of the methods we've been working on are numbers (integers mostly) not...
5
4280
by: bizt | last post by:
Hi, Below I have a simple object / function thing (still getting head round these) declaration: function MyObject() { this.alertMe = function() { alert('hello'); }; this.alertMeAgain() {
0
7911
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8200
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7954
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
3836
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1448
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1179
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.