Exposing C# struct to COM breaks for VB6 app

妖精的绣舞 提交于 2019-12-05 12:01:55

I think I found a solution to this problem. I had the same exact problem, vb6 breaks when calling a method of an interop library by passing an structure. This is a project I created for testing a DLL interop, so all I have in my project was a form. But I had another project (the main application) with the same reference and it works fine.

After reading Joel post, I wanted to test his solution and in fact id did work (using a class instead a structure). But I have other interops where I'm using structures, so I was quite worried that at any point my application might fail. Additionally I didn't want to do the extra work of creating and exposing interface and a class to replace the structure.

So, I took the code from my form and move it to a public sub in a module. It Worked immediately. By the way, that's how i had implemented the call in the main application which was working ok.

I hope it might help others.

Mike Mustaine

Is there some magic to exposing a struct to COM for using in VB6?

The article COM Data Types* on MSDN says that structs are supported. Specifically, the MSDN article says that COM structures are defined as:

ByRef VALUETYPE< MyStruct >

There are also a couple of articles on customing your COM-callable wrappers at the bottom of the page, you may wish to review those.

  • Edit (2016): Original link was broken, so I fixed it to Version 3.5 of the .Net Framework.
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!