Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Problem Definition:

We are having MFC regular dll trough which we exported 5 functions.
Question is how to access regular MFC dll exported functions from C# application?

Input:

1. Originally MFC dll was developed and built under Visual Studio 6.0
2. It's having def file containing list of 5 exported functions. (Not under any class)
3. I was able to built this dll successfully on VS 2005 studio with /Clr option enabled.
4. If i tried to add reference of .tlb file in C# application, it's giving me error: Not valid assembly or com component.


Question is,

What I am doing wrong here? Adding converted dll (with /clr enabled) also as reference in C# application does not show me list of exported functions.

What is the proper way of accessing regular MFC dll (Use MFC in shared Dll) from C# application?

Newly Added Information:

I am having 5 exported functions in my dll, not member of any class and exported as follows:

__declspec(dllexport)long WINAPI Functio1(float *pf, float *pf1,
float *pf2, float *pf3, long Size)
Posted
Updated 23-Mar-10 2:47am
v2

I think what you need to do is use the System.Runtime.InteropServices namespace.




 
Share this answer
 
v3
You can use a normal native dll from C# using P/Invoke. Export your C++ functions using extern "C" to prevent C++ name mangling, then import them in your C# project like this:

C#
[DllImport( "user32.dll" )]
public static extern IntPtr SendMessage(
    IntPtr hWnd,
    UInt32 msg,
    IntPtr wParam,
    IntPtr lParam );


There's plenty of info on P/Invoke on the net. This site will give you plenty of examples:

http://www.pinvoke.net/[^]

Nick
 
Share this answer
 
Thanks to both of you for your answers, can you please tell me How I can achieve the same using C++/CLI wrapper?

For some good reasons I don't want to go with P/Invoke. Thanks in advance.
 
Share this answer
 
v2
Just point the guy to some source code that he can download.
I hate aholes who just paste and copy answers like those above
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900