473,396 Members | 1,713 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,396 software developers and data experts.

Accessing and Unmanaged Class from Managed Code

Hi Guys,
I am trying to access a class in an unmanaged dll. I have
created a wrapper managed class to access the functions I need but no matter
what I try from the MSDN samples I can not get it to work with my code. I
have a VB Net front end which need the access the unmanaged functions. The
wrapper I wrote can be accessed but the wrapper will not compile when I
refer to the unmanaged class. I have tried using header file for definitions
with and #include in the managed code, __dllExport and all my attempts do
not work. I am escentially a VB programmer but have done enough C years ago
to allow me to get the code working stand alone. I am not up to the task at
hand and would really appreciate some ideas from the C++ experts out there.

Thanks
Brett Styles.

snippet:

managed wrapper:

namespace CameraSDK
{
__gc public class CameraManaged
{
public:
CameraManaged(void)
{
}

~CameraManaged(void)
{
}

ConnectCamera()
{
CProg.Connect(); //Error here every time.
}

private:
CameraU CProg; //ERROR here every time
}:
}
Unmanaged Code

class CameraU
{
CameraU::CameraU(void)
{
}

~CameraU::CameraU(void)
{
}

Connect()
{
.......code here
}
};

Nov 17 '05 #1
2 2375
Lev
Hi,

You should use a pointer to the unmanaged class instead of embedding the
unmanaged type in the managed class. Embedding only work in the most trivial
cases, and should you find yourself in such a situation, you are most likely
better off making the class to be embedded either __gc or __value. The
problem is that when you embed an unmanaged object in a managed class, all
the members of the unmanged class will be created on the GC heap (think of
the disastrous effects of for instance a memcpy on the managed heap).
If possible, you should have a pointer to the unmanaged class in the
managed class and new it up from the constructor (or other function) of the
managed class if possible.

Hope this helps,

Lev

"Brett Styles" <br*********@tpg.com.au> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hi Guys,
I am trying to access a class in an unmanaged dll. I have
created a wrapper managed class to access the functions I need but no matter what I try from the MSDN samples I can not get it to work with my code. I
have a VB Net front end which need the access the unmanaged functions. The
wrapper I wrote can be accessed but the wrapper will not compile when I
refer to the unmanaged class. I have tried using header file for definitions with and #include in the managed code, __dllExport and all my attempts do
not work. I am escentially a VB programmer but have done enough C years ago to allow me to get the code working stand alone. I am not up to the task at hand and would really appreciate some ideas from the C++ experts out there.
Thanks
Brett Styles.

snippet:

managed wrapper:

namespace CameraSDK
{
__gc public class CameraManaged
{
public:
CameraManaged(void)
{
}

~CameraManaged(void)
{
}

ConnectCamera()
{
CProg.Connect(); //Error here every time.
}

private:
CameraU CProg; //ERROR here every time
}:
}
Unmanaged Code

class CameraU
{
CameraU::CameraU(void)
{
}

~CameraU::CameraU(void)
{
}

Connect()
{
......code here
}
};

Nov 17 '05 #2
I did not make my example clear. I actually have two
projects one managed (which contains the class CameraManaged) and another
project which is unmanaged but refrenced by the managed one (this contains
the class CameraU). I tried embedding early on but that did not work. Both
operate independently prefectly ok. I just can not create a reference to
the unmanaged class from the managed one, in VB this is a simple task but in
C++ there are so many options I do not know what the errors reported mean
when I try different options as set out in the MSDN samples. One error that
comes up a lot is unreferenced exteral _dtor, when I search I cannot find
any thing that calls such a method.

Regards
Brett
Nov 17 '05 #3

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

Similar topics

2
by: Brett | last post by:
We have an application completely written in C++ under visual studio v6. One of our customers wants to use some of our existing components in his project but doesn't know C++ and isn't interested...
4
by: Rachel Suddeth | last post by:
What is the difference between a managed/unmanaged resource, and how do you tell which is which? I'm trying to understand how to write some Dispose() methods, and we are supposed to put code that...
3
by: zhphust | last post by:
I want to convert a object of a managed class to a unmanaged structure that has the same member with that managed class. Can anybody tell me how i can do it? Thanks in advance. -- zhphust...
1
by: sklett | last post by:
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...
1
by: Sparhawk | last post by:
Hi, my company is going to migrate a large VC++ application to .NET to make use of Windows Forms (the old class library is not updated any more). We are not planning to migrate the rest of the...
3
by: Dave | last post by:
I've seen at least one article on this: How to access classes, etc. managed-to-unmanaged. I can't find it. Any tricks or pointers? I guess the class name won't get munged but I'm not clear about...
5
by: Andy | last post by:
I'm having trouble accessing an unmanaged long from a managed class in VC++.NET When I do, the contents of the variable seem to be mangled. If I access the same variable byte-by-byte, I get the...
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...
9
by: Amit Dedhia | last post by:
Hi All I have a VC++ 2005 MFC application with all classes defined as unmanaged classes. I want to write my application data in xml format. Since ADO.NET has buit in functions available for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
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
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
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,...

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.