Dynamic load of a c++ dll in C#?http://www.codecomments.com/archive290-2004-7-216328.html
转载
http://www.codecomments.com/archive290-2004-7-216328.html
|
lallous
2004-06-16, 8:57 am
|
|
Hello
I'm new to C# and wonder if it is possible as it is possible in C++ to dynamically load a DLL and use it in C#.
The dll is written in C++ and has the following export: int test(void);
and the code resides in test.dll
I want a C# application that when I press Button1, it should dynamically load test.dll and its 'test' function and call it and get its return value.
Is this possible in C#? If so, how?
-- Elias
|
|
|
I guess your dll is unmanaged. Write a managed wrapper in C++ and use this in C#.
---- Bob www.componentXtra.com Graph Controls/Components for .NET
|
|
rawal
2004-07-16, 4:19 pm
|
|
Hi Bob, May be it is a stupid question, but I am new to .Net and I am wondering if you can please help me. How can you dynamically load a component in c#. Imean I understand that you can do the new and can have an instance of a component but for that it is also required to use "using component class".
What I want to achieve is to read teh name of component from some out side file and then can instantiate it.
Regards, Rawal. |
|
Stuart Carnie
2004-07-20, 3:57 am
|
|
Do you want to instanciate a managed class or a set of exported functions from a DLL?
Cheers,
Stu rawal <rawal.19imdq@mail.codecomments.com> wrote in message news:<851526108ea4250abc8be46cf9a31a9c@news.thenewsgroups.com>... > Hi Bob, > May be it is a stupid question, but I am new to .Net and I am wondering > if you can please help me. > How can you dynamically load a component in c#. Imean I understand > that you can do the new and can have an instance of a component but for > that it is also required to use "using component class". > > What I want to achieve is to read teh name of component from some out > side file and then can instantiate it. > > Regards, > Rawal.
|
|
Dincer Ozturan
2004-07-20, 8:58 am
|
|
Hi,
You can dynamically load a managed component (.dll) by using the components under System.Reflection namespace, like "System.Reflection.Assembly". You can load the dll by using System.Reflection.Assembly.Load(..) System.Reflection.Assembly.LoadFile(string FileName) System.Reflection.Assembly.LoadFrom(string FilePath) methods. If you do not have managed dll, you have to wrap it and load the wrapper. After loading you can use the loaded component by using the other classes under same namespace(Sys.Ref).
Regards, Dincer
rawal <rawal.19imdq@mail.codecomments.com> wrote in message news:<851526108ea4250abc8be46cf9a31a9c@news.thenewsgroups.com>... > Hi Bob, > May be it is a stupid question, but I am new to .Net and I am wondering > if you can please help me. > How can you dynamically load a component in c#. Imean I understand > that you can do the new and can have an instance of a component but for > that it is also required to use "using component class". > > What I want to achieve is to read teh name of component from some out > side file and then can instantiate it. > > Regards, > Rawal.
|
|
本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。