从VB.net调用的C ++函数 [英] C++ Function called from VB.net

查看:109
本文介绍了从VB.net调用的C ++函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已尝试发布此内容但未得到回复。也许我的帖子太长而复杂。我会再尝试。我有一个DLL,它有一个从C ++应用程序调用的函数。我想从vb.net应用程序调用该函数。这是C ++应用程序中的函数定义:



I tried posting this already but got no response. Maybe my post was too long and complex. I''ll try again. I have a DLL that has a function being called from a C++ app. I want to also call that function from a vb.net app. THis is the function definition in the C++ app:

typedef unsigned int (*DLL_SENDCOMMAND) (const char   *,
                                      const char   ,
                                      unsigned int ,
                                      int          ,
                                      int          ,
                                      int          ,
                                      const char   *,
                                      const char   *,
                                      const char   *,
                                      const char   *,
                                      char         *,
                                      int          );





这是我在我的vb.net应用程序中使用的定义:





This is the definition I am using in my vb.net app:

Private Declare Function SendCommand Lib "STBremoteconfDLL.dll" Alias "?STBRemoteLib_SendCommand@@YAHPBDDIHHH0000PADH@Z" (ByVal cmd As String, ByVal TimeToLive As String, _
        ByRef Timeout As UInteger, ByVal CommandType As Integer, ByVal y2 As Integer, ByVal ConnectTimeOut As Integer, ByVal SaveFile As String, ByVal KeyFile As String, _
        ByVal KeyPhrase As String, ByVal x As String, ByRef str As String, ByVal z As Integer) As UInteger





我的函数声明有问题吗?我知道切入点很好。该功能实际上有效,但它错误,并没有放弃答复。当我调用它时,我得到关于读/写受保护内存的错误。谢谢。



Is there something wrong with my function declaration? I know the entry point is good. The function actually works, but it errors and doesn''t give up the reply. I get that error about reading/writing to protected memory when I call it. Thanks.

推荐答案

看看:使用ACE和C ++ CLI [ ^ ] - 使用C ++ / CLI来弥合托管代码和非托管代码之间的差距通常更容易。



Best问候

Espen Harlinn
Have a look at: Using ACE with C++ CLI[^] - it''s usually easier to use C++/CLI to bridge the gap between managed and unmanaged code.

Best regards
Espen Harlinn


我只能看到一些类型的差异。 C ++ int 默认编组为 System.Int32 ,而不是 UInteger System.UInt32 ),类似于C ++ unsigned int ;更重要的是,C ++ char 是一个8位字符,它被编组为.NET byte



-SA
I can see just some type discrepancy. C++ int is be default marshaled as System.Int32, not UInteger (System.UInt32) which is like C++ unsigned int; more importantly, C++ char is a 8-bit char, it is marshaled as .NET byte.

—SA


要调试这个,你应该提供几个Hello World接口(有和没有参数)并测试该过程是否按预期工作,将int,float,string和其他任何您感兴趣的内容传递给您的应用程序。然后切换到其他功能。



我不认为你正确地验证了语言间的握手细节。
To debug this you should really provide several "Hello World" interfaces (with and without parameters) and test that the process works as you intended, passing int, float, string and anything else of interest to your app. Then switch over to the other functions.

I don''t think you are correctly verifying the inter-language handshake details.


这篇关于从VB.net调用的C ++函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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