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 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'm writing a windows application in c#,FW3.5 & Visual Studio 2008. I need to
I am writing some unit tests in Visual Studio 2010. I can run all
I am writing a visual studio add-in which preforms operations on javascript files after
During uninstallation of the Visual Studio Integration Package that I am writing, I need
I'm writing a Visual Studio toolbar Add-In that displays the current time. I have
I'm writing a visual studio Add-In that will activate when the debugger is launched.
I am writing a Visual Studio add-in to process C++ code, and think that
I'm writing a replacement for a Visual Studio Add-In which we've got from a
I'm writing a Visual Studio extension/add-in and I want to find the names of
I'm writing a simple Visual Studio 2010 Add-In to do a common copying job

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.