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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:14:40+00:00 2026-05-26T13:14:40+00:00

This one is basic, how do I call the function SubscribeNewsFeed in the following

  • 0

This one is basic, how do I call the function SubscribeNewsFeed in the following from a C# DllImport?

class LogAppender : public L_Append
{
public:
    LogAppender()
        : outfile("TestLog.txt", std::ios::trunc | std::ios::out)
        , feedSubscribed(false)
    {
        outfile.setf(0, std::ios::floatfield);
        outfile.precision(4);
    }



    void SubscribeNewsFeed()
    {
        someOtherCalls();
    }

};

I’m unable to figure out how to include the class name when using the DllImport in my C# program here:

 class Program
    {

        [DllImport("LogAppender.dll")]
        public static extern void SubscribeNewsFeed();

        static void Main(string[] args)
        {
            SubscribeNewsFeed();
        }
    }
  • 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-26T13:14:40+00:00Added an answer on May 26, 2026 at 1:14 pm

    PInvoke cannot be used to call directly into a C++ function in this way. Instead you need to define an extern "C" function which calls the PInvoke function and PInvoke into that function. Additionally you cannot PInvoke into a class instance method.

    C / C++ Code

    extern "C" void SubscribeNewsFeedHelper() {
      LogAppender appender;
      appender.SubscribeNewsFeed();
    }
    

    C#

    [DllImport("LogAppender.dll")]
    public static extern void SubscribeNewsFeedHelper();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Perhaps someone can help me out with this one: I'm using a basic search
This is a very very basic question and I know one way is to
This is probably a basic html/css question... I have a simple one-button form that
I realise that this is a very basic question, but it is one which
This one is a case of not doing your homework.:-) Apart from dynamic loading
I have a function that wraps a call to one of my socket types.
EDIT 11/3/2011 9:37pm: This is my error: error: no matching function for call to
I really hope this isn't one of those super basic questions. Anyway, I've got
Ok, this is one of these basic questions, but I've googled and debugged now
This should be fairly basic, but say I have a Public property as local

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.