I am trying to code up a DLL that does a bunch of things, including file I/O, string split, processing, output a lot of information. I am using VS2008, .net 3.5, C++
I followed this article
http://msdn.microsoft.com/en-us/library/ms235636.aspx
First I build a caller(tester) project in the solution and try to call a test function in the dll, and that works. So I proceed to turn on CLR compile flag in the DLL, so that I can do string processing easier. But that gives me a link error. I tried turning on the CLR compile flag in the caller project and suddenly i have two link error.
What do i have to do to be 开发者_运维百科able to use CLR inside DLL and be able to return the result as an object back to the caller?
Yes, you can pass CLR types through flat APIs at the DLL boundary. But only other C++-based /clr code would be able to consume them. And because there is just one IAT for a process, this won't always work right if you have multiple appdomains.
The recommended way to pass managed types would be through direct managed references.
Martyn
Put your functions inside a
public ref struct
and then using managed types for parameters and return values becomes very straightforward.
If you want to call the functions without creating an object first, make them static.
精彩评论