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

Exporting C++ classes as ordinals (via a def file)

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 mapping is required) to the names in the def
file.
Apr 18 '07 #1
12 7210

"2b|!2b==?" <ro**@your.box.comwrote in message
news:wc*********************@bt.com...
>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
Dependency Walker is your friend.
2). How to map them (if any mapping is required) to the names in the def
file.

Apr 18 '07 #2


Ben Voigt wrote:
"2b|!2b==?" <ro**@your.box.comwrote in message
news:wc*********************@bt.com...
>>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


Dependency Walker is your friend.
Surely, there must be a better way than manually going through (copy and
paste?) over 100+ (Class::methods) PER Dll ?

>
>>2). How to map them (if any mapping is required) to the names in the def
file.
Do I use the same decorated names in the .def file, or do I need to
"munge" (i.e. transform) the names into something else using another
tool for example ?
Apr 18 '07 #3
"2b|!2b==?" <ro**@your.box.comwrote in message
news:of******************************@bt.com...
>

Ben Voigt wrote:
>"2b|!2b==?" <ro**@your.box.comwrote in message news:wc*********************@bt.com...
>>>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


Dependency Walker is your friend.

Surely, there must be a better way than manually going through (copy and paste?) over 100+
(Class::methods) PER Dll ?

>>
>>>2). How to map them (if any mapping is required) to the names in the def file.

Do I use the same decorated names in the .def file, or do I need to "munge" (i.e.
transform) the names into something else using another tool for example ?


Are you talking about class members? If yes, stop here, you can't call methods from managed
code, only C style exports can be called via PInvoke, you need to wrap them in managed
classes using C++/CLI.
If you are talking about C style functions, you'll have to find the export ordinals using -
dumpbin /exports <dllnameand add them manually into your DllImports, IMO there is no tools
to do this automatically.

Willy.

Apr 18 '07 #4


Willy Denoyette [MVP] wrote:
"2b|!2b==?" <ro**@your.box.comwrote in message
news:of******************************@bt.com...
>>

Ben Voigt wrote:
>>"2b|!2b==?" <ro**@your.box.comwrote in message
news:wc*********************@bt.com...

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

Dependency Walker is your friend.

Surely, there must be a better way than manually going through (copy
and paste?) over 100+ (Class::methods) PER Dll ?

>>>
2). How to map them (if any mapping is required) to the names in the
def file.


Do I use the same decorated names in the .def file, or do I need to
"munge" (i.e. transform) the names into something else using another
tool for example ?


Are you talking about class members? If yes, stop here, you can't call
methods from managed code, only C style exports can be called via
PInvoke, you need to wrap them in managed classes using C++/CLI.
If you are talking about C style functions, you'll have to find the
export ordinals using - dumpbin /exports <dllnameand add them manually
into your DllImports, IMO there is no tools to do this automatically.

Willy.
Hmmm, neither of the above. I'm not using C# (I was under the impression
that this was a C++ specific ng). This is a C++ only framework.

I am already exporting my classes etc by name - but I want to export the
classes using ordinal numbers (for consumption by other C++ projects).

As I mentioned before, I already know this involves using .def file
(again I have experience of using def files to export C functions by
ordinal). My SPECIFIC question is how may I export C++ classes by
ORDINAL #, for use in other C++ libraries ?
Apr 18 '07 #5
Do I use the same decorated names in the .def file, or do I need to
"munge" (i.e. transform) the names into something else using another
tool for example ?

Are you talking about class members? If yes, stop here, you can't call
methods from managed code, only C style exports can be called via
PInvoke, you need to wrap them in managed classes using C++/CLI.
If you are talking about C style functions, you'll have to find the
export ordinals using - dumpbin /exports <dllnameand add them manually
into your DllImports, IMO there is no tools to do this automatically.

Willy.

Hmmm, neither of the above. I'm not using C# (I was under the impression
that this was a C++ specific ng). This is a C++ only framework.

I am already exporting my classes etc by name - but I want to export the
classes using ordinal numbers (for consumption by other C++ projects).

