Passing data from C++ DLL to C# application

I have a application in which has following component -

PushManager - This solution contains a class in which C++ DLL(PushCommon) is Imported using DllImport().

PushCommon - This soultion receives data from PushManager processes it and returns output.methods written in this solution are all exported.


Now requirement I got is call one of the method in PushManger in PushCommon.
I am not sure how I it can be done.
So I am here to get advice from the experts here.

Thanks in Advance.
Not following completely. Please fill in the blanks:

C++ Side:

Project Name or DLL name: _______________
Does it export functions or does it export objects?___________
What are the names of the exported functions or objects?____________

C# Side:
Project Name:____________________
Does it export anything? If yes, what?_______________________

Hopefully this format will help.
C++ Side:

Project Name or DLL name: ___PushCommon.dll____________
Does it export functions or does it export objects?____Functions_______
What are the names of the exported functions or objects?____ProcessData()________

C# Side:
Project Name:________PushManager____________
Does it export anything? If yes, what?_______It doesn't exports anything________________
Awesome. Thanks. What you describe is a typical P/Invoke scenario.

Assuming you used extern "C" when exporting the ProcessData() function, all you would do in C# is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public static class PushCommon
{
    [DllImport("PushCommon.dll")]
    extern public static <return type> ProcessData(<list of parameters>);
}


...

//And now you just use it.
public class Program
{
    public static int Main(string[] args)
    {
        PushCommon.ProcessData(<list of arguments here>);
        return 0;
    }
}
Thanks that one was helpful -

Now in above implementation is it possibel to invoke any method from PushManager(C#) in to a PushCommon(C++ DLL)?

Last edited on
There must be a way, but I don't know it. Maybe it is easier if PushManager were a C++/CLI application?

Anyway, the short answer is: I don't know about C# to C++.
Thanks

ANybody knows how can I achieve this?
closed account (z05DSL3A)
ANybody knows how can I achieve this?

Exposing .NET Framework Components to COM
http://msdn.microsoft.com/en-us/library/zsfww439.aspx

NB: I don't do native -> managed interop but I think this is how you do it.
I am having a similar problem, and i have been looking for this for days. can someone help me solve my problem. I have a C++ program and i created a DLL out of it.

I have another C# forms application, and i added the DLL as 'add reference'. when i double click on this DLL, i get the 'Object Browser' and when i expand the '+' sign i don't see any of my member functions that i wrote in it.

example.h

1
2
3
4
5
6
7
8
9
10
11
12
13
#pragma once

using namespace System;

namespace example {

	public ref class Class1
	{
	public:
		// TODO: Add your methods for this class here.
		 int main1(void); 
	};
}


example.cpp

1
2
3
4
5
6
7
#include "stdafx.h"
#include <stdio.h>

int main1( void ) {

printf("Hi !! ");
}


The above is a C++/CLL project (and i use Windows Vista, MS visual studio 2008)

Now i need to access this main1(), from the C# Main() method. can some one please tell me how i could do this.
Topic archived. No new replies allowed.