需要从非托管c ++代码调用托管代码!

编程入门 行业动态 更新时间:2024-10-28 06:31:32
本文介绍了需要从非托管c ++代码调用托管代码!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个要求,我需要从一个 C ++代码调用用VB.Net编写的方法。我一直在疯狂阅读网上的各种文章 互操作和编组,但现在更加困惑了。 我需要符合的签名VB.Net DLL是 int MyAppInitFunc(int argc,char ** argv) 到这个程度我试过以下 公共函数MyAppInitFunc(ByVal argc as integer,ByRef argv as string) as Integer 公共函数MyAppInitFunc(ByVal argc as Int32,ByVal argv()as string ) 作为Int32 ....基于我甚至尝试的一些帖子 公共函数MyAppInitFunc(ByVal argc as Int32 ,ByVal argv as IntPtr) Int32 但是还没能得到任何工作。 是否有一些阅读我错过了? 问候。 - Ravi Shankar

解决方案

我通过COM完成所有vb6互操作,这个效果很好 也许这是你的想法? 问候 米歇尔 " Ravi Shankar" < sh ********* @ newsgroup.nospamschreef in bericht 新闻:4F ********************* ************* @ microsof t ...

我有一个要求,我需要从 C ++代码中调用VB.Net编写的方法。我一直疯狂阅读网上的各种文章 wrt 互操作和编组,但现在更加困惑。 我需要在VB.Net DLL中符合的签名是 int MyAppInitFunc(int argc,char ** argv) 在这个程度上,我有试过以下 公共函数MyAppInitFunc(ByVal argc作为整数,ByRef argv作为字符串) 作为整数 公共函数MyAppInitFunc(ByVal argc as Int32,ByVal argv()as string) as Int32 Public函数MyAppInitFunc(ByVal argc as Int32,ByVal argv as IntPtr) as Int32 但未能获得什么都可以工作。 是否有一些阅读我错过了? 问候。 - Ravi Shankar

>我需要的签名在VB.Net DLL中符合

> int MyAppInitFunc(int argc,char ** argv)

