473,781 Members | 2,413 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Building a C# dll for an application that wants to call c++

Hi,

I have an application that allows functionality extension by third party
DLL's. All the specs for building these DLL's are targeted to c++, with
demo.h files containing "extern" statements, etc.

However not really knowing c++ I would rather use C#. Could you point me to
documentation/information on how to use this c++ information to properly
construct my C# routine to connect properly?

Thank-you for your help!!
Regards,
Raj
Aug 26 '06 #1
13 2214
Raj Wall wrote:
I have an application that allows functionality extension by third party
DLL's. All the specs for building these DLL's are targeted to c++, with
demo.h files containing "extern" statements, etc.

However not really knowing c++ I would rather use C#. Could you point me to
documentation/information on how to use this c++ information to properly
construct my C# routine to connect properly?
Are those DLL's .NET assemblies or Win32 DLL's ?

Arne
Aug 26 '06 #2
Raj Wall wrote:
Hi,

I have an application that allows functionality extension by third
party DLL's. All the specs for building these DLL's are targeted to
c++, with demo.h files containing "extern" statements, etc.

However not really knowing c++ I would rather use C#. Could you point
me to documentation/information on how to use this c++ information to
properly construct my C# routine to connect properly?
Odds are reasonably good that unless the application expects you to provide
extensions as COM DLLs then you won't be able to use C# to build an
extension - at least, not without first using managed C++ (or C++/CLI if
you're using VS 2005) to build a "shim" DLL that adapts your C# class to the
C-based interface that the program requires.

If you can give some examples of the types of function signatures that the
application expects your extension DLL to expose, someone will be able to
give you more specific help on how to proceed.

-cd
Aug 26 '06 #3
Arne, Carl, hi,
Thanks for your help.The SDK includes a "Demo.cpp" file that references <windows.hand two SDK .h files. I have included them below ("Wave59" is the name of the application).
Thanks again for your help!!
Regards,
Raj
The two SDK .h files are as follows:
---
Wave59_SDK.h
-------------------
#ifndef WAVE59_SDK_H
#define WAVE59_SDK_H
struct WAVE59_DATASTRU CT
{
int year,month,day, starttime,endti me;
double t;
double open,high,low,c lose;
int volume;
int upticks,downtic ks,equalticks;
bool plotme;
bool ascii_been_here ;
};
#endif
----------------------------------
Demo.h
---------------------------------
#ifndef DEMO_H
#define DEMO_H
extern "C" double __declspec(dlle xport) average(WAVE59_ DATASTRUCT *price_ptr,
int currentptr,int *int_args,int num_int_args,do uble *double_args,
int num_double_args ,char **string_args,i nt num_string_args );
#endif
-------------------------------
And the demo .cpp file is as follows:
-----------------------------
#include <windows.h>
#include "Wave59_SDK .h"
#include "Demo.h"
extern "C" double __declspec(dlle xport) average(WAVE59_ DATASTRUCT *price_ptr,
int currentptr,int *int_args,int num_int_args,do uble *double_args,
int num_double_args ,char **string_args,i nt num_string_args )
{
//don't crash if we've got a bad length parameter
if ((num_int_args< 1)||(int_args[0]<1))
return 0;
//too soon to start our average, just return the close
if (currentptr<int _args[0])
return price_ptr[currentptr].close;
//calculate a simple moving average of the closes
double average=0;
for (int i=0; i<int_args[0]; i++)
average+=price_ ptr[currentptr-i].close;
average/=(double)int_ar gs[0];
return average;
}

#pragma argsused
BOOL WINAPI DllMain(HINSTAN CE hinstDLL, DWORD fwdreason, LPVOID lpvReserved)
{
return 1;
}
---------------------
Thanks for any advice or pointers!
Raj

-------------------
"Carl Daniel [VC++ MVP]" <cp************ *************** **@mvps.org.nos pamwrote in message news:u0******** ******@TK2MSFTN GP04.phx.gbl...
Raj Wall wrote:
>Hi,

I have an application that allows functionality extension by third
party DLL's. All the specs for building these DLL's are targeted to
c++, with demo.h files containing "extern" statements, etc.

However not really knowing c++ I would rather use C#. Could you point
me to documentation/information on how to use this c++ information to
properly construct my C# routine to connect properly?
Odds are reasonably good that unless the application expects you to provide
extensions as COM DLLs then you won't be able to use C# to build an
extension - at least, not without first using managed C++ (or C++/CLI if
you're using VS 2005) to build a "shim" DLL that adapts your C# class to the
C-based interface that the program requires.

If you can give some examples of the types of function signatures that the
application expects your extension DLL to expose, someone will be able to
give you more specific help on how to proceed.

-cd

Aug 27 '06 #4
Raj -

You're going to need to use C or C++ to make an extension for that app. You
could write a wrapper in managed C++ that adapts a C# class to that
interface, but AFIAK there's no way to make a DLL that exposes that
interface directly in C#.

-cd
"Raj Wall" <me********@nos pam.nospamwrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
Arne, Carl, hi,
Thanks for your help.The SDK includes a "Demo.cpp" file that references
<windows.hand two SDK .h files. I have included them below ("Wave59" is
the name of the application).
Thanks again for your help!!
Regards,
Raj
Aug 27 '06 #5
Carl, hi,

*sigh* thanks--I was afraid of that. I was hoping something existed for c++
interfaces similar in ease of use to the ActiveX interop "drop-in", which
automagically eats a ActiveX and gives you a nice i/f to it.

Regards,
Raj

"Carl Daniel [VC++ MVP]" <cp************ *************** **@mvps.org.nos pam>
wrote in message news:uO******** ******@TK2MSFTN GP05.phx.gbl...
Raj -

You're going to need to use C or C++ to make an extension for that app.
You could write a wrapper in managed C++ that adapts a C# class to that
interface, but AFIAK there's no way to make a DLL that exposes that
interface directly in C#.

-cd
"Raj Wall" <me********@nos pam.nospamwrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
Arne, Carl, hi,
Thanks for your help.The SDK includes a "Demo.cpp" file that references
<windows.hand two SDK .h files. I have included them below ("Wave59" is
the name of the application).
Thanks again for your help!!
Regards,
Raj


Aug 28 '06 #6
Hi Raj,

So far .NET provides two approaches to interop with unmanaged code.
1. P/Invoke, calling unmanaged C++ legacy DLL from .NET.
2. COM Interop, Calling .NET code from unmanaged COM Client or Calling
unmanaged COM server from .NET.
Interoperating with Unmanaged Code
http://msdn2.microsoft.com/en-us/library/sd10k43k.aspx

But so far .NET did not provide such an approach that make a C# .NET
assembly and export function just as legacy C++ DLL do.

Now a possible approach is to write a mix-mode managed C++ to wrap the C#
dll just as Carl said.

If you have further question about this issue, please feel free to post
here and I am happy to be of assistance.
Best regards,

Peter Huang

Microsoft Online Community Support
=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Aug 29 '06 #7
Peter Huang [MSFT] wrote:
Hi Raj,

So far .NET provides two approaches to interop with unmanaged code.
1. P/Invoke, calling unmanaged C++ legacy DLL from .NET.
2. COM Interop, Calling .NET code from unmanaged COM Client or Calling
unmanaged COM server from .NET.
Interoperating with Unmanaged Code
http://msdn2.microsoft.com/en-us/library/sd10k43k.aspx

But so far .NET did not provide such an approach that make a C# .NET
assembly and export function just as legacy C++ DLL do.

Now a possible approach is to write a mix-mode managed C++ to wrap the C#
dll just as Carl said.

If you have further question about this issue, please feel free to post
here and I am happy to be of assistance.
Best regards,

Peter Huang

Microsoft Online Community Support
=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.
I for one would like to have a tutorial on how to access hardware in C#.

C++ was a pain, and C# is not possible.

Please try to address the hardware interface of C#.

Thank You
Donald
Aug 29 '06 #8

"hjgvhv uhhgvjuhv" <as**@asdf.comw rote in message
news:eM******** ******@TK2MSFTN GP05.phx.gbl...
| Peter Huang [MSFT] wrote:
| Hi Raj,
| >
| So far .NET provides two approaches to interop with unmanaged code.
| 1. P/Invoke, calling unmanaged C++ legacy DLL from .NET.
| 2. COM Interop, Calling .NET code from unmanaged COM Client or Calling
| unmanaged COM server from .NET.
| Interoperating with Unmanaged Code
| http://msdn2.microsoft.com/en-us/library/sd10k43k.aspx
| >
| But so far .NET did not provide such an approach that make a C# .NET
| assembly and export function just as legacy C++ DLL do.
| >
| Now a possible approach is to write a mix-mode managed C++ to wrap the
C#
| dll just as Carl said.
| >
| If you have further question about this issue, please feel free to post
| here and I am happy to be of assistance.
| >
| >
| Best regards,
| >
| Peter Huang
| >
| Microsoft Online Community Support
| =============== =============== =============== =====
| When responding to posts, please "Reply to Group" via your newsreader so
| that others may learn and benefit from your issue.
| =============== =============== =============== =====
| This posting is provided "AS IS" with no warranties, and confers no
rights.
| >
|
| I for one would like to have a tutorial on how to access hardware in C#.
|
A tutorial of what? It's just not possible to use .NET to access the
hardware, at least not directly.
| C++ was a pain, and C# is not possible.
|

No it's not possible, but this has nothing to do with C#, which is after all
just a programming language, it's the framework (CLR and FCL) which is not
suited to directly access hardware (devices), this is the domain of device
driver programming using C and/or C++. C# just like any other .NET language
can only access the hardware via the device driver interface.

Willy.
Aug 29 '06 #9
Willy Denoyette [MVP] wrote:
|
| I for one would like to have a tutorial on how to access hardware in C#.
|
A tutorial of what? It's just not possible to use .NET to access the
hardware, at least not directly.
A tutorial on writing device drivers, then accessing those drivers in C#.

| C++ was a pain, and C# is not possible.
|

No it's not possible, but this has nothing to do with C#, which is after all
just a programming language, it's the framework (CLR and FCL) which is not
suited to directly access hardware (devices), this is the domain of device
driver programming using C and/or C++. C# just like any other .NET language
can only access the hardware via the device driver interface.
Does C# have a standard way of accessing device drivers ?

Are there any good links on how this is can be done ??

>
Willy.

Aug 29 '06 #10

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

Similar topics

2
1451
by: Job Lot | last post by:
I have created an application which creates a financial plan for our customers. Now my financial planner wants to distribute a copy of application to our customer with their respective plans and limited functionality. How can I can I do this? I am using SQL Server at the back end with several stored procedures. I’ll have to distribute a copy of .NET Framework and MDAC as well. Moreover I’ll have to distribute the application on a CD as...
10
2139
by: Saso Zagoranski | last post by:
hi, this is not actually a C# problem but since this is the only newsgroup I follow I decided to post my question here (please tell me where to post this next time if you think this post shouldn't be here). I have two design questions: 1. what is the correct (or best) way to include database queries into the code if you plan on
0
1573
by: Irfan Akram | last post by:
Hello People, I would appreciate your responses on this. I am writing an asp.net web-application involving C#. I am actually building a test hierarchy at the moment, which involves producing dynamic controls, depending on user response. To be more precise, I prompt the user for the number of questions, that should be in the test. He types in a number, say 10. Then I need to ask him
8
1516
by: Sericinus hunter | last post by:
I hope this is right group for the question. If not, please forgive me and give some pointers. I have VS 2003 and Web application project which builds and works just fine. I need to build the project with command line on a different machine, which does not have IIS running. Devenv naturally wants the working virtual folder exist. Is it at all possible to instruct it not refer to the URL? Theoretically, it should not be necessary just...
13
3998
by: royaltiger | last post by:
I am trying to copy the inventory database in Building Access Applications by John L Viescas but when i try to run the database i get an error in the orders form when i click on the allocate button "Unexpected Error":3251 operation is not supported for this type of object.The demo cd has two databases, one is called inventory and the other just has the tables for the design called inventory data. When you run inventory the database works...
1
1448
by: Diffident | last post by:
Hello All, I have a question as to why my users are noticing error when I am building the project on the production system. Here is the problem's background. In order to build the project on the production system, I use the Visual Studio's File > Open From Web and then build the solution. Some of the build settings are as follows: Output path: bin
3
3284
by: Bill Davidson | last post by:
All: I have a problem in which a worker thread in my (.dll) assembly isn't allowing the main (.exe) assembly from terminating. Here's the scenario: 1) App.Exe is launched. 2) App.Exe calls into my .dll (Sub.Dll)
0
1194
by: ...:::JA:::... | last post by:
Hello, I have problem with building directpython ( .exe ) application , actually when I finish building application and when I run it, in log file I get an error: Traceback (most recent call last): File "sampleMeshAnim.py", line 16, in ?
7
7158
Curtis Rutland
by: Curtis Rutland | last post by:
Building A Silverlight (2.0) Multi-File Uploader All source code is C#. VB.NET source is coming soon. Note: This project requires Visual Studio 2008 SP1 or Visual Web Developer 2008 SP1 and Silverlight 2.0. To get these tools please visit this page Get Started : The Official Microsoft Silverlight Site and follow Step 1. Occasionally you find the need to have users upload multiple files at once. You could use multiple FileUpload...
0
10306
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...
1
10075
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9931
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8961
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7485
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
6727
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5373
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...
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.