473,695 Members | 2,575 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Managed code / unmanaged code?

Hi
I have a project which is going to be doing some string manipulation which
needs to be pretty fast. The user interface is going to be written in C#. I
am going to write the string handling functions in a C++ DLL.

My first question is, if I insert a C++ project into my C# solution, how
will VS.NET know that I want it to be unmanaged code? I intend to be calling
the DLLs functions using DllImport. I've heard that you can have unmanaged
code and managed code in a single code file, so I was wondering if the
setting between managed code and unmanaged code is some sort of declaration,
or is it at the project level?

My second question is, if I want to use DllImport to call the DLL's
functions, what is the best way to specify the directory in which to look
for the DLL? I can't get my head round whether to specify the debug
location, the release location, or none - in the DllImport section.
Nov 17 '05 #1
4 7178
Here si the deal,

/CLR will create 'by default' managed code only, and will also allow running
certain 'unmanaged code'.

if the unmanaged code in within a .DLL, you can pretty much do anything you
need.
if the code is within the same managed project you'll need to use the
#pragma unmanaged, in case of VC++/CLR.

the thing is that, from what I have seen, CLR is extremely fast in almost
all the circumstances, even in string manipulations, you'll need to do some
million loops of string manipulations to see 'some' difference.

you'll really need the unmanaged code in rare instances, trust me.

but I am a time-critical-optimization freak myself, so I share your concern.

ultimately, a DLL, call is not the faastes anyway, because between the IJW
(it just works) transition clr-unmanaged and the dll-function-call indirect
mapping, you'll lose timing anyway.
consider this too if it helps.

"repstat" <re*****@wonder code.com> wrote in message
news:eB******** ******@TK2MSFTN GP11.phx.gbl...
Hi
I have a project which is going to be doing some string manipulation which
needs to be pretty fast. The user interface is going to be written in C#. I am going to write the string handling functions in a C++ DLL.

My first question is, if I insert a C++ project into my C# solution, how
will VS.NET know that I want it to be unmanaged code? I intend to be calling the DLLs functions using DllImport. I've heard that you can have unmanaged
code and managed code in a single code file, so I was wondering if the
setting between managed code and unmanaged code is some sort of declaration, or is it at the project level?

My second question is, if I want to use DllImport to call the DLL's
functions, what is the best way to specify the directory in which to look
for the DLL? I can't get my head round whether to specify the debug
location, the release location, or none - in the DllImport section.

Nov 17 '05 #2
Your best bet is to separate the managed part from the unmanaged
part to multiple files. For the files that contain the managed code, you
would
add #using <mscorlib.dll > and add the compilation switch /clr.
For the unmanaged part is the exactly the opposite, no /clr, no
mscorlib.dll.

For the second question, just drop the dll to the current working directory,
in which your exe resides.

--

This posting is provided "AS IS" with no warranties, and confers no rights.
"repstat" <re*****@wonder code.com> wrote in message
news:eB******** ******@TK2MSFTN GP11.phx.gbl...
Hi
I have a project which is going to be doing some string manipulation which
needs to be pretty fast. The user interface is going to be written in C#.
I
am going to write the string handling functions in a C++ DLL.

My first question is, if I insert a C++ project into my C# solution, how
will VS.NET know that I want it to be unmanaged code? I intend to be
calling
the DLLs functions using DllImport. I've heard that you can have unmanaged
code and managed code in a single code file, so I was wondering if the
setting between managed code and unmanaged code is some sort of
declaration,
or is it at the project level?

My second question is, if I want to use DllImport to call the DLL's
functions, what is the best way to specify the directory in which to look
for the DLL? I can't get my head round whether to specify the debug
location, the release location, or none - in the DllImport section.

Nov 17 '05 #3

"andrea catto'" <ac****@datafli ght.com> wrote in message
news:eY******** ******@TK2MSFTN GP09.phx.gbl...
Here si the deal,

/CLR will create 'by default' managed code only, and will also allow running certain 'unmanaged code'.

if the unmanaged code in within a .DLL, you can pretty much do anything you need.
if the code is within the same managed project you'll need to use the
#pragma unmanaged, in case of VC++/CLR.
Does this mean it can use managed code within the SAME project as unmanaged
code, as long as it's in a different file with #pragma unmanaged??? !!??
Surely not!...?

Oh god, you know what that means!
That means there's a reason for me to use the *dreaded* MANAGED C++!
NOOOOOOOOOO!!! AAAAAAAARRRRGGH HHHHHH!!!

Do I trust that the garbage collector will work correctly in the managed
file?

