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

Namespace with managed C++ DLL and C# usage [Try #3]

Hello,

I have a C++ (unmanaged) class named K in a DLL.
I create a managed C++ class named K in an other DLL that wrapped the
unmanaged one.

To refer the unmanaged one I use ::K and the managed one is in a
namespace MyNameSpace.

If want to use my managed DLL in a C# project,so I added : #using
Mynamespace;

If in the code I put :
K klass = new K;
There is compilation error. It seems that le K sybol is the unmanaged
one and identifyed as a 'struct'.

Is there a solution to remove the knowledge of the unmanged symbol to be
able to refer K in C# with only its name and not Mynamespace.K ?

Thx
Nov 22 '05 #1
3 3464
> Is there a solution to remove the knowledge of the unmanged symbol to be
able to refer K in C# with only its name and not Mynamespace.K ?
I tried your example with beta2 toolset and I am able to call into the
managed assembly and dont get the compilation error. This is what I did.

cl /EHsc /LD def.cpp
cl /clr /LD m.cpp /link def.lib
csc /r:m.dll t.cs
////////////////def.cpp
#include <stdio.h>
class __declspec(dllexport) Native
{
public:
void foo()
{
printf("native foo called\n");
}
};
////////////////m.cpp

using namespace System;
class __declspec(dllimport) Native
{
public:
void foo();
};

namespace N
{
public ref class Native
{
public:
void foo()
{
Console::WriteLine("N::Native::foo");
}
};
}

///////////////////t.cs

using System;
using N;

class Test
{
static void Main()
{
Native obj = new Native(); // No compilation error
obj.foo(); // foo in namespace N called
}
}

Does this work for you? If not, can you tell me the compiler you are using
so that we can try to find what is going on?
Thanks,
Kapil

--
This posting is provided "AS IS" with no warranties, and confers no
rights."Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm"

"Mr Topom" <mr*****@yahoo.com> wrote in message
news:4a**************************@posting.google.c om... Hello,

I have a C++ (unmanaged) class named K in a DLL.
I create a managed C++ class named K in an other DLL that wrapped the
unmanaged one.

To refer the unmanaged one I use ::K and the managed one is in a
namespace MyNameSpace.

If want to use my managed DLL in a C# project,so I added : #using
Mynamespace;

If in the code I put :
K klass = new K;
There is compilation error. It seems that le K sybol is the unmanaged
one and identifyed as a 'struct'.

Is there a solution to remove the knowledge of the unmanged symbol to be
able to refer K in C# with only its name and not Mynamespace.K ?

Thx

Nov 22 '05 #2
Hello,

Thx for the answer.

I just tested and it works... But If I modify the managed class like
that :

namespace managedDll
{
public __gc class Native {
protected:
// Put the line below in comment and everything works
fine
::Native __nogc *unmanagedNativePtr; // <--- Reference
to the unmaged class

public:
void foo();
};
}

I have a compile problem and Native in the C# code is highlighted as
struct.

I am with VC 2003 and I can't change the compiler...

Any Idea ?
Nov 22 '05 #3
Kapil:

I tried this under VS8 Beta2 and I'm confused. Why is there a class in
def.cpp called Native and a class in m.cpp also called Native?

When I build this, I see "N::Native::foo". I would like to see "native foo
called".

I would like to instantiate an object of the class Native that lives in
def.cpp and run it inside N::Native::foo(). Can this be done?

Thanks,
Denny Huber

"Kapil Khosla [MSFT]" <kk*****@online.microsoft.com> wrote in message
news:ue**************@tk2msftngp13.phx.gbl...
Is there a solution to remove the knowledge of the unmanged symbol to be
able to refer K in C# with only its name and not Mynamespace.K ?


I tried your example with beta2 toolset and I am able to call into the
managed assembly and dont get the compilation error. This is what I did.

cl /EHsc /LD def.cpp
cl /clr /LD m.cpp /link def.lib
csc /r:m.dll t.cs
////////////////def.cpp
#include <stdio.h>
class __declspec(dllexport) Native
{
public:
void foo()
{
printf("native foo called\n");
}
};
////////////////m.cpp

using namespace System;
class __declspec(dllimport) Native
{
public:
void foo();
};

namespace N
{
public ref class Native
{
public:
void foo()
{
Console::WriteLine("N::Native::foo");
}
};
}

///////////////////t.cs

using System;
using N;

class Test
{
static void Main()
{
Native obj = new Native(); // No compilation error
obj.foo(); // foo in namespace N called
}
}

Does this work for you? If not, can you tell me the compiler you are using
so that we can try to find what is going on?
Thanks,
Kapil

--
This posting is provided "AS IS" with no warranties, and confers no
rights."Use of included script samples are subject to the terms specified
at
http://www.microsoft.com/info/cpyright.htm"

"Mr Topom" <mr*****@yahoo.com> wrote in message
news:4a**************************@posting.google.c om...
Hello,

I have a C++ (unmanaged) class named K in a DLL.
I create a managed C++ class named K in an other DLL that wrapped the
unmanaged one.

To refer the unmanaged one I use ::K and the managed one is in a
namespace MyNameSpace.

If want to use my managed DLL in a C# project,so I added : #using
Mynamespace;

If in the code I put :
K klass = new K;
There is compilation error. It seems that le K sybol is the unmanaged
one and identifyed as a 'struct'.

Is there a solution to remove the knowledge of the unmanged symbol to be
able to refer K in C# with only its name and not Mynamespace.K ?

Thx


Nov 22 '05 #4

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

Similar topics

3
by: Mr Topom | last post by:
Hello, I have a C++ (unmanaged) class named K in a DLL. I create a managed C++ class named K in an other DLL that wrapped the unmanaged one. To refer the unmanaged one I use ::K and the...
1
by: The Real Andy | last post by:
This is probably not the most relevant NG for this topic, but if someone could point me to a more relevant NG I would be forever grateful. I am having some issues with the Managed DirectX...
4
by: J | last post by:
I've just been reading a few articles on how Managed Extensions are now obsolete! Tough thing to hear, as I've been spending every spare moment studying them to try to solve a problem. I'd like...
1
by: RaKKeR | last post by:
Hi, I'm trying to wrap my unmanaged c++ code into a managed c++ wrapper. The problem is VC .NET doesn't seem to find the namespaces defined in my unmanaged code. Let's say I have a file...
3
by: bill | last post by:
All, I cannot find any examples of doing Excel automation from a VC++ .Net environment. Does anyone ay least know what the namespace should be to expose the Excel app? i.e. using namespace...
0
by: Charles Leonard | last post by:
I need opinions regarding Web Service Namespace usage and/or suggestions regarding how to handle deployment. Our web service application will exist in two different domains and is likely to...
87
by: Robert Seacord | last post by:
The SEI has published CMU/SEI-2006-TR-006 "Specifications for Managed Strings" and released a "proof-of-concept" implementation of the managed string library. The specification, source code for...
6
by: PC | last post by:
Gentlesofts, Forgive me. I'm an abject newbie in your world, using VB 2005 with the dot-Net wonderfulness. So, I'm writing a wonderful class or two to interface with a solemnly ancient...
1
by: raylopez99 | last post by:
I seem to get name collision between the Generic collection SortedList and C++.NET Framework collection SortedList. How to resolve? Here are the libraries that seem to clash:...
1
by: Dan Holmes | last post by:
I can't find where i have declared ICategoryService as being in the IVS.WMS.Product namespace. I have recompiled. Deleted the obj and bin dirs. Removed the reference. I can't figure out how the...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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...

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.