Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,673 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,177 people online right now. Registration is fast and FREE... Join Now!




How to Call C# DLL in C++

2 Pages V  1 2 >  
Reply to this topicStart new topic

How to Call C# DLL in C++

plenitude
post 29 Jul, 2008 - 12:39 AM
Post #1


New D.I.C Head

*
Joined: 4 Jul, 2008
Posts: 12

I am a begineer in C# I have created sinmple DLL but hoe to call functions of DLL from C++ code.it can be simple client program for C++.
Following is code of DLL:
CODE

using System;
using System.Collections.Generic;
using System.Text;

namespace mcMath
{
    public class mcMathComp
    {
        private bool bTest = false;
        public mcMathComp()
        {
            
            
            
        }
        public void McTestMethod()
        {
            throw new System.NotImplementedException();
        }

        public long Add(long val1, long val2)
        {
            throw new System.NotImplementedException();
            return val1 + val2;
        }

        public bool Extra
        {
            get
            {
                throw new System.NotImplementedException();
                return bTest;
            }
            set
            {
                bTest = Extra;
            }
        }



    }
}


thanks in Advance..
Please explain it simple way as I am a begineer
smile.gif
User is offlineProfile CardPM

Go to the top of the page

zakary
post 29 Jul, 2008 - 04:09 AM
Post #2


D.I.C Regular

Group Icon
Joined: 15 Feb, 2005
Posts: 401



Thanked 6 times

Dream Kudos: 175
My Contributions


I don't really understand what you want. if you are looking to call a C++ method from your C# code and you have the C++ DLL and .h files, we need to know what the method is you want to call, it's return type, and any parameters it takes. normally the .h file will have this information.
User is offlineProfile CardPM

Go to the top of the page

plenitude
post 2 Sep, 2008 - 02:23 AM
Post #3


New D.I.C Head

*
Joined: 4 Jul, 2008
Posts: 12

Hi Zakary,

I was busy in other assignments rolleyes.gif .
Now I am back at this one..... smile.gif

I want to call C# DLL from C++ code

plz help me some one,.......plz plz

As I am begineer plz explain ,if possible, by a simple example or code

Thankz in Advance.... cool.gif
User is offlineProfile CardPM

Go to the top of the page

JackOfAllTrades
post 2 Sep, 2008 - 05:39 AM
Post #4


D.I.C Addict

Group Icon
Joined: 23 Aug, 2008
Posts: 508



Thanked 45 times

Dream Kudos: 25
My Contributions


Have you tried MSDN?
User is offlineProfile CardPM

Go to the top of the page

zakary
post 2 Sep, 2008 - 11:29 AM
Post #5


D.I.C Regular

Group Icon
Joined: 15 Feb, 2005
Posts: 401



Thanked 6 times

Dream Kudos: 175
My Contributions


QUOTE(plenitude @ 2 Sep, 2008 - 06:23 AM) *

Hi Zakary,

I was busy in other assignments rolleyes.gif .
Now I am back at this one..... smile.gif

I want to call C# DLL from C++ code

plz help me some one,.......plz plz

As I am begineer plz explain ,if possible, by a simple example or code

Thankz in Advance.... cool.gif


you should post this question in the C++ form. They would be able to help you there.
User is offlineProfile CardPM

Go to the top of the page

plenitude
post 4 Sep, 2008 - 08:47 PM
Post #6


New D.I.C Head

*
Joined: 4 Jul, 2008
Posts: 12

I am a begineer,I have created DLL in C#

How to call DLL from C++ code?

Can u give a small client program as to how to call C# DLL

Following is code of DLL:
CODE

using System;
using System.Collections.Generic;
using System.Text;

namespace mcMath
{
    public class mcMathComp
    {
        private bool bTest = false;
        public mcMathComp()
        {
                  
            
        }
        public void McTestMethod()
        {
            throw new System.NotImplementedException();
        }

        public long Add(long val1, long val2)
        {
            throw new System.NotImplementedException();
            return val1 + val2;
        }

