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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:22:56+00:00 2026-06-07T03:22:56+00:00

I am writing C# code that interfaces to a legacy (Feb 2012) C program,

  • 0

I am writing C# code that interfaces to a legacy (Feb 2012) C program, using DllImport. It works fine, but I need to call more than 30 different functions, turning my normally impeccable, exquisite code into something of near-elephantine proportions. Surely there must be a way around this? [Warning: those with weak stomachs may want to avert their eyes from what follows]:

    [DllImport("C:\\Users\\mitt\\Documents\\Visual Studio 2010\\Projects\\mrSolution\\mr\\x64\\Debug\\mrDll.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
    public static extern bool mrEngine_initialize(     [In, Out, MarshalAs(UnmanagedType.LPStruct)] PLOT_SPEC PlotSpec);
    [DllImport("C:\\Users\\mitt\\Documents\\Visual Studio 2010\\Projects\\mrSolution\\mr\\x64\\Debug\\mrDll.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
    public static extern bool mrEngine_getDataPoint(   [In, Out, MarshalAs(UnmanagedType.LPStruct)] PLOT_SPEC PlotSpec);
  • 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-07T03:22:58+00:00Added an answer on June 7, 2026 at 3:22 am

    This is fairly inevitable with a C style api. The Windows api being a prime example of one with thousands of functions. Tying them together with handles. With the handle being the C style equivalent of this, the object reference for a class object.

    The next leg up is a COM interface, it allows building an object model. Very common in Windows apis, looks like you lost out on that one.

    This however doesn’t stop you from creating your own object model, using C# classes whose methods and properties map in a logical way to the underlying C style api. The fugly code that implements your class members and makes the pinvoke calls can be hidden in a #region that you hopefully never have to look at again.

    There is more than one benefit to doing it this way. Thinking about the object model mapping really helps you to understand the underlying api. And gives you plenty of unit test extension points. And makes you feel really good about creating order out of chaos.

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

Sidebar

Related Questions

I am a very proficient C# developer, but need to start writing code that
I'm using c#. In many cases I'm writing code that can benefit from a
I am writing some code that connects to a website, and using C#, and
I am writing a program written in C# that interfaces with a Sage Payroll
I'm writing a class that interfaces to a MoinMoin wiki via xmlrpc (simplified code
I am writing code that will spawn two thread and then wait for them
I am writing code that catches this OutOfMemoryException and throws a new, more intuitive
I'm writing some code that will take a screenshot of another application, given its'
I am writing some code that will go through a file, edit it as
I'm writing a code that uses bitboards. since iterating on all bits of a

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.