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

  • Home
  • SEARCH
  • 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 334389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:02:59+00:00 2026-05-12T10:02:59+00:00

I am writing a Visual Studio add in and need to marshall a managed

  • 0

I am writing a Visual Studio add in and need to marshall a managed CodeElements object to it’s unmananged form. I just need the pointer in memory, as I can cast it and treat it like a CodeElement on the unmanaged side.

    [DllImport("CodeMethodsToString.dll")]
    private static extern BSTR* CodeMethodsToString(void* functionObject);

    public static void CodeMethodsToXML(XmlElement parent, CodeElements elements)
    {
        //Call CodeMethodsToString: how do I marshall CodeElements to an IntPtr?
        //set XmlElement in here
    }

I know how to deal with the XML, and I have a working version of this in C#. I created the unmanaged DLL because calling all of the various member variables at the lowest level of recursion was killing the speed of the program. I simply need to know how to use System.Runtime.Interop.Marshal to convert the CodeElements object to a pointer to the COM object in memory.

Thanks.

  • 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-12T10:02:59+00:00Added an answer on May 12, 2026 at 10:02 am

    Looks like Jonathan was close. This is how I’d do it:

    [DllImport("CodeMethodsToString.dll")]
    [return: MarshalAs(UnmanagedType.BStr)]
    private static extern string CodeMethodsToString(IntPtr functionObject);
    
    public static void CodeMethodsToXML(XmlElement parent, CodeElements elements)
    {
       GCHandle pin;
       try
       {
          pin = GcHandle.Alloc(elements, GCHandleType.Pinned);
          string methods = CodeMethodsToString(pin.AddrOfPinnedObject());
        }
        finally
        {
           pin.Free();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I writing a report in Visual Studio that takes a user input parameter and
Currently I`m using Visual Studio for writing code in C++. But it seems so
I am writing a website with Visual Studio 2008 and ASP.NET 3.5. I have
I am writing a macro for Visual studio that will generate some code. I
Instead of writing my ASP.NET C# applications in Visual Studio, I used my favorite
I use Vim and Vim plugins for Visual Studio when writing C++. Often, I
I'm writing a GUI in C#, Visual Studio 2008, using the Designer and WinForms.
I'm in Eclipse writing Java. I come from Visual Studio with Resharper writing C#.
Writing some test scripts in IronPython, I want to verify whether a window is
Writing the code for the user authentication portion of a web site (including account

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.