|
-
February 14th, 2005, 10:11 AM
#1
Import a C++ class in C# project
Hello,
I have a DLL written in C++ that export a class.
I want import the class in my C# project.
How?
Thanks.
-
February 14th, 2005, 12:33 PM
#2
Re: Import a C++ class in C# project
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.
-
February 15th, 2005, 07:23 AM
#3
Re: Import a C++ class in C# project
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
-
February 15th, 2005, 10:00 AM
#4
Re: Import a C++ class in C# project
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|