Well, this is a bit of legacy code that I'm not sure I want to modify.
I'll probably leave it compiled as unmanaged for now, and eventually
get around to re-writing it.
But I will test your hypothesis, once I figure out how...can we pass a
pointer in c++/cli? Don't we have to use IntPtr or something? ??
Thanks,
Sharon
> Well, this is a bit of legacy code that I'm not sure I want to modify.
> I'll probably leave it compiled as unmanaged for now, and eventually
> get around to re-writing it.
Just add a new file to the project that is compiled without /clr. Place the
function into this file. If necessay, you can also write a wrapper function
in this file, that passes all the arguments via one struct pointer or so.
In the file where you want to call the wapper function, just declare it is
usual.
> But I will test your hypothesis, once I figure out how...can we pass a
> pointer in c++/cli? Don't we have to use IntPtr or something? ??
No, you can work with pointers in C++/CLI, no need to use IntPtr.
Marcus
dotnetchic - 11 May 2006 16:30 GMT
> Just add a new file to the project that is compiled without /clr. Place the
> function into this file. If necessay, you can also write a wrapper function
> in this file, that passes all the arguments via one struct pointer or so.
I've been using the #pragma unmanaged/managed keywords to delimit
native functions, but it looks like a lot of my native code will end up
residing in the same file, so I can in some cases compile the entire
file without /clr.
Is this a bad practice? Should I avoid using the #pragma unmanaged
keyword? I'd really hate to write wrappers for all these native
functions. I'm porting a very large codebase.
Sharon
Marcus Heege - 11 May 2006 18:15 GMT
Hi Sharon,
>> Just add a new file to the project that is compiled without /clr. Place
>> the
[quoted text clipped - 9 lines]
> Is this a bad practice? Should I avoid using the #pragma unmanaged
> keyword?
It is a bad practice to use #pragma unmanaged. Native functions should end
up in cpp files compiled to native code and managed functions should end up
in cpp files compiled with /clr.
> I'd really hate to write wrappers for all these native functions. I'm
> porting a very large codebase.
There is no need to write wrappers.The only reason why you had to write one
wrapper frunction was because you reached the limits of P/Invoke
dotnetchic - 11 May 2006 18:35 GMT
Duly noted. I suppose it does make more sense to have all the native
code residing in separate units. Many thanks, Marcus.
> There is no need to write wrappers.The only reason why you had to write one
> wrapper frunction was because you reached the limits of P/Invoke
Speaking of, is this limitation of P/Invoke documented anywhere? I've
been reading up on the usage of P/Invoke for a couple of weeks now, and
only in debugging did I discover this problem.
Sharon
Marcus Heege - 12 May 2006 06:25 GMT
> Duly noted. I suppose it does make more sense to have all the native
> code residing in separate units. Many thanks, Marcus.
[quoted text clipped - 6 lines]
> been reading up on the usage of P/Invoke for a couple of weeks now, and
> only in debugging did I discover this problem.
After you have made me aware of this problem, it will likely be in the book
I am currently witing. Thanks for the info :-)
That was easier than I thought. Pass pointers to the structs instead,
compile as managed, and it appears to run smoothly. Well, the program
crashes :( but it's beyond the scope of this thread.
cheers!