473,508 Members | 2,263 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(PCSTR filename, IVSSItem& founditem); // note that
founditem is a REFERENCE
-------- Managed C++ code ---------
bool CSUSSWrapper::FindFileItem(String* filename, IVSSItem& founditem)
{
char* pFilename = (char*)(void*)Marshal::StringToHGlobalAnsi(filenam e);
bool result = m_objSourceSafe->FindFileItem(pFilename, founditem);
// m_objSourceSafe is the unmanaged class
Marshal::FreeHGlobal(pFilename);
return result;
}
-------- C# code ---------
IVSSItem item;
sourceSafe.FindFileItem(shortYear, &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 COleDispatchDriver
The problem I'm having is I get this error (somewhat randomly):

An unhandled exception of type 'System.NullReferenceException' 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 1085

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

Similar topics

4
9615
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...
14
9551
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....
7
2017
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...
1
2881
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...
4
1593
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...
1
2682
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...
10
3123
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...
11
3243
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...
5
4273
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
7231
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
7336
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,...
1
7063
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...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5640
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5059
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3211
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...
0
1568
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 ...
0
432
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...

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.