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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:43:30+00:00 2026-06-04T21:43:30+00:00

As msdn http://msdn.microsoft.com/en-us/library/aa288468(v=vs.71).aspx says Platform Invocation Services (PInvoke) allows managed code to call unmanaged

  • 0

As msdn http://msdn.microsoft.com/en-us/library/aa288468(v=vs.71).aspx says “Platform Invocation Services (PInvoke) allows managed code to call unmanaged functions that are implemented in a DLL.”

I want to import some class from DLL that i made in c++
Is it possible and how?

for example, i have some structures inside DLL:

struct __declspec(dllexport) DLLVector3
{
    float x, y, z;
};

struct __declspec(dllexport) DLLQuaternion
{
    float x, y, z, w;
};

class __declspec(dllexport) DLLCharacter
{
public:
    DLLVector3 position;
    DLLQuaternion orientation;

    DLLCharacter()
    {

    }

    ~DLLCharacter()
    {

    }

    void setPosition(PxVec3 pos)
    {
        position.x = pos.x;
        position.y = pos.y;
        position.z = pos.z;
    }

    void setOrientation(PxQuat or)
    {
        orientation.x = or.x;
        orientation.y = or.y;
        orientation.z = or.z;
        orientation.w = or.w;
    }
};

struct __declspec(dllexport) PhysicalObject
{
    DLLCharacter *character;
    PxRigidActor *mActor;
    PxController *mController;
};

Which way i can import those? Especially those structures with pointers

  • 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-06-04T21:43:31+00:00Added an answer on June 4, 2026 at 9:43 pm

    You don’t need to write C++ managed code for access – but – you can’t easily hop around between unmanaged and managed memory. Here’s a few key points
    1) Use [StructLayout(LayoutKind.Sequential)] to define .net classes that map on top of your c++ structs

    [StructLayout(LayoutKind.Sequential)]
    [Serializable]
    public struct SFVec3F : IRawStreamIO
    {
        public double _x;
        public double _y;
        public double _z;
    }
    

    2) Basic types like doubles, int32, etc move across the P/Invoke layer efficiently – more complex types earn you the .net variant of thunking – msft doco covers which data types move efficiently, try and use them

    3) Everything that’s a pointer in C++ land is an IntPtr in .net land and if you want to be safe you should treat it as a handle, i.e. you get the c++ side to do any manipulations/access to the underlying structure

    4) Access to the native C++ is pretty straightforward (the Handle props are IntPtrs that were originally sourced on the native C++ side)

    [DllImport("CS2V3.dll", CharSet = CharSet.Ansi)]
    private static extern void AddChild(IntPtr csoPtr, IntPtr childPtr, short recomputeBounds, short adjustCoords, short blindchild);
    public void AddChild(V3CSO theChild)
    {
        AddChild(m_handle, theChild.Handle,0,0,0);
    }
    

    5) Strings and some other types require marshalling to obtain a .net usable form – note that this happens automatically for strings when you pass a string to unmanaged code, but you have to do it yourself when it’s inbound

     [DllImport("CS2V3.dll", CharSet = CharSet.Ansi)]
    private static extern IntPtr GetName(IntPtr csoPtr);
    [DllImport("CS2V3.dll", CharSet = CharSet.Ansi)]
    private static extern void SetName(IntPtr csoPtr, string newName);
    
       public string Name
        {
            get
            {
                IntPtr np = GetName(m_handle);
                return Marshal.PtrToStringAnsi(np);
            }
            set
            {
                SetName(m_handle, value);
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code was grabbed from MSDN: http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.stringlengthattribute.aspx [MetadataType(typeof(ProductMetadata))] public partial class Product {
See the code sample from MSDN: ( http://msdn.microsoft.com/en-us/library/b1yfkh5e(v=VS.100).aspx ) // Design pattern for a
http://msdn.microsoft.com/en-us/library/system.resources.resxresourcewriter.aspx In this link and others like it, I see code to write in
I have been working with the following code published on msdn: http://msdn.microsoft.com/en-us/library/fx6588te.aspx I understand
A quote from MSDN: http://msdn.microsoft.com/en-us/library/6kac2kdh.aspx One or more managed threads (represented by System.Threading.Thread) can
From this sample code from MSDN http://msdn.microsoft.com/en-us/library/system.string.gethashcode.aspx The hash code for abc is: 536991770
I want to understand the example from msdn ( http://msdn.microsoft.com/en-us/library/ms742521.aspx#defining_simple_datatemplate ). XAML Code: <ListBox
According to MSDN (http://msdn.microsoft.com/en-us/library/dd487208.aspx), there is an object called DbDataReader that is created in
According to MSDN ( http://msdn.microsoft.com/en-us/library/system.windows.forms.label.autosize.aspx ), there's a note about Label 's AutoSize property:
I'm looking at WCF documentation in the MSDN ( http://msdn.microsoft.com/en-us/library/bb332338.aspx ), and have come

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.