为想要调用c ++的应用程序构建C#dll [英] Building a C# dll for an application that wants to call c++

查看:59
本文介绍了为想要调用c ++的应用程序构建C#dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一个允许第三方功能扩展的应用程序

DLL'。用于构建这些DLL的所有规范都是针对c ++的,包含extern的

demo.h文件。声明等


但是不知道c ++我宁愿使用C#。你能否指点一下

关于如何正确使用这个c ++信息的文档/信息

构建我的C#例程以正确连接?


谢谢你的帮助!!

问候,

Raj

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

推荐答案

Raj Wall写道:
Raj Wall wrote:

我有一个允许第三方功能扩展的应用程序

DLL'。用于构建这些DLL的所有规范都是针对c ++的,包含extern的

demo.h文件。声明等


但是不知道c ++我宁愿使用C#。你能否指点一下

关于如何正确使用这个c ++信息的文档/信息

构建我的C#例程来正确连接?
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?



这些DLL的.NET程序集或Win32 DLL是什么?


Arne

Are those DLL''s .NET assemblies or Win32 DLL''s ?

Arne


Raj Wall写道:
Raj Wall wrote:




我有一个允许的应用程序第三个功能扩展

派对DLL'的。用于构建这些DLL的所有规范都是针对

c ++,其中demo.h文件包含extern。声明等


但是不知道c ++我宁愿使用C#。您能否指出

我有关如何使用此c ++信息的文档/信息

正确构建我的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?



赔率相当不错,除非应用程序希望你提供

扩展名作为COM DLL,否则你将无法使用C#构建一个

扩展 - 至少,首先使用托管C ++(或C ++ / CLI,如果你使用VS 2005,是否需要使用VS 2005)来构建一个垫片。 DLL,使您的C#类适应程序所需的基于C的界面。


如果您可以提供一些函数签名类型的示例

应用程序希望你的扩展DLL公开,有人可以

给你更具体的帮助,如何继续。


-cd

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


Arne,Carl,

感谢您的帮助.SDK包含一个Demo.cpp。引用< windows.hand两个SDK .h文件的文件。我已将它们包括在下面(Wave59是应用程序的名称)。

再次感谢您的帮助!!

问候,

Raj

两个SDK .h文件如下:

---

Wave59_SDK.h

-------------------

#ifndef WAVE59_SDK_H

#define WAVE59_SDK_H

struct WAVE59_DATASTRUCT

{

int年,月,日,开始时间,结束时间;

双t;

双开,高,低,收盘;

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

----------------------------- -

和demo .cpp文件如下:

---------------------- -------

#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)

{

//如果我们的长度参数不好,不要崩溃

if((num_int_args< 1 )||(int_args [0]< 1))

返回0;

//过早开始我们的平均值,只需返回收盘价

if(currentptr< int_args [0])

return price_ptr [currentptr] .close;

//计算关闭的简单移动平均值

double average = 0;

for(int i = 0; i< int_args [0]; i ++)

average + = price_ptr [currentptr-i]。关闭;

平均/ =(双)int_args [0];

返回平均值;

}


#pragma argsused

BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fwdreason,LPVOID lpvReserved)

{

返回1;

}

----------------- ----

感谢您的任何建议或指示!

Raj


---------- ---------

Carl Daniel [VC ++ MVP]" < cp ***************************** @ mvps.org.nospamwr ote in message news:u0 ****** ******** @ TK2MSFTNGP04.phx.gbl ...
Arne, Carl,
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写道:
Raj Wall wrote:

>

我有一个应用程序允许通过第三方DLL'进行功能扩展。用于构建这些DLL的所有规范都以
c ++为目标,其中demo.h文件包含extern。语句等

然而,不知道c ++我宁愿使用C#。您能否指出我有关如何使用此c ++信息来正确构建我的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?



赔率相当不错,除非应用程序希望你提供

扩展作为COM DLL,否则你将无法使用C#构建一个

扩展 - 至少,并非没有首先使用托管C ++(或C ++ / CLI,如果你使用VS 2005的
)来构建一个垫片 DLL,使您的C#类适应程序所需的基于C的界面。


如果您可以提供一些函数签名类型的示例

应用程序希望你的扩展DLL公开,有人可以

给你更具体的帮助,如何继续。


-cd

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


这篇关于为想要调用c ++的应用程序构建C#dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