        public bool Extra
        {
            get
            {
                throw new System.NotImplementedException();
                return bTest;
            }
            set
            {
                bTest = Extra;
            }
        }

    }
}


Thankz in Advance smile.gif
User is offlineProfile CardPM

Go to the top of the page

JackOfAllTrades
post 5 Sep, 2008 - 03:01 AM
Post #7


D.I.C Addict

Group Icon
Joined: 23 Aug, 2008
Posts: 508



Thanked 45 times

Dream Kudos: 25
My Contributions


Was there a problem with the reply I made in your original thread? It's rather complicated, and requires that the C# DLL be properly built to support being called from C++.
User is offlineProfile CardPM

Go to the top of the page

NickDMax
post 5 Sep, 2008 - 08:36 AM
Post #8


2B||!2B

Group Icon
Joined: 18 Feb, 2007
Posts: 2,858



Thanked 47 times

Dream Kudos: 550
My Contributions


Well in the other thread someone did ask that he post here to get help.

Basically if you are using mannaged C++.Net then it is no problem to call C# dll from C++.

HOWEVER if you are working with non-mannaged C++ then it does become a little complicated since the C# dll will need to run on the .Net framework.

Why are you mixing languages? Why not just use 1 or the other. Chances are you can do what you need in C# rather than using C++ unless you need to do something outside of the .net framework in which case this will get complicated.
User is offlineProfile CardPM

Go to the top of the page

PsychoCoder
post 5 Sep, 2008 - 08:45 AM
Post #9


using DIC.Core;

Group Icon
Joined: 26 Jul, 2007
Posts: 8,933



Thanked 118 times

Dream Kudos: 8525

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions


Please don't create duplicate topics, it doesnt help you to get help any faster, and can actually slow it down since people don't know which thread to reply to smile.gif I'm merging the two topics smile.gif
User is offlineProfile CardPM

Go to the top of the page

plenitude
post 9 Sep, 2008 - 03:57 AM
Post #10


New D.I.C Head

*
Joined: 4 Jul, 2008
Posts: 12

Hi
I was told to post it on c/c++ FORUM RATHER ON c#

I 'll take care nxt time...

Thanx JACKOFALL.... I did worked on msdn link tht u provided...
but in my case I don't have to create client ,just have to do my part of creating DLL in C# & tell how to call my DLL in sombody elses C++ code..................... ph34r.gif

plz help
how to tell the other person way to call my C# DLL
User is offlineProfile CardPM

Go to the top of the page

plenitude
post 14 Sep, 2008 - 08:39 PM
Post #11


New D.I.C Head

*
Joined: 4 Jul, 2008
Posts: 12

QUOTE(plenitude @ 9 Sep, 2008 - 04:57 AM) *

Hi
I was told to post it on c/c++ FORUM RATHER ON c#

I 'll take care nxt time...

Thanx JACKOFALL.... I did worked on msdn link tht u provided...
but in my case I don't have to create client ,just have to do my part of creating DLL in C# & tell how to call my DLL in sombody elses C++ code..................... ph34r.gif

plz help
how to tell the other person way to call my C# DLL



Somebody plz help I am really struck........help help
User is offlineProfile CardPM

Go to the top of the page

skaoth
post 14 Sep, 2008 - 10:32 PM
Post #12


D.I.C Regular

Group Icon
Joined: 7 Nov, 2007
Posts: 338



Thanked 9 times

Dream Kudos: 100
My Contributions


NickDMax is pretty much spot on.

The only other way I can think of doing this is by using COM. Your C# dll Will have to use COM and Interop.

Let me google and see what I find: ... ah here we go
http://www.codeproject.com/KB/cs/ManagedCOM.aspx

If you don't know COM or how it works this may not be the best solution for you.
User is offlineProfile CardPM

Go to the top of the page

2 Pages V  1 2 >
Reply to this topicStart new topic
Time is now: 11/23/08 06:18AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month