(Shit! I think I was somehow clinging to the hope that calling u-MC++
code in a DLL from C# was just as quick as this gloomy inevitability)

the thing is that, from what I have seen, CLR is extremely fast in almost
all the circumstances, even in string manipulations, you'll need to do some million loops of string manipulations to see 'some' difference.

you'll really need the unmanaged code in rare instances, trust me.

but I am a time-critical-optimization freak myself, so I share your concern.
ultimately, a DLL, call is not the faastes anyway, because between the IJW
(it just works) transition clr-unmanaged and the dll-function-call indirect mapping, you'll lose timing anyway.
consider this too if it helps.

"repstat" <re*****@wonder code.com> wrote in message
news:eB******** ******@TK2MSFTN GP11.phx.gbl...
Hi
I have a project which is going to be doing some string manipulation which needs to be pretty fast. The user interface is going to be written in C#.
I
am going to write the string handling functions in a C++ DLL.

My first question is, if I insert a C++ project into my C# solution, how
will VS.NET know that I want it to be unmanaged code? I intend to be

calling
the DLLs functions using DllImport. I've heard that you can have

unmanaged code and managed code in a single code file, so I was wondering if the
setting between managed code and unmanaged code is some sort of

declaration,
or is it at the project level?

My second question is, if I want to use DllImport to call the DLL's
functions, what is the best way to specify the directory in which to look for the DLL? I can't get my head round whether to specify the debug
location, the release location, or none - in the DllImport section.


Nov 17 '05 #4
>
Does this mean it can use managed code within the SAME project as unmanaged code, as long as it's in a different file with #pragma unmanaged??? !!??
Surely not!...?

Oh god, you know what that means!
That means there's a reason for me to use the *dreaded* MANAGED C++!
NOOOOOOOOOO!!! AAAAAAAARRRRGGH HHHHHH!!!

Do I trust that the garbage collector will work correctly in the managed
file?

(Shit! I think I was somehow clinging to the hope that calling u-MC++
code in a DLL from C# was just as quick as this gloomy inevitability)


You can use managed code and unmanaged code in the same file without the
#pragma - the limitations between the two only become apparent when you're
trying to mix unmanaged / managed class members. The garbage collector will
tidy up any managed objects. If you create unmanaged objects you need to
ensure they get tidied up, same as normal. This only applies to C++ - you
obviously can't compile C++ and C# together. Managed C++ is fine, it's just
the syntax is a bit crusty at the moment.

Steve
Nov 17 '05 #5

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

Similar topics

1
741
by: Bob Rock | last post by:
Hello, in the last few days I've made my first few attempts at creating mixed C++ managed-unmanaged assemblies and looking aftwerwards with ILDASM at what is visible in those assemblies from a managed point-of-view I've noticed that: 1) for each managed and unmanaged C function (not C++ classes) I get a public managed static method (defined on a 'Global Functions' class) in the generated assembly with an export name of the form...
1
2121
by: Eric Twietmeyer | last post by:
Hello, I'm starting to investigate cs, managed c++ and interoperating with a very large unmanaged code base. We are going to use Windows Forms (written in cs) to replace our old fashioned GUI. The guts will remain in unmanaged c++. So I need to write public managed c++ wrapper classes for the couple of interfaces the unmanaged stuff needs to expose for the GUI. Questions:
3
3503
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 ------------------------------------------------------------------------
3
2779
by: Thorsten | last post by:
HI I'm a C# developer and unfortunately I have to write now some code in managed and unmanaged C++. In this area I'm Newbie and therefore please forgive me if this is a really simple question.
13
5043
by: bonk | last post by:
Hello, I am trying to create a dll that internally uses managed types but exposes a plain unmanaged interface. All the managed stuff shall be "wrapped out of sight". So that I would be able to use that dll from pure unmanaged code (for example inherit from classes in that dll). Is something like that possible. I heared something called ManWarp tried that approach. If it is possible, how can I do that. Maybe there is a small litttle
2
2722
by: Sandy | last post by:
I am confused about Unmanaged Code, How .Net Framework treate that code, What is the use of that. Thanks in advance Sandeep Chitode
12
1625
by: doug | last post by:
I understand the basics of what managed code offers and that you open yourself up to security issues if you allow unmanaged code. We already have a decent amount of VB6 code to include COM DLLs. If we put wrappers around some of our code or leave some "asis" what makes our existing production code 'evil' just because it is now considered 'unmanaged'? It may seem like a simple niave question, but the definitions for managed and...
9
3119
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 this, I want to use it. Is it possible to call Managed class functions from Unmanaged class? How to do it? I did something like this. I declared a managed class (in C++ CLI) called as MyManagedClass whose
25
3016
by: Koliber (js) | last post by:
sorry for my not perfect english i am really f&*ckin angry in this common pattern about dispose: ////////////////////////////////////////////////////////// Public class MyClass:IDisposable
0
8649
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8586
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8838
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7683
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6506
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4351
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4592
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3025
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
2
2289
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.