473,326 Members | 2,102 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,326 software developers and data experts.

help with wrapping and reference types

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 the
managed 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 16 '05 #1
0 1068

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

Similar topics

13
by: Roy Smith | last post by:
I've got a C library with about 50 calls in it that I want to wrap in Python. I know I could use some tool like SWIG, but that will give me a too-literal translation; I want to make some...
5
by: xuatla | last post by:
Hi, I encountered the following compile error of c++ and hope to get your help. test2.cpp: In member function `CTest CTest::operator+=(CTest&)': test2.cpp:79: error: no match for 'operator='...
2
by: Paul Kenny | last post by:
Hi, I am trying to expose the functionality of an unmanaged C++ class to the other languages available in the .NET Framework. I have decided to do this by wrapping the unmanaged C++ class in a...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
6
by: Markus Ernst | last post by:
Hi Searching for a possibility to display some text with preserved white space and line breaks, but with long lines being wrapped, I found this CSS declaration, which I found helpful: pre {...
5
by: Joel | last post by:
(1) Can anyone please tell me the exact meaning of primitive types in the MSIL context. (2) Also what is the meaning of the world inline? (3) What is the meaning of the statement: "You should...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
by: akshaycjoshi | last post by:
I am reading a book which says Even though unboxed value types don't have a type object pointer, you can still call virtual methods (such as Equals, GetHashCode, or ToString) inherited or...
2
by: hcaptech | last post by:
This is my Test.can you help me ? 1.Which of the following statement about C# varialble is incorrect ? A.A variable is a computer memory location identified by a unique name B.A variable's name...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.