I am familiar with creating lean and mean WIN32 DLLS and exporting C
functions via a DEF file (or cconv decorators), but I am wndering how I
can export my C++ objects from my DLLs?
Ideally, I would be able to use the classes (and their methods) by
calling the objects and invoking their methods - is this possible, given
the fact that the C++ compiler decorates names ?
looking forward to an informed answer -tkx 8 1589
// in your header...
class __declspec(dlle xport) CDllTest
{
public:
CDllTest(){}
~CDllTest(){}
public:
void SayHello();
};
// in your cpp...
void CDllTest::SayHe llo()
{
printf(_T("Hell o World!!"));
}
Another option: if you create a new dll project using VS it will create an
example dummy exported class.
--
Un saludo
Rodrigo Corral González [MVP]
FAQ de microsoft.publi c.es.vc++ http://rcorral.mvps.org
Gracias mucho por su ayuda :-)
(Thanks for your help)
Rodrigo Corral [MVP] wrote: // in your header...
class __declspec(dlle xport) CDllTest { public: CDllTest(){} ~CDllTest(){}
public: void SayHello(); };
// in your cpp...
void CDllTest::SayHe llo() { printf(_T("Hell o World!!")); }
Another option: if you create a new dll project using VS it will create an example dummy exported class.
Rodrigo Corral [MVP] wrote: // in your header...
class __declspec(dlle xport) CDllTest { public: CDllTest(){} ~CDllTest(){}
public: void SayHello(); };
// in your cpp...
void CDllTest::SayHe llo() { printf(_T("Hell o World!!")); }
Another option: if you create a new dll project using VS it will create an example dummy exported class.
Thanks - but that's on the exporting side of things. I wanted to know
how to use the exported classes in a seperate project that imports the
classes and uses them. The code you gave above, only shows how to export
the classes (which I already know how to do).
mtia
The class declaration header file should look something like this :-
#ifdef EXPORTSCLASS
#define EXPORTCLASS_API __declspec(dlle xport)
#else
#define EXPORTCLASS_API __declspec(dlli mport)
#endif
class EXPORTCLASS_API CMyClass
{
public:
//...
};
When you use this in the DLL project, define EXPORTSCLASS, but refrain from
doing so in the EXE project where you call this dll.
--
Regards,
Nish [VC++ MVP] http://www.voidnish.com http://blog.voidnish.com
"Alfonso Morra" <sw***********@ the-ring.com> wrote in message
news:db******** **@nwrdmz01.dmz .ncs.ea.ibs-infra.bt.com...
Rodrigo Corral [MVP] wrote:
// in your header...
class __declspec(dlle xport) CDllTest { public: CDllTest(){} ~CDllTest(){}
public: void SayHello(); };
// in your cpp...
void CDllTest::SayHe llo() { printf(_T("Hell o World!!")); }
Another option: if you create a new dll project using VS it will create an example dummy exported class.
Thanks - but that's on the exporting side of things. I wanted to know how to use the exported classes in a seperate project that imports the classes and uses them. The code you gave above, only shows how to export the classes (which I already know how to do).
mtia
Nishant Sivakumar wrote: The class declaration header file should look something like this :-
#ifdef EXPORTSCLASS #define EXPORTCLASS_API __declspec(dlle xport) #else #define EXPORTCLASS_API __declspec(dlli mport) #endif
class EXPORTCLASS_API CMyClass { public: //... };
When you use this in the DLL project, define EXPORTSCLASS, but refrain from doing so in the EXE project where you call this dll.
Thanks. this is what I was looking for.
Nishant Sivakumar wrote: The class declaration header file should look something like this :-
#ifdef EXPORTSCLASS #define EXPORTCLASS_API __declspec(dlle xport) #else #define EXPORTCLASS_API __declspec(dlli mport) #endif
class EXPORTCLASS_API CMyClass { public: //... };
When you use this in the DLL project, define EXPORTSCLASS, but refrain from doing so in the EXE project where you call this dll.
Nishant, I tried this (exported a single method) and then run dumbin
against my DLL. I find that the name of the method is mangled (as I had
suspected).
Two questions:
If I declare a FAR PASCAL calling convention (i.e. declspec(export )) at
the class level, do I get all the public methods exported "for free" or
do I have to manually export every public method in the classes public
interface?
2). If the names are mangled (ehich I suspect they will be because of
the overloading etc I have in my code), can I still use the unmangled
names of classes and methods in an application that links to the library?
tks
Alfonso Morra wrote:
Nishant Sivakumar wrote:
The class declaration header file should look something like this :-
#ifdef EXPORTSCLASS #define EXPORTCLASS_API __declspec(dlle xport) #else #define EXPORTCLASS_API __declspec(dlli mport) #endif
class EXPORTCLASS_API CMyClass { public: //... };
When you use this in the DLL project, define EXPORTSCLASS, but refrain from doing so in the EXE project where you call this dll.
Nishant, I tried this (exported a single method) and then run dumbin against my DLL. I find that the name of the method is mangled (as I had suspected).
Two questions:
If I declare a FAR PASCAL calling convention (i.e. declspec(export )) at the class level, do I get all the public methods exported "for free" or do I have to manually export every public method in the classes public interface?
OK I found the answer to do this. I just did this and the answer is yes. 2). If the names are mangled (ehich I suspect they will be because of the overloading etc I have in my code), can I still use the unmangled names of classes and methods in an application that links to the library?
The names are mangled as I had expected. I will try using the library
from another project and see if I can access the classses andntheir
methods using the undecorated names - unless you reply to this before
I'm through with my test ... tks
The names are mangled, but in the calling exe, if you include the header
file and add the lib (a lib is generated along with the dll) to the linker
list, you will be alright. Note that the lib does not contain the real
functions (it just contains definitions that the linker can use, so you need
to have the dll for the exe to run).
--
Regards,
Nish [VC++ MVP] http://www.voidnish.com http://blog.voidnish.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: sridevi |
last post by:
Hello
How to export data from ms-access database to excel worksheet using ASP.
mainly i need to export data to multiple worksheets. it is very urgent to
us.
i have a sample code which works only exporting to single worksheet. but i
need to export data to multiple worksheets.
it is very urgent to us. so please help me in code.
|
by: Niall |
last post by:
I'm attempting to put a C# front end on my unmanaged C++ ray tracer code.
It's still in experimental stage, as I have never done anything with
exporting types from an unmanaged dll through to a managed C# dll before.
Currently, I have an unmanaged dll, a managed C++ wrapper dll and a C# dll.
I have managed to get enough exported from the unmanaged code to get a
vaguely correct picture on the screen, however there is some odd behaviour.
...
|
by: Gustavo L. Fabro |
last post by:
Greetings!
Some classes that once compiled without problems on VS 2003 have now
problems on VS 2005 Beta 1. I'm talking about a __nogc class that is
exported with __declspec(dllexport).
The compiler message is this:
VCSelectLibraryForm.cpp
...\Forms\QiForm.h(48) : error C3395: 'TQiForm::GetDotNetMouseButton' :
|
by: paul |
last post by:
I am exporting a class from a managed dll created in Visual C++ 2005
Express.
In A.h header file I have
// A.h
public ref class A {};
In the same module, I create a new class to be exported which will use
A as its base class.
|
by: bienwell |
last post by:
Hi,
I have a question about exporting data from datagrid control into Excel file
in ASP.NET. On my Web page, I have a linkbutton "Export data". This link
will call a Sub Function to perform exporting ALL data from the datagrid
control. Exporting data works fine when I show all data on the datagrid
control.
I'd like to shows only 30 records on the datagrid control instead of ALL
data using page navigation, and perform exporting...
| |
by: =?Utf-8?B?QWw=?= |
last post by:
Hello,
I'm writing a service using VS2005 and C#. I've found that only the objects
used as parameters in WebMethods get exported to proxy dlls and the Service
Description. I'd like my service clients to be able to use the objects I've
defined in messages to the service and send them as "object" parameters or as
embeded items in other objects.
I can work around the problem by declaring all of the objects as public
members of a dummy...
|
by: 2b|!2b==? |
last post by:
I want to export my C++ classes in a DLL, using ordinal # - rather than
by name. Will anyone care to enumerate through the steps required to do
this?
I am already failiar with exporting classes and symbols (both C++ and C)
from a DLL. In the case of C functions, i also know how to export them
by ordinal # - my main problem revolves around how to do the ff:
1). Obtaining the mangled names from the C++ DLL
2). How to map them (if any...
|
by: Grey Alien |
last post by:
I have a class that contains a std::map variable. I need to export the
class via a DLL. the class looks something like this:
class MyClass
{
public:
MyClass();
MyClass(const MyClass&);
private:
|
by: puzzlecracker |
last post by:
is there a way to create a library (assembly/dll) where I can only
export few class? I don't want client to use or know about other
internal classes in the assembly.
Thanks
|
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...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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...
|
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |