Click to See Complete Forum and Search --> : Query: In my DLL, Could I have C++ file & C# file
gsmurthy30
August 2nd, 2008, 07:09 AM
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#.
darwen
August 2nd, 2008, 07:17 AM
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. ('http://msdn.microsoft.com/en-us/library/aa720072(VS.71).aspx')
Darwen.
gsmurthy30
August 2nd, 2008, 08:27 AM
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
darwen
August 2nd, 2008, 03:26 PM
Sorry : I missed an important point. You'll have to convert your C# code to C++/CLI.
Darwen.
darwen
August 2nd, 2008, 05:38 PM
I've found these on some more searching :
http://www.codeguru.com/forum/showthread.php?t=440637&highlight=netmodule
and
http://blogs.msdn.com/frankpr/archive/2004/07/27/198918.aspx.
However I'd still recommend just converting your C# code to C++/CLI.
Darwen.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.