CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2005
    Posts
    2

    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.

  2. #2
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    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.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  3. #3
    Join Date
    Feb 2005
    Posts
    1

    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

  4. #4
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    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.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured