Thursday, June 16, 2005

Frustrating Code

I have this function, written in unmanaged(native) C++. I need to call that function from within a .NET application. As I understand it, the only way to accomplish this is to use p/invoke. The only problem is that this method is meant to be added as part of an existing C++ app, so it isn't really designed to go into a .dll. You have to have(I think) your code in a dll to call it from .NET.

I tried creating a C++ dll several ways, but none worked. Anyone have any other ideas?

4 comments:

Anonymous said...

#pragma unmanaged

Cullen Waters said...

Can you give me an example of how you do that? Does it only work in a managed C++ class, or can I use that in a C# class? Some sample code would be great

Anonymous said...

Can't paste the code in the comment, so heres a link to the sample from MSDN...

http://msdn.microsoft.com/library
/default.asp?url=/library/en-us/vclang
/html/vcerrManagedUnmanaged.asp

Anonymous said...

And it's a #pragma, so it's only for C++. C# is another matter, the only way I know of is to create a managed wrapper around the C++ code or use platform invoke.