Results 1 to 5 of 5

Thread: C++ Class From a DLL using C#

  1. #1

    Thread Starter
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    C++ Class From a DLL using C#

    Hi guys!

    I need a little help here. I've built a piece of code that wraps around several functions of windows. I've done this by creating a class in the C++ DLL. I know how to call functions from a C++ DLL already but how to you create a class from the C++ library and call its methods?

    Cheers
    My Blog.

    Ryan Jones.

  2. #2
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: C++ Class From a DLL using C#

    Wait, what..? You know how to call functions from a C++ DLL, but you don't know how to call methods from a C++ library?

    Here's a hint: functions are methods too.
    And another hint: a DLL is a library too.

  3. #3

    Thread Starter
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: C++ Class From a DLL using C#

    I got that. But since these methods require class initialization isn't there something that I need to do before I call them?

    Currently I do this:

    Code:
            [DllImport("cpu.information.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "?HasSSE42Extensions@CPUIdentification@@QAE_NXZ")]
            public static extern bool HasSSE42Extensions();
    Which works but seems... wrong. Does the code internally run the class constructor or something?
    My Blog.

    Ryan Jones.

  4. #4
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: C++ Class From a DLL using C#

    Well you should have mentioned that in your post
    I can't really help you as I don't know myself, I just happened to read your post and it sounded to me like you had already answered your own question.

    So just to be clear, the know how to call static methods, but you don't know how to call instance methods (or, how to create an instance and then call its methods)?

  5. #5

    Thread Starter
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: C++ Class From a DLL using C#

    Yeah. You got it. I can confirm that the above code doesn't work if the class has not been initialized first.
    My Blog.

    Ryan Jones.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width