这是否意味着C ++调用者希望这样的函数是从DLL导出的静态输出入口点? VB不允许你这样做。 Mattias - Mattias Sj?gren [C#MVP] mattias @ mvps www.msjogren/dotnet/ | www.dotnetinterop 请回复到新闻组。

Hello Michel, 请解释..我已经用注册COM Interop制作了我的项目;。我还是也做了一个regasm / tlb:..... 我的所有功能都是ComVisible()。 由于VB.Net DLL和经典的Win32 DLL有区别, 我甚至做过IL调整以确保我的函数正在运行导出。 我无法弄清楚如何将Char **编组到我的托管代码中? 我尝试的组合是 1.< MarshalAs(UnmanagedType.SafeArray,SafeArraySubType:= VarEnum.VT_BSTR)> ByVal argv as string() 这给了我一个错误,说11888等级的SafeArray已被传递给 方法,期望排名为1的数组 2.< MarshalAs (Unmanaged.LPArray)ByRef argv as string 这给我一个错误,说不能编组''参数#2'':无效 托管/非托管类型组合(字符串参数和返回类型必须 与LPStr,LP配对WStr,LPTStr,BSTR,TBStr,VBByRefStr或AnsiBStr)。 和上面的组合使用char()()而不是string()等等。 x - Ravi Shankar " Michel Posseth [MCP]"写道:

我通过COM做我所有的vb6互操作,这个效果很好 也许这是你的想法? 问候 米歇尔 " Ravi Shankar" < sh ********* @ newsgroup.nospamschreef in bericht 新闻:4F ********************* ************* @ microsof t ...

我有一个要求,我需要从 C ++代码中调用VB.Net编写的方法。我一直疯狂阅读网上的各种文章 wrt 互操作和编组,但现在更加困惑。 我需要在VB.Net DLL中符合的签名是 int MyAppInitFunc(int argc,char ** argv) 在这个程度上,我有试过以下 公共函数MyAppInitFunc(ByVal argc作为整数,ByRef argv作为字符串) 作为整数 公共函数MyAppInitFunc(ByVal argc as Int32,ByVal argv()as string) as Int32 Public函数MyAppInitFunc(ByVal argc as Int32,ByVal argv as IntPtr) as Int32 但未能获得什么都可以工作。 是否有一些阅读我错过了? 问候。 - Ravi Shankar

Hi, I have a requirement where I need to call methods written in VB.Net from a C++ code. I have been going crazy reading various articles on the net w.r.t interop and marshalling but an more confused now that before. the signature I need to conform in the VB.Net DLL is int MyAppInitFunc(int argc, char** argv) To this extent I have tried the following Public Function MyAppInitFunc(ByVal argc as integer, ByRef argv as string) as Integer Public Function MyAppInitFunc(ByVal argc as Int32, ByVal argv() as string) as Int32 .... based on some posts I even tried Public Function MyAppInitFunc(ByVal argc as Int32, ByVal argv as IntPtr) as Int32 but have not been able to get anything to work. Is there perhaps some reading I''m missing up on ? Regards. -- Ravi Shankar

解决方案

I do all my vb6 interop through COM , this works great maybe this is an idea for you to ? Regards Michel "Ravi Shankar" <sh*********@newsgroup.nospamschreef in bericht news:4F**********************************@microsof t...

Hi, I have a requirement where I need to call methods written in VB.Net from a C++ code. I have been going crazy reading various articles on the net w.r.t interop and marshalling but an more confused now that before. the signature I need to conform in the VB.Net DLL is int MyAppInitFunc(int argc, char** argv) To this extent I have tried the following Public Function MyAppInitFunc(ByVal argc as integer, ByRef argv as string) as Integer Public Function MyAppInitFunc(ByVal argc as Int32, ByVal argv() as string) as Int32 ... based on some posts I even tried Public Function MyAppInitFunc(ByVal argc as Int32, ByVal argv as IntPtr) as Int32 but have not been able to get anything to work. Is there perhaps some reading I''m missing up on ? Regards. -- Ravi Shankar

>the signature I need to conform in the VB.Net DLL is

>int MyAppInitFunc(int argc, char** argv)

Does that mean the C++ caller expects such a function to be a staticly exported entrypoint from the DLL? VB doesn''t let you do that. Mattias -- Mattias Sj?gren [C# MVP] mattias @ mvps www.msjogren/dotnet/ | www.dotnetinterop Please reply only to the newsgroup.

Hello Michel, Please explain.. I have made my project with "Register for COM Interop". I have also done a regasm /tlb:..... All my functions are ComVisible(). Since there is a difference in the VB.Net DLL''s and classic Win32 DLL''s, I''ve even done the IL tweaking to ensure that my functions are being exported. I can''t figure out how to get Char** marshalled into my managed code ? The combinations Ive tried are 1. <MarshalAs(UnmanagedType.SafeArray, SafeArraySubType:=VarEnum.VT_BSTR)> ByVal argv as string() This gives me an error saying SafeArray of rank 11888 has been passed to a method expecting an array of rank 1 2. <MarshalAs(Unmanaged.LPArray)ByRef argv as string This gives me an error saying cannot marshal ''parameter #2'' : Invalid managed/unmanaged type combination (string parameters and return types must be paired with LPStr, LPWStr, LPTStr, BSTR, TBStr, VBByRefStr, or AnsiBStr). and combiantions of the above with char()() instead of string() etc, etc. x-- Ravi Shankar "Michel Posseth [MCP]" wrote:

I do all my vb6 interop through COM , this works great maybe this is an idea for you to ? Regards Michel "Ravi Shankar" <sh*********@newsgroup.nospamschreef in bericht news:4F**********************************@microsof t...

Hi, I have a requirement where I need to call methods written in VB.Net from a C++ code. I have been going crazy reading various articles on the net w.r.t interop and marshalling but an more confused now that before. the signature I need to conform in the VB.Net DLL is int MyAppInitFunc(int argc, char** argv) To this extent I have tried the following Public Function MyAppInitFunc(ByVal argc as integer, ByRef argv as string) as Integer Public Function MyAppInitFunc(ByVal argc as Int32, ByVal argv() as string) as Int32 ... based on some posts I even tried Public Function MyAppInitFunc(ByVal argc as Int32, ByVal argv as IntPtr) as Int32 but have not been able to get anything to work. Is there perhaps some reading I''m missing up on ? Regards. -- Ravi Shankar

更多推荐

需要从非托管c ++代码调用托管代码!

本文发布于:2023-11-02 18:09:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1553057.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:代码

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!