473,325 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

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 2178
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_DATASTRUCT
{
int year,month,day,starttime,endtime;
double t;
double open,high,low,close;
int volume;
int upticks,downticks,equalticks;
bool plotme;
bool ascii_been_here;
};
#endif
----------------------------------
Demo.h
---------------------------------
#ifndef DEMO_H
#define DEMO_H
extern "C" double __declspec(dllexport) average(WAVE59_DATASTRUCT *price_ptr,
int currentptr,int *int_args,int num_int_args,double *double_args,
int num_double_args,char **string_args,int 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(dllexport) average(WAVE59_DATASTRUCT *price_ptr,
int currentptr,int *int_args,int num_int_args,double *double_args,
int num_double_args,char **string_args,int 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_args[0];
return average;
}

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

-------------------
"Carl Daniel [VC++ MVP]" <cp*****************************@mvps.org.nospamwr ote in message news:u0**************@TK2MSFTNGP04.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********@nospam.nospamwrote in message
news:%2****************@TK2MSFTNGP04.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.nospam >
wrote in message news:uO**************@TK2MSFTNGP05.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********@nospam.nospamwrote in message
news:%2****************@TK2MSFTNGP04.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.comwrote in message
news:eM**************@TK2MSFTNGP05.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

"hjgvhv uhhgvjuhv" <as**@asdf.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
| 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#.
|

Grab a copy of the WDK
http://www.microsoft.com/whdc/devtools/ddk/default.mspx and read the Getting
Started with ... chapter. If you really feel the need to start driver
development, you should have a solid knowledge of C and a working knowledge
of Windows OS internals and you should get trained, one great company
specialized in Driver develompment training is OSR - www.osr.com.
|
| | 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 ?
|

C# applications like any other application on Windows operating systems
cannot access the device driver export routines directly (except for User
Mode Device drivers on Vista), all device IO requests must go via the Win32
subsystem using API calls like CreateFile and DeviceIoControl. These API's
are exported from Kernel32.dll so you will have to use PInvoke to call them
from C#.
Willy.
Aug 29 '06 #11
Willy Denoyette [MVP] wrote:
|
| A tutorial on writing device drivers, then accessing those drivers in C#.
|

Grab a copy of the WDK
http://www.microsoft.com/whdc/devtools/ddk/default.mspx and read the Getting
Started with ... chapter. If you really feel the need to start driver
development, you should have a solid knowledge of C and a working knowledge
of Windows OS internals and you should get trained, one great company
specialized in Driver develompment training is OSR - www.osr.com.
Thank You, I'll get it.

>

|
| | 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 ?
|

C# applications like any other application on Windows operating systems
cannot access the device driver export routines directly (except for User
Mode Device drivers on Vista), all device IO requests must go via the Win32
subsystem using API calls like CreateFile and DeviceIoControl. These API's
are exported from Kernel32.dll so you will have to use PInvoke to call them
from C#.
Willy.

I am glad to see that it can be done, "it'll be a pain as usual".
Aug 29 '06 #12
Peter, hi,

Thanks for the sad update. I guess this means I can't use C# to build a mod
for Half-Life either? (The Source SDK uses C++)
http://developer.valvesoftware.com/w..._Release_Notes
Regards,
Raj
""Peter Huang" [MSFT]" <v-******@online.microsoft.comwrote in message
news:%2*****************@TK2MSFTNGXA01.phx.gbl...
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 30 '06 #13
Hi Raj,

Based on my experience, the .NET platform languages (I mean the language
using .NET runtime and IL code) are popular due to its easy using(compared
to C++), but C++ is still alive and keep growing. Because C++ has many
advantages, e.g. the performance.

Also the legacy DLL which export function to working with other DLL/EXE is
not longer working in .NET language. So far to use .NET language built
library in unmanaged code, the COM interop is the main approach. That is
the say, the client needs to be COM client, which should follow the COM
rule to access to the .NET library. Or as we discussed in the previous
posts, use VC++ mix mode to create a wrap.

Also AFAIK, so far most of the Game, especially the 3D gaming it mainly
developed with C++ for performance and many existing 3D engine built in the
past are of C++.

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 31 '06 #14

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

Similar topics

2
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...
10
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...
0
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...
8
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...
13
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...
1
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...
3
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...
0
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...
7
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.