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 7504665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:38:51+00:00 2026-05-29T21:38:51+00:00

I’m trying to port some functionality from my engine from c++ to C#. I

  • 0

I’m trying to port some functionality from my engine from c++ to C#.
I compile my engine as a dll with unmanaged c++ and only use extern “C” functions in the C# wrapper.

I have various functions that take and return Vector3df. This is defined as

typedef Vector3d<f32> Vector3df;

and f32 is a actually a float. The class itself has nothing more than some members called x y and z and a lot of methods.

I can rewrite the whole class in C#, that’s not a problem but is there anyway in which the 2 could be matched?

Let’s take for example the following functions:

extern "C" void SetColor(Vector3df color)
extern "C" Vector3df GetColor()

I would like to have something like this in C#:

[DllImport("Engine.dll", EntryPoint = "SetColor", CallingConvention = CallingConvention.Cdecl)]
static extern void SetColor(Vector3df color);
[DllImport("Engine.dll", EntryPoint = "GetColor", CallingConvention = CallingConvention.Cdecl)]
static extern Vector3df GetColor();

Is there anyway in which I could make code similar to this work?

Note that I’m not by any means a C# guru.I’m lost when it comes to marshaling. I’m mostly doing this to make a map editor for my game without having to learn Qt or wxWidgets.

Thank you!

  • 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. Editorial Team
    Editorial Team
    2026-05-29T21:38:51+00:00Added an answer on May 29, 2026 at 9:38 pm

    All you need to do is define a C# structure that has an equivalent binary layout to the one expected by the c++ dll. Assuming only x,y,z with no packing, that’s just…

    [StructLayout(LayoutKind.Sequential)] //Required, as default layout is Auto
    struct Vector3df {
        public float x, y, z;
    }
    

    That should work with the C and C# function signatures you’ve given. The difficulty arises if you wish to invoke any method on the Vector3df class, because you cannot p/invoke C++ class methods. You need to wrap each of the methods as a plain C function as you’ve done with the Set/GetColor.

    It ends up being a lot of work if you’re trying to import a big library, and might be simpler to use C++/CLI to create the wrapper. Another option might be to investigate using cxxi, but I have no experience using this.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
For some reason, after submitting a string like this Jack’s Spindle from a text
I want use html5's new tag to play a wav file (currently only supported
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.