473,734 Members | 2,724 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing c++ dll plugin in c#

I have an application written in c#. I have a c++ wrapper class dll plugIn. I
would like to integrate my c# application with the dll plugin and use the
fuctions written in c++ in my c# code. I need to know how to accessing c++
dll plugin using c#. Can any one give me information and suggestions.

Thanks in advance
Aug 2 '06 #1
5 2138
I am afraid I am not an expert in this, but here is how I got it to work in
one of our little applications... .

C#:
class Program
{
// ready the validation DLL for use
[DllImport("DocV al.dll")]
public static extern String DllMain(string path);
static void Main(string[] args)
{
try
{
// lannch our C++ DLL with the fully qualified path to the
document
String response =
DllMain(@"\\sha re\SharedDocs\t est\Sometext.tx t");
Console.WriteLi ne("Validation response is: " + response);
}
catch (Exception exec)
{
Console.WriteLi ne("There was an internal error with the DLL
:-( Details: " + exec.Message);
}
}
-----------------------
in C++: ( I choose to make a new dll project in the editor)
......normal header stuff ....

#pragma data_seg("Share dBlockOMemory")
// shared stuff here... (if needed)
#pragma data_seg()

// these are the functions we can call outside of our DLL if need be
extern LPCSTR _declspec(dllex port) DllMain(char * pathToFile);
LPCSTR _declspec(dllex port) DllMain(char * pathToFile)
{
char inputFile[255]; // our input .txt file
bool verboseMode = false; // to keep track if we want everything
logged verbosely
bool ignoreFileExten sion = false; // to see if we are to ignore the file
extension

sprintf(inputFi le, "%s\0", pathToFile); // and store it into a char[]

inputFileCStrin g = pathToFile; // assign this to a CString for use later

// ... your work here...

return /*(something in LPCSTR format)*/ "Hello!";
} // end DllMain ()

Note that you may have trouble using CStrings in your C++ code... I had to
take almost all of them out when I converted some of our stuff to dlls...
expecially CString return types from calling any functions within your C
code. I used char *'s and that seemed to work well.

Hope this gets you started...

Rob K

Aug 2 '06 #2
Thank you for your reply. But the problem is I am using third party plugin. I
must use functions of a COM-interface that the plugin provides me. I think
now my problem is more clear to you. Do you have any solutions??
"RobKinney1 " wrote:
I am afraid I am not an expert in this, but here is how I got it to work in
one of our little applications... .

C#:
class Program
{
// ready the validation DLL for use
[DllImport("DocV al.dll")]
public static extern String DllMain(string path);
static void Main(string[] args)
{
try
{
// lannch our C++ DLL with the fully qualified path to the
document
String response =
DllMain(@"\\sha re\SharedDocs\t est\Sometext.tx t");
Console.WriteLi ne("Validation response is: " + response);
}
catch (Exception exec)
{
Console.WriteLi ne("There was an internal error with the DLL
:-( Details: " + exec.Message);
}
}
-----------------------
in C++: ( I choose to make a new dll project in the editor)
.....normal header stuff ....

#pragma data_seg("Share dBlockOMemory")
// shared stuff here... (if needed)
#pragma data_seg()

// these are the functions we can call outside of our DLL if need be
extern LPCSTR _declspec(dllex port) DllMain(char * pathToFile);
LPCSTR _declspec(dllex port) DllMain(char * pathToFile)
{
char inputFile[255]; // our input .txt file
bool verboseMode = false; // to keep track if we want everything
logged verbosely
bool ignoreFileExten sion = false; // to see if we are to ignore the file
extension

sprintf(inputFi le, "%s\0", pathToFile); // and store it into a char[]

inputFileCStrin g = pathToFile; // assign this to a CString for use later

// ... your work here...

return /*(something in LPCSTR format)*/ "Hello!";
} // end DllMain ()

Note that you may have trouble using CStrings in your C++ code... I had to
take almost all of them out when I converted some of our stuff to dlls...
expecially CString return types from calling any functions within your C
code. I used char *'s and that seemed to work well.

Hope this gets you started...

Rob K
Aug 2 '06 #3
Hmm... I am not sure then. The only other kind of dll stuff I have done is
calling a managed dll that calls an unmanaged dll (written in C++).. but all
that required is a call to\a namespace defined in the managed dll.

I hope someone else here can help. This is the limit of my experience in
this area.

Best of Luck,

Rob K

"Aravind" wrote:
Thank you for your reply. But the problem is I am using third party plugin. I
must use functions of a COM-interface that the plugin provides me. I think
now my problem is more clear to you. Do you have any solutions??
"RobKinney1 " wrote:
Aug 2 '06 #4
If it's a COM dll, then you are looking into Interop.

You need to add a reference to that COM dll.

At the top of the using, include the com interface like this:
using System.Runtime. InteropServices ;
using *** YourCOM ***

Then, all the COM interface should be visible to you.

The code is like this :

m_oComObject = new ComObjectClass( );
After finishing, do this:
Marshal.Release ComObject(m_m_o ComObject);
HTH

Jianwei

Aravind wrote:
Thank you for your reply. But the problem is I am using third party plugin. I
must use functions of a COM-interface that the plugin provides me. I think
now my problem is more clear to you. Do you have any solutions??
"RobKinney1 " wrote:
>I am afraid I am not an expert in this, but here is how I got it to work in
one of our little applications... .

C#:
class Program
{
// ready the validation DLL for use
[DllImport("DocV al.dll")]
public static extern String DllMain(string path);
static void Main(string[] args)
{
try
{
// lannch our C++ DLL with the fully qualified path to the
document
String response =
DllMain(@"\\sh are\SharedDocs\ test\Sometext.t xt");
Console.WriteLi ne("Validation response is: " + response);
}
catch (Exception exec)
{
Console.WriteLi ne("There was an internal error with the DLL
:-( Details: " + exec.Message);
}
}
-----------------------
in C++: ( I choose to make a new dll project in the editor)
.....normal header stuff ....

#pragma data_seg("Share dBlockOMemory")
// shared stuff here... (if needed)
#pragma data_seg()

// these are the functions we can call outside of our DLL if need be
extern LPCSTR _declspec(dllex port) DllMain(char * pathToFile);
LPCSTR _declspec(dllex port) DllMain(char * pathToFile)
{
char inputFile[255]; // our input .txt file
bool verboseMode = false; // to keep track if we want everything
logged verbosely
bool ignoreFileExten sion = false; // to see if we are to ignore the file
extension

sprintf(inputFi le, "%s\0", pathToFile); // and store it into a char[]

inputFileCStrin g = pathToFile; // assign this to a CString for use later

// ... your work here...

return /*(something in LPCSTR format)*/ "Hello!";
} // end DllMain ()

Note that you may have trouble using CStrings in your C++ code... I had to
take almost all of them out when I converted some of our stuff to dlls...
expecially CString return types from calling any functions within your C
code. I used char *'s and that seemed to work well.

Hope this gets you started...

Rob K
Aug 2 '06 #5
Thanks alot Rob n Jianwei. Its a com dll so I will try today as Jianwei
suggestion and tell you guys if it works.

Aravind.
"Jianwei Sun" wrote:
If it's a COM dll, then you are looking into Interop.

You need to add a reference to that COM dll.

At the top of the using, include the com interface like this:
using System.Runtime. InteropServices ;
using *** YourCOM ***

Then, all the COM interface should be visible to you.

The code is like this :

m_oComObject = new ComObjectClass( );
After finishing, do this:
Marshal.Release ComObject(m_m_o ComObject);
HTH

Jianwei

Aravind wrote:
Thank you for your reply. But the problem is I am using third party plugin. I
must use functions of a COM-interface that the plugin provides me. I think
now my problem is more clear to you. Do you have any solutions??
"RobKinney1 " wrote:
I am afraid I am not an expert in this, but here is how I got it to work in
one of our little applications... .

C#:
class Program
{
// ready the validation DLL for use
[DllImport("DocV al.dll")]
public static extern String DllMain(string path);
static void Main(string[] args)
{
try
{
// lannch our C++ DLL with the fully qualified path to the
document
String response =
DllMain(@"\\sha re\SharedDocs\t est\Sometext.tx t");
Console.WriteLi ne("Validation response is: " + response);
}
catch (Exception exec)
{
Console.WriteLi ne("There was an internal error with the DLL
:-( Details: " + exec.Message);
}
}
-----------------------
in C++: ( I choose to make a new dll project in the editor)
.....normal header stuff ....

#pragma data_seg("Share dBlockOMemory")
// shared stuff here... (if needed)
#pragma data_seg()

// these are the functions we can call outside of our DLL if need be
extern LPCSTR _declspec(dllex port) DllMain(char * pathToFile);
LPCSTR _declspec(dllex port) DllMain(char * pathToFile)
{
char inputFile[255]; // our input .txt file
bool verboseMode = false; // to keep track if we want everything
logged verbosely
bool ignoreFileExten sion = false; // to see if we are to ignore the file
extension

sprintf(inputFi le, "%s\0", pathToFile); // and store it into a char[]

inputFileCStrin g = pathToFile; // assign this to a CString for use later

// ... your work here...

return /*(something in LPCSTR format)*/ "Hello!";
} // end DllMain ()

Note that you may have trouble using CStrings in your C++ code... I had to
take almost all of them out when I converted some of our stuff to dlls...
expecially CString return types from calling any functions within your C
code. I used char *'s and that seemed to work well.

Hope this gets you started...

Rob K
Aug 3 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2997
by: Julius Mong | last post by:
Dear all, I have something like this: <html... > <embed ...> </html> Am I out of luck if I wanted to access the embedded DOM and manipulate its content? Or if I have:
5
2167
by: ilKaos | last post by:
hi all. I have a script that tries to open a file that is on a different folder than the one in which i am working. that is the script: openmydoc= "file://///192.168.1.1/web/" + type+ "/" + year+ "/" + Month+ "/myfile.xyz" ; open(openmydoc);
2
20956
by: Rudolf | last post by:
Dear NG, I want to create a Plugin System in C# (WinForms). Has anybody experience about this, tips, tricks, or any links. Thank you very much The DotNetJunkie
6
1580
by: Jack Addington | last post by:
I've got a bit of a problem acceessing a class that I am using as a 'global' placeholder of numerous static variables I'm using across the application. Basically I need a place to store a reference to my MDIframe so I can access it from anywhere. I have a class called AppObj in a framework assembly. I inherited it in my main application assembly and called it EPMApp. In my mainform (which is a mdiframe) I am setting the EPMApp.MDIFrame...
2
2792
by: Edvard Majakari | last post by:
Hi, My idea is to create a system working as follows: each module knows path to plugin directory, and that directory contains modules which may add hooks to some points in the code. Inspired by http://www.python.org/pycon/2005/papers/7/pyconHooking.html I would create a class like this:
2
3318
by: Ron | last post by:
Hello, I'm attempting to develop a plugin framework for an application that I'm working on. I wish to develop something in which all plugins exist in a directory tree. The framework need only be given the root of the tree. The framework then uses os.path.walk to search all for all files named 'plugin.pyc'. These are then loaded using imp.load_compiled(). They need contain only one variable called 'plugin' which is a reference to an...
2
1850
by: Aravind | last post by:
I have 3rd party dll plugin COM interface, when loaded executes the following functions. public class Test: IPlugin { public void Innitialize(IPluginApp obj, int pluginHandle) { //gets the plugin obj dynamically to work with third party application. //can be added events etc. }
7
10600
by: WTH | last post by:
I am now aware (I am primarily a C++ developer) that in C# if you reference the same interface from the same file in two different projects the types are actually incompatible. I found this out because I have written a generic plugin system for my current and future C# needs. I defined a base plugin system interface named IPlugin (original, I know...) which contains some basic plugin infomration all plugins of this system must expose...
0
838
by: chewanmak | last post by:
Hi, I am working on a C# IE plugin. When a user clicks the icon of the plugin in a IE browser, it activates my plugin code to read the source code of the web page displaying and performs some action. My problem is how can the plugin know which instance of the IE active it and how can it retrieve the source code of the page. You help is greatly appreciated
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9449
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9310
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.