jitendra_wadhwani
asked on
Loading MFC Dll in C# Form
Suppose there is an MFC dll which creates some CWnd.
Some Functions are exported in MFC dll.
I need to display this CWnd on C# Form as otherchild controls of Form.
How Should I do to implement it?
Thanks in advance.
Some Functions are exported in MFC dll.
I need to display this CWnd on C# Form as otherchild controls of Form.
How Should I do to implement it?
Thanks in advance.
ASKER
Hi mahesh...
Thanks for the quick response
I have implemented this method....
I have more than 500 dlls in my project and I dont want to import each and every dll althought all the dlls have same exported functions for creating and destroying.
Suppose I have created One CWnd and I want to set its parent as C# form.
I need to pass the parent to MFC dll and want to use in MFC dll....
I am anyhow able to pass the handle of C# form as long but getting CWnd* from that long created some problem in MFC.
I need one function in which I will pass DLL Name and parameters. Want to load that particular DLL and also there should be any unloading process.
Dll name will be decided on runtime.
Hope you understood my requirement.
Thanks for the quick response
I have implemented this method....
I have more than 500 dlls in my project and I dont want to import each and every dll althought all the dlls have same exported functions for creating and destroying.
Suppose I have created One CWnd and I want to set its parent as C# form.
I need to pass the parent to MFC dll and want to use in MFC dll....
I am anyhow able to pass the handle of C# form as long but getting CWnd* from that long created some problem in MFC.
I need one function in which I will pass DLL Name and parameters. Want to load that particular DLL and also there should be any unloading process.
Dll name will be decided on runtime.
Hope you understood my requirement.
ASKER
Will see the specified urls also...
>>Dll name will be decided on runtime.
you can also create a DLL which can forward function calls to any location and load any DLL further into your address space... using LoadLibrary() function..
Have a look following codeproject article :
Late binding on native DLLs with C#
http://www.codeproject.com/csharp/dyninvok.asp
-MAHESH
you can also create a DLL which can forward function calls to any location and load any DLL further into your address space... using LoadLibrary() function..
Have a look following codeproject article :
Late binding on native DLLs with C#
http://www.codeproject.com/csharp/dyninvok.asp
-MAHESH
rather look into this for quick solution :
Dynamic Invoke from Unmanaged DLL
http://www.codeproject.com/csharp/dynamicinvokedll.asp <== this may be of your use
-MAHESH
Dynamic Invoke from Unmanaged DLL
http://www.codeproject.com/csharp/dynamicinvokedll.asp <== this may be of your use
-MAHESH
ASKER
>>http://www.codeproject.com/csharp/dyninvok.asp
Already seen.......
>>http://www.codeproject.com/csharp/dynamicinvokedll.asp
Tried similar to this one not exactly same......
Will try and confirm....
Already seen.......
>>http://www.codeproject.com/csharp/dynamicinvokedll.asp
Tried similar to this one not exactly same......
Will try and confirm....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
http://www.msjogren.net/dotnet/eng/samples/dotnet_dynpinvoke.asp
404
The requested document was not found on this server.
--------------------------
Web Server at msjogren.net
check this link if u able to download this
http://www.msjogren.net/dotnet/download.asp?dynpinvoke.zip
http://www.msjogren.net/dotnet/download.asp?dynpinvoke.zip
ASKER
yes downloaded....
wil check it..
wil check it..
again click on link it will open its opening at my end
ASKER
Not opening....
Downloaded the zip.....
I treid to open
http://www.msjogren.net/dotnet/
Showing
The site is temporarily down, sorry. Please check back in a couple of weeks.
Anyway....trying to understad the code given in zip file and will implement...
Downloaded the zip.....
I treid to open
http://www.msjogren.net/dotnet/
Showing
The site is temporarily down, sorry. Please check back in a couple of weeks.
Anyway....trying to understad the code given in zip file and will implement...
ASKER
Hi Mahesh,
Thanks for the help.....
Although The provided Help has not solved my issue but I have achieved the Displaying part now other part is remainning....
My 500 Dlls were developed in 3000 man days.....
Your provide help has enriched my knowledge. You are the only person who responded for this question...Giving Grade A
Thanks
Jitendra
Thanks for the help.....
Although The provided Help has not solved my issue but I have achieved the Displaying part now other part is remainning....
My 500 Dlls were developed in 3000 man days.....
Your provide help has enriched my knowledge. You are the only person who responded for this question...Giving Grade A
Thanks
Jitendra
using System;
using System.Runtime.InteropServ
class PInvoke1App
{
[DllImport("user32.dll")]
static extern int MessageBoxA(int hWnd, string strMsg,string strCaption,int iType);
public static void Main()
{
MessageBoxA(0, "Hello, World!", "This is called from a C# app!", 0);
}
}
above calls MessageBoxA function from user32.dll
following may be of your use refer:
'Call Unmanaged DLLs from C#, ' :http://msdn.microsoft.com/msdnmag/issues/02/08/CQA/
'Using Unmanage Code in C# ' http://www.codeguru.com/Csharp/Csharp/cs_syntax/unmanagedcode/article.php/c5887/
-MAHESH