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

Instantiating a native class from a /clr DLL

I have a little C++/CLI problem. I have a DLL that contains the following definition:

Expand|Select|Wrap|Line Numbers
  1. // *************************
  2. // IN THE HEADER FILE
  3. // *************************
  4.  
  5. #pragma once
  6.  
  7. #ifdef EXPORTS
  8. #define MYAPI __declspec(dllexport)
  9. #else
  10. #define MYAPI __declspec(dllimport)
  11. #endif
  12.  
  13. class MYAPI NNative
  14. {
  15. public:
  16.     NNative();
  17.     int DoSomething();   // just returns the integer 1000.
  18. };
  19.  
  20. // *************************
  21. // IN THE CPP FILE
  22. // *************************
  23.  
  24. #include "CliLib.h"
  25.  
  26. NNative::NNative()
  27. {
  28. }
  29.  
  30. int NNative::DoSomething()
  31. {
  32.     return 1000;
  33. }
  34.  
My calling app code is even more simple:

Expand|Select|Wrap|Line Numbers
  1. #include "stdafx.h"
  2. #include "..\CliLib\CliLib.h"
  3.  
  4. using namespace System;
  5.  
  6. int main(array<System::String ^> ^args)
  7. {
  8.     NNative *pn = new NNative();
  9.     Console::WriteLine(String::Format("You got {0}", pn->DoSomething()));
  10.     delete pn;
  11.     return 0;
  12. }
  13.  
If I build the DLL with no CLR support, everything builds and executes fine. However, if I build the DLL with CLR support...

1. The DLL still builds fine.
2. The main app produces 2 linker error for each public symbol of the NNative class: LNK2028 and LNK2019.

What am I doing wrong that I can't import the native class from the CLR DLL?

Thanks.
Aug 18 '06 #1
0 3231

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: David Kantowitz | last post by:
I am trying to wrap a native-C++ DLL in managed C++, to use in a .NET project. The native code is compiled into a DLL, and I have created a .def file that exports the mangled names of the...
2
by: HarishP | last post by:
Hi, How to avoid instantiating the class more than 10 times Harish.P Sr. Software Engineer Comat Technologies Pvt. Ltd., Bangalore Email: harish.p@comat.com
9
by: Herby | last post by:
Is possible to have a managed method within a Native(un-managed) class within a \clr project? E.g. class myClass { public: #pragma managed void myMethod(void);
1
by: Marja Ribbers-de Vroed | last post by:
I've been provided with a custom ActiveX DLL (written in C++) that reads a certiifcate to generate a signature for a passed XML string, and I'm having trouble instantiating it. The DLL is registered...
3
by: Nagesh | last post by:
hi, I have seen the winvnc(tightvnc server) source code in this I seen that class member funtions are calling without instantiating the object i.e. like vncService::ShowDefaultProperties() where...
3
by: Lonewolf | last post by:
Hi all, I'm having difficulties passing data back to managed class from my native class when the data is generated from within a native thread in the native class itself. I will give the following...
3
by: Greg | last post by:
In the following example, where is "n" allocated (e.g. managed heap?) ? public ref class N { .... .... } main() {
2
by: Joe | last post by:
I am trying to get a good understanding of these concepts and how they apply to code and classes (possibly different). As well as MSIL and Native Code (x86 assembly). To facilitate discussion...
2
by: Bob Altman | last post by:
Hi all, We have a native class modeled after the System::Exception class, and all exceptions that we throw derive from this class. For now this class is quite simple: just Description and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
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,...
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
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.