As I mentioned before, I already know this involves using .def file
(again I have experience of using def files to export C functions by
ordinal). My SPECIFIC question is how may I export C++ classes by
ORDINAL #, for use in other C++ libraries ?
Hi,

Maybe I am missing something, but why would you want to export by ordinal if
you are going to use it in other C++ projects anyway?
Why don't you simply export your C++ class by name?

Classes are nothing but a collection of functions. A class does not really
exist in binary, only mangled functions do.
To export by ordinal you'd have to somehow export each member by ordinal in
the correct order, and hope that you never have to insert a new member
because therwise the ordinals will all be messed up.
I don't think this is possible at all.
--
Kind regards,
Bruno.
br**********************@hotmail.com
Remove only "_nos_pam"

Apr 19 '07 #6
>
Hi,

Maybe I am missing something, but why would you want to export by ordinal
if
you are going to use it in other C++ projects anyway?
Why don't you simply export your C++ class by name?

Classes are nothing but a collection of functions. A class does not really
exist in binary, only mangled functions do.
To export by ordinal you'd have to somehow export each member by ordinal
in
the correct order, and hope that you never have to insert a new member
because therwise the ordinals will all be messed up.
I don't think this is possible at all.
I think the problem is going to be *importing* the functions by ordinal, is
there some syntax akin to __declspec(dllimport, ordinal)?

Certainly, as long as the ordinals are assigned manually, the "insert a new
member" problem goes away. Indexes are certainly a feasible way to call
member functions because this is how COM works, it's an index into the
v-table instead of into the import table, but as long as you can control the
ordering and preserve it across versions, that should protect you against
changes in the name-mangling convention between compiler versions as long as
the calling convention doesn't change. And name-mangling changes are
coming, because they're needed to fix
https://connect.microsoft.com/Visual...dbackID=100917
Apr 19 '07 #7
On Apr 19, 4:36 pm, "Ben Voigt" <r...@nospam.nospamwrote:
Hi,
Maybe I am missing something, but why would you want to export by ordinal
if
you are going to use it in other C++ projects anyway?
Why don't you simply export your C++ class by name?
Classes are nothing but a collection of functions. A class does not really
exist in binary, only mangled functions do.
To export by ordinal you'd have to somehow export each member by ordinal
in
the correct order, and hope that you never have to insert a new member
because therwise the ordinals will all be messed up.
I don't think this is possible at all.

I think the problem is going to be *importing* the functions by ordinal, is
there some syntax akin to __declspec(dllimport, ordinal)?
Indeed. It would be usefull if the OP explained us how it intends to
*use* this DLL in client code, because I do not believe it would be
possible to call methods on those classes using normal C++ syntax.
It would probably be possible to import them as "C" style functions,
and call them by passing explicitely the "this" argument, but I do not
see any interest to the exercise.

Btw, one should also consider other aspects, such as stack unwinding
across a DLL boundary in case of exception....

Arnaud
MVP - VC

Apr 19 '07 #8
<ad******@club-internet.frwrote in message
news:11*********************@q75g2000hsh.googlegro ups.com...
On Apr 19, 4:36 pm, "Ben Voigt" <r...@nospam.nospamwrote:
Hi,
Maybe I am missing something, but why would you want to export by
ordinal
if
you are going to use it in other C++ projects anyway?
Why don't you simply export your C++ class by name?
Classes are nothing but a collection of functions. A class does not
really
exist in binary, only mangled functions do.
To export by ordinal you'd have to somehow export each member by
ordinal
in
the correct order, and hope that you never have to insert a new member
because therwise the ordinals will all be messed up.
I don't think this is possible at all.

I think the problem is going to be *importing* the functions by ordinal,
is
there some syntax akin to __declspec(dllimport, ordinal)?

Indeed. It would be usefull if the OP explained us how it intends to
*use* this DLL in client code, because I do not believe it would be
possible to call methods on those classes using normal C++ syntax.
It would probably be possible to import them as "C" style functions,
and call them by passing explicitely the "this" argument, but I do not
see any interest to the exercise.

