Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 93591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:22:06+00:00 2026-05-10T23:22:06+00:00

I am writing a DLL with mixed C/C++ code. I want to specify the

  • 0

I am writing a DLL with mixed C/C++ code. I want to specify the ordinals of the functions I’m exporting. So I created a .DEF file that looks like this

LIBRARY LEONMATH  EXPORTS      sca_alloc   @1     vec_alloc   @2     mat_alloc   @3      sca_free    @4     vec_free    @5     mat_free    @6      ... 

I would like to specify the ordinals of my C++ functions and class methods too. I have tried using the Dependency Walker to add the mangled names of my functions to the .DEF file:

    ??0CScalar@@QAE@XZ      @25     ??0CScalar@@QAE@O@Z     @26     ??0CScalar@@QAE@ABV0@@Z @27     ??1CScalar@@QAE@XZ      @28 

But this has failed. Any ideas why this could be happening?


EDIT: kauppi made a good observation, so I’m adding more information to the question.

  • Platform: Windows (and I’m not interested in portability)
  • Compiler: Microsoft’s C++ compiler (I’m using VS2005)
  • Why I want to do this?: Using the ordinals has the advantage of letting me call exported C++ functions from C code.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T23:22:07+00:00Added an answer on May 10, 2026 at 11:22 pm

    Well, I don’t have experience with ordinals (which look like some ugly, compiler-specific thing), but I can help you with making C++/C code compatible.

    Suppose, in C++, that your header file looks like this:

    class MyClass {     void foo(int);     int bar(int);     double bar(double);     void baz(MyClass); }; 

    You can make it C-compatible by doing the following:

    #ifdef __cplusplus #define EXTERN_C extern 'C' // Class definition here; unchanged #else #define EXTERN_C typedef struct MyClass MyClass; #endif  EXTERN_C void MyClass_foo (MyClass*, int); EXTERN_C int MyClass_bar_int (MyClass*, int); EXTERN_C double MyClass_bar_double (MyClass*, double); EXTERN_C void MyClass_baz (MyClass*, MyClass*); 

    In the C++ source file, you just define the various extern 'C' functions to pass to the desired member functions, like this (this is only one; the rest work similarly)

    extern 'C' void MyClass_foo (MyClass* obj, int i) {   obj->foo(i); } 

    The code will then have a C interface, without having to change the C++ code at all (except for declarations in the header; but those could also be moved to another file 'myclass_c.h' or the like). All the functions declared/defined extern ‘C’ won’t be mangled, so you can do other operations on them easily. You will also probably want functions to construct/destroy instances of MyClass (you can, of course, use new/delete for this).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a query to fetch results for all the values in a
I am learning on my own about writing an interpreter for a programming language,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.