开发者

Getting strange error when attempting to convert Unmanaged C++ class to Managed C++ class (for use in .net)

Greetings,

First off, I am not a C++ developer, so please forgive my shortcomings....

I am attempting to take another developer's C++ unmanaged code and re-work it so it can be called from a managed DLL from our c#.net application. Please keep in mind that I'm a .net developer, and I haven't touched C++ in like 12 years. And when I did... I made a rock-paper-scissor game. :(

Anyway... I found a nice little note from another developer on a forum that suggested we go ahead and add a garbage collector to the class in the .h file with "Public __gc". Well, there are two classes I'm trying to convert to managed code, so I went ahead and did that... and one of them just instantly worked! The other... well, is throwing this error:

'cannot convert parameter 5 from 'char *__gc *' to 'char **'

Ok, so I know this has something to do with pointers pointing to more pointers and stuff... but here are the variables in question that DID work when the garbage collector wasn't added to the class name, and now won't build with it added:

<<< HEADER FILE >>>

public __gc class bob { ... public: char *img_buff; ... int init(void); }

<<< CPP FILE >>>

int init(void) { ... nRet = is_AllocImageMem(hcam, img_wid, img_hgt, depth, &开发者_开发问答;img_buff, << doesn't like it here &mem_id ); ... }

Any suggestions or ideas? I just don't know enough about "*" and & and pointers and stuff in C++.

Thanks in advance. Best wishes!!!


What version of Visual Studio do you have? The __gc stuff is Managed C++, which was awful. You want C++/CLI, where the magic words are public ref class. Still, no matter which way you do this, you're going to have to understand pointers a little bit, because you're going to have code that says "I take a native pointer" and you intend to hand it a managed reference to something on the garbage collected heap. You'll have to change that code to make it work.

I am pretty sure using PInvoke is going to be a better plan for you because it won't require as much tweaking of the C++ code. If you have C++ expertise on the team my answer would be different.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