Click to See Complete Forum and Search --> : Import a C++ class in C# project
Cap
February 14th, 2005, 09:11 AM
Hello,
I have a DLL written in C++ that export a class.
I want import the class in my C# project.
How?
Thanks.
darwen
February 14th, 2005, 11:33 AM
Look up P/Invoke (platform invoke) in MSDN. This'll show you how to access dll methods in native code from .NET.
This is way too big a subject to enter into in a posting on the forums. You'll just have to get started off yourself I'm afraid.
Darwen.
vikram_seri
February 15th, 2005, 06:23 AM
Hey,
Is there any other way other than pInvoke to use a C++ dll in C#?
In my WebApplication project I have used the following declaration:
[DllImport("SEComponent.dll", EntryPoint="SEGetStringDecrypted")][return: MarshalAs(UnmanagedType.BStr)]
public static extern string SEGetStringDecrypted([MarshalAs(UnmanagedType.BStr)] string sz);
and the following line for method Invocation:
decryptedPwd = SEGetStringDecrypted(encyptedPwd);
The problem is after this method is used the SEComponent.dll is not being released and i am getting an error saying "SEComponent dll is currently in use"
when I am trying to UnInstall my Product, even when I close the application.
As a workaround I intend to use the LoadLibrary/FreeLibrary methods from Win32 API, but we have no API methods to invoke a particular method after Loading the dll, there is a GetProcAddress which gives me the Physical address of a particular Method.
With this address I have written a Assembly program dll to invoke the method and it returns me a result, now i am unable to get rid of this Assembly language dll and getting the same problem that I got with SEComponent dll saying the dll is currently in use.
Summary: I have to Load a dll explicitly, invoke a method defined in that dll, and unload that dll.
Any Ideas!!!!
Regards
darwen
February 15th, 2005, 09:00 AM
The problem isn't that the dll isn't being unloaded : the problem is that the caller assembly of the dll isn't being unloaded.
Even if you manage to get the dll to unload itself I think you're going to find that there's another assembly which isn't unloaded which won't uninstall either.
I don't really know enough about WebApplications to help you any further I'm afraid.
Darwen.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.