CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2008
    Posts
    42

    Question Query: In my DLL, Could I have C++ file & C# file

    In my DLL, Could I have C++ file that exports functions in traditional way using __declspec(dllexport), and have remaining code written in C# file?

    This is because: myDLL is a bridge between two applications.

    Application_1 wants me to export functions using __declspec(dllexport).

    Application_2 has APIs exposed in C#.

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

    Re: Query: In my DLL, Could I have C++ file & C# file

    You can if you use C++/CLI.

    Create an ordinary Win32 (native) dll project and set the "common language support" option in the project options to "common language support /clr".

    Alternatively native C++ code can interact with C# dlls using COM. See here.

    Darwen.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  3. #3
    Join Date
    Jul 2008
    Posts
    42

    Re: Query: In my DLL, Could I have C++ file & C# file

    Thanks darwen. but i am getting some build problem when i try to call the methods defined in the *.cs file.

    i have opened *.cs file through 'File | New... | C# | C# Class file'

    //myClass.cs file

    using System;

    /// <summary>
    /// Summary description for Class1
    /// </summary>
    ///
    namespace mynameSpace
    {
    public class myClass
    {
    public myClass()
    {
    //
    // TODO: Add constructor logic here
    //
    }
    public int clConnect()
    {

    return 1;
    }

    public int clQuit()
    {
    return 1;
    }
    }
    }


    // cpp file has this

    ...
    using namespace mynameSpace ;

    int clConnect()
    {
    return myClass::clConnect();
    }

    int clQuit()
    {
    return myClass::clQuit();
    }

    //errors i am getting at build time of the DLL

    1>.\export_functions.cpp(19) : error C2871: 'mynameSpace' : a namespace with this name does not exist
    1>.\export_functions.cpp(27) : error C2653: 'myClass' : is not a class or namespace name
    1>.\export_functions.cpp(35) : error C2653: 'myClass' : is not a class or namespace name

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

    Re: Query: In my DLL, Could I have C++ file & C# file

    Sorry : I missed an important point. You'll have to convert your C# code to C++/CLI.

    Darwen.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

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

    Re: Query: In my DLL, Could I have C++ file & C# file

    I've found these on some more searching :

    http://www.codeguru.com/forum/showth...ight=netmodule
    and
    http://blogs.msdn.com/frankpr/archiv...27/198918.aspx.

    However I'd still recommend just converting your C# code to C++/CLI.

    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