Link C++ static lib in C# project - confirm not possible?

  • Thread starter Thread starter Bret Pehrson
  • Start date Start date
B

Bret Pehrson

I just need to confirm now (after I've spent several days chasing mystery
metadata warnings/errors) that this is *NOT* possible:

Link a managed C++ static library into a (managed) C# application.

NOT POSSIBLE?

Please respond *only* if you *know* the answer, I'm not interested in
conjecture.

For those that care: my project is *not* trivial, and is a migration from C++.
The library in question is composed of 100's of files, and isn't trivial to
convert to either a DLL or C# (at least w/o seriously affecting my timeline).

Finally, presuming that the above is not possible, why wouldn't the C#
compiler/linker emit a simple error such as "Cannot link C/C++ static library
with C# project"?
 
NO, its not possible, the compiler doesn't emit a simple error because there
is no link step involved when compiling a C# source file.

Willy.
 
Hello Bret,

Thanks for your post. As I understand, you have a .NET Managed Class
Library created by C++ and want to link it directly to C# project. Please
correct me if there is any misunderstanding. I now share the following
information with you:

Willy is correct that it's not possible. If it's a .NET Managed Class
Library, you can add reference to it and use it in your C# project.

If it's a Win32 Static Library, you can create C++ DLL which simply links
to the Static Library and put the names of the functions that need to be
exported to the .DEF file of the DLL. Then, your C# application can call
the functions via P/Invoke.

Consuming Unmanaged DLL Functions
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconconsumingunmanageddllfunctions.asp

Please feel free to let me know if you have any problems or concerns.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top