PC Review


Reply
Thread Tools Rate Thread

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

 
 
Raj Wall
Guest
Posts: n/a
 
      26th Aug 2006
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


 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?Arne_Vajh=F8j?=
Guest
Posts: n/a
 
      26th Aug 2006
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
 
Reply With Quote
 
Carl Daniel [VC++ MVP]
Guest
Posts: n/a
 
      26th Aug 2006
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


 
Reply With Quote
 
Raj Wall
Guest
Posts: n/a
 
      27th Aug 2006
Arne, Carl, hi,
Thanks for your help.The SDK includes a "Demo.cpp" file that references <windows.h> and 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]" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> 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
>
>

 
Reply With Quote
 
Carl Daniel [VC++ MVP]
Guest
Posts: n/a
 
      27th Aug 2006
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" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
Arne, Carl, hi,
Thanks for your help.The SDK includes a "Demo.cpp" file that references
<windows.h> and two SDK .h files. I have included them below ("Wave59" is
the name of the application).
Thanks again for your help!!
Regards,
Raj


 
Reply With Quote
 
Raj Wall
Guest
Posts: n/a
 
      28th Aug 2006
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]" <(E-Mail Removed)>
wrote in message news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> Arne, Carl, hi,
> Thanks for your help.The SDK includes a "Demo.cpp" file that references
> <windows.h> and two SDK .h files. I have included them below ("Wave59" is
> the name of the application).
> Thanks again for your help!!
> Regards,
> Raj
>
>



 
Reply With Quote
 
Peter Huang [MSFT]
Guest
Posts: n/a
 
      29th Aug 2006
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.

 
Reply With Quote
 
hjgvhv uhhgvjuhv
Guest
Posts: n/a
 
      29th Aug 2006
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
 
Reply With Quote
 
Willy Denoyette [MVP]
Guest
Posts: n/a
 
      29th Aug 2006

"hjgvhv uhhgvjuhv" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
| 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.


 
Reply With Quote
 
hjgvhv uhhgvjuhv
Guest
Posts: n/a
 
      29th Aug 2006
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.
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Building an Application =?Utf-8?B?TVNB?= Microsoft Excel Misc 1 21st Aug 2006 01:20 PM
An outgoing call cannot be made since the application is dispatching an input-synchronous call Sagaert Johan Microsoft C# .NET 4 6th Apr 2005 12:12 AM
Please help - How to call functions that exists in the main application. The call should be initiated from one of the components. Anand Ganesh Microsoft C# .NET 5 16th Oct 2004 01:53 AM
Re: Please help - How to call functions that exists in the main application. The call should be initiated from one of the components. Baavgai Microsoft C# .NET 0 4th Sep 2004 05:54 AM
Building a .net application Microsoft Dot NET 0 23rd Jul 2003 02:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:46 AM.