Btw, one should also consider other aspects, such as stack unwinding
across a DLL boundary in case of exception....
I don't have any experience doing it, but it's got to be possible as the MFC
dlls do exactly this: export the class member functions using
[decorated_fname @ ordinal NONAME] in a def file, and I assume the import
libs take care of the linking requirements.
--
Jeff Partch [VC++ MVP]
Apr 19 '07 #9
I don't have any experience doing it, but it's got to be possible as the
MFC dlls do exactly this: export the class member functions using
[decorated_fname @ ordinal NONAME] in a def file, and I assume the import
libs take care of the linking requirements.
Entries in import libraries are resolved based on the linker matching the
mangled name, but the mangled name is prone to change even when the function
signature is compatible.
--
Jeff Partch [VC++ MVP]


Apr 19 '07 #10
"Ben Voigt" <rb*@nospam.nospamwrote in message
news:ex**************@TK2MSFTNGP05.phx.gbl...
>I don't have any experience doing it, but it's got to be possible as the
MFC dlls do exactly this: export the class member functions using
[decorated_fname @ ordinal NONAME] in a def file, and I assume the import
libs take care of the linking requirements.

Entries in import libraries are resolved based on the linker matching the
mangled name, but the mangled name is prone to change even when the
function signature is compatible.
But wouldn't that be the same situation either with named exports or
NONAME'd ordinals?

--
Jeff Partch [VC++ MVP]
Apr 19 '07 #11
>
I don't have any experience doing it, but it's got to be possible as the MFC
dlls do exactly this: export the class member functions using
[decorated_fname @ ordinal NONAME] in a def file, and I assume the import
libs take care of the linking requirements.
Thi sis precisely what I intend to do - from the info on the MS website
and comments so far, I think the way forward is to use dumpbin to obtain
the mangled names for use in the def file.
Apr 19 '07 #12

"Jeff Partch" <je***@mvps.orgwrote in message
news:eW**************@TK2MSFTNGP03.phx.gbl...
"Ben Voigt" <rb*@nospam.nospamwrote in message
news:ex**************@TK2MSFTNGP05.phx.gbl...
>>I don't have any experience doing it, but it's got to be possible as the
MFC dlls do exactly this: export the class member functions using
[decorated_fname @ ordinal NONAME] in a def file, and I assume the
import libs take care of the linking requirements.

Entries in import libraries are resolved based on the linker matching the
mangled name, but the mangled name is prone to change even when the
function signature is compatible.

But wouldn't that be the same situation either with named exports or
NONAME'd ordinals?
If there was a __declspec(dllimport, ordinal) notation, it would be
independent of mangling changes between compiler versions.
>
--
Jeff Partch [VC++ MVP]


Apr 19 '07 #13

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

Similar topics

3
by: Chris | last post by:
Could someone please provide me an effective means of exporting data from a data set (or data grid) to Excel?
5
by: Jayjay | last post by:
Is it possible to export a report to word and have it include the graphics that are in the report? I'd like to take some of our reports and export them to word so we can email those to the...
1
by: nunYa | last post by:
I am trying to use the DoCmd.TransferText method to export an access table to a Tab Delimited Text File. I have put the code behind the onclick event of a button and keep getting the error...
4
by: Joshua Emele | last post by:
Hello - I am new to c# having come from the land of c. With c, I could create a .def file: library cdll exports foo @1 bar @2
2
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...
8
by: Alfonso Morra | last post by:
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...
2
by: Snozz | last post by:
The short of it: If you needed to import a CSV file of a certain structure on a regular basis(say 32 csv files, each to one a table in 32 databases), what would be your first instinct on how to...
15
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&); ...
1
by: Marty Klunk | last post by:
I have an Access97 data base where we are exporting records out to a text file that is then sent to a customer via EDI transmission. The problem I am having is that during the export process access...
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
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
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
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
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,...
0
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...